Commit 2317429f authored by baueko's avatar baueko
Browse files

added java parsing, need to fix javaParser and javaSemantics

parent d7f6fa41
......@@ -22,12 +22,14 @@ public abstract class CodeBlock extends AbstractNode {
super(range);
this.debugId = debugId;
this.blob = blob;
//TODO parse blob to javaTree
try{
this.javaTree = JavaCompiler.parseJava(blob);
} catch(Exception e){}
}
@Override
protected void putDescription(StringBuilder builder) {
builder.append(blob);
builder.append(javaTree);
}
}
package de.in.tum.www2.cup.ast;
import java.io.*;
import java.nio.file.*;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Source;
......@@ -15,13 +13,9 @@ import mouse.runtime.SourceString;
import java_cup.runtime.SyntaxTreeTransform;
public class JavaCompiler {
public static void main(String args[]) throws Exception {
StringBuffer lines=new StringBuffer();
for (String line: Files.readAllLines(FileSystems.getDefault().getPath(args[0]))){
lines.append(line);
lines.append("\n");
}
SourceString src = new SourceString(lines.toString());
public static XMLElement parseJava(String blob) throws Exception {
SourceString src = new SourceString(blob);
JavaParser parser=new JavaParser();
boolean ok = parser.parse(src);
if (ok) {
......@@ -61,8 +55,12 @@ public class JavaCompiler {
// Transform XML-Tree via XSL into an HTML-Based Syntaxtree
transformer= TransformerFactory.newInstance().newTransformer(new StreamSource("tree-view.xsl"));
text=new StreamSource(new ByteArrayInputStream(out.toByteArray()));
transformer.transform(text,new StreamResult(new File(args[1]+".ast.html")));
//transformer.transform(text,new StreamResult(new File(args[1]+".ast.html")));
System.out.println(" -> Transformation succeeded"); }
System.out.println(" -> Transformation succeeded");
return elem;
}
//TODO add exception
throw new RuntimeException("Java parsing failed.");
}
}
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
package de.in.tum.www2.cup.ast;
import java_cup.runtime.ComplexSymbolFactory.Location;
import java_cup.runtime.XMLElement;
import mouse.runtime.Phrase;
public interface JavaSemanticsUsercode {
Phrase lhs();
Phrase rhs(int i);
//-------------------------------------------------------------------
// Identifier = !Keyword Letter LetterOrDigit* Spacing
//-------------------------------------------------------------------
default void Identifier()
{
XMLElement x = (XMLElement)lhs().get();
lhs().put(new XMLElement.Terminal(new Location(lhs().getStartLine(),lhs().getStartColumn(),lhs().getStartPos()),"Identifier",lhs().text().trim(),new Location(lhs().getEndLine(),lhs().getEndColumn(),lhs().getEndPos())));
}
//-------------------------------------------------------------------
// CLASS = "class" !LetterOrDigit Spacing
// INTERFACE = "interface" !LetterOrDigit Spacing
// LPAR = "(" Spacing
// RPAR = ")" Spacing
// LWING = "{" Spacing
// RWING = "}" Spacing
// SEMI = ";" Spacing
// Spacing = ([ \t\r\n\f]+ / "/*" _*+ "*/" / "//" _*+ [\r\n])*
//-------------------------------------------------------------------
default void Suppress()
{
lhs().put(null);
}
}
Supports Markdown
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