Commit 377feea8 authored by Konrad Pröll's avatar Konrad Pröll

Added Eclipse AST

parent 8cef6ae2
......@@ -14,37 +14,52 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
import java_cup.runtime.XMLElement;
import mouse.runtime.SourceString;
import java_cup.runtime.SyntaxTreeTransform;
public class JavaCompiler {
private static String[] blacklist = { "VariableDeclaratorId" };
public static XMLElement parseJava(String blob, CodeBlock codeblock) throws NoSuchMethodException, SecurityException, IllegalAccessException, InvocationTargetException {
SourceString src = new SourceString(blob);
JavaParser parser = new JavaParser();
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(blob.toCharArray());
boolean ok = false;
ASTNode node;
switch (codeblock.getBt()) {
case Action:
ok = parser.parse(src, "Action");
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
node= parser.createAST(null);
//ok = parser.parse(src, "Action");
break;
case Parser:
ok = parser.parse(src, "Parser");
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
node= parser.createAST(null);
break;
case Init:
ok = parser.parse(src, "InitWith");
parser.setKind(ASTParser.K_STATEMENTS);
node= parser.createAST(null);
break;
case Scan:
ok = parser.parse(src, "ScanWith");
parser.setKind(ASTParser.K_STATEMENTS);
node= parser.createAST(null);
break;
case ActionCode:
ok = parser.parse(src, "ActionCode");
parser.setKind(ASTParser.K_STATEMENTS);
node= parser.createAST(null);
break;
}
if (ok) {
/*if (ok) {
JavaSemantics sem = parser.semantics();
System.out.println(" -> Compilation succeeded");
XMLElement elem = (XMLElement) sem.rule.rhs(0).get();
......@@ -56,7 +71,7 @@ public class JavaCompiler {
// elem = SyntaxTreeTransform.removeUnaryChains(elem);
System.out.println(elem);
return elem;
}
}*/
// TODO add exception
throw new RuntimeException("Java parsing failed.");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment