Skip to content
Snippets Groups Projects
Commit cd2d4ee6 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Generated prettyprinter now prints all(?) information. Now need to rearrange...

Generated prettyprinter now prints all(?) information. Now need to rearrange the tree from current diagonal shape
parent b3022c9e
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ aspect AbsGrammarGeneration {
pStream.println("ComplexElement : Element ::= OwlIdentifier Attribute* Element*;");
pStream.println("ValueElement : ComplexElement;");
pStream.println("abstract SimpleElement : Element;");
pStream.println("StringElement : SimpleElement ::= OwlIdentifier;");
pStream.println("StringElement : SimpleElement ::= <IDENTIFIER>;");
pStream.println("IntElement : SimpleElement ::= <INTEGER_LITERAL>;");
pStream.println("FloatElement : SimpleElement ::= <FLOAT_LITERAL>;");
pStream.println("Attribute ::= Value;");
......@@ -112,6 +112,7 @@ aspect GenAspects {
pStream.println("import java.io.PrintStream;");
pStream.println();
genRewrites(pStream);
genMisc(pStream);
genPrettyPrinter(pStream);
}
}
......@@ -138,9 +139,19 @@ aspect GenPrettyPrinter {
pStream.println(" }\n");
pStream.println(" syn String Attribute.id() = \"\";");
pStream.println(" eq RdfId.id() = \"Rdf:ID\";");
pStream.println(" eq RdfDatatype.id() = \"Rdf:datatype\";");
pStream.println(" public void Attribute.prettyPrint(String indent, PrintStream pStream) {");
pStream.println(" System.out.print(\" \"+id()+\"=\"+getValue().getSTRING_LITERAL());");
pStream.println(" }\n");
pStream.println(ind(1)+"public void ValueElement.prettyPrint(String indent, PrintStream pStream) {");
pStream.println(ind(2)+"System.out.print(indent+\"<value \");");
pStream.println(ind(2)+"for (int i=0; i<getNumAttribute(); i++) {");
pStream.println(ind(3)+"getAttribute(i).prettyPrint(indent,pStream);");
pStream.println(ind(2)+"}");
pStream.println(ind(2)+"System.out.println(\">\");");
pStream.println(ind(2)+"System.out.println(indent+\" \"+value());");
pStream.println(ind(2)+"System.out.println(indent+\"</value>\");");
pStream.println(ind(1)+"}\n");
super.genPrettyPrinter(pStream);
pStream.println("}\n");
}
......@@ -166,9 +177,9 @@ aspect GenPrettyPrinter {
pStream.println(ind(2)+"System.out.println(childIndent+\"</has"+
r.name()+">\");");
}
// pStream.println(ind(1)+" for (int i=0; i<getNumElement(); i++) {");
// pStream.println(ind(1)+" getElement(i).prettyPrint(childIndent,pStream);");
// pStream.println(ind(1)+" }");
pStream.println(ind(2)+"for (int i=0; i<getNumElement(); i++) {");
pStream.println(ind(3)+"getElement(i).prettyPrint(childIndent,pStream);");
pStream.println(ind(2)+"}");
pStream.println(ind(1)+"System.out.println(indent+\"</"+name()+">\");");
pStream.println(ind(1)+"}\n");
}
......@@ -243,6 +254,36 @@ aspect GenRewrites {
}
aspect GenMisc {
public void ASTNode.genMisc(PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).genMisc(pStream);
}
}
public void Start.genMisc(PrintStream pStream) {
pStream.println();
pStream.println("aspect Misc {");
pStream.println();
pStream.println(ind(1)+"String ValueElement.value() {");
pStream.println(ind(2)+"StringBuffer b = new StringBuffer();");
pStream.println(ind(2)+"for (int i=0; i<getNumElement(); i++) {");
pStream.println(ind(3)+"b.append(((SimpleElement) getElement(i)).value());");
pStream.println(ind(3)+"b.append(\" \");");
pStream.println(ind(2)+"}");
pStream.println(ind(2)+"return b.toString().trim();");
pStream.println(ind(1)+"}");
pStream.println();
pStream.println(ind(1)+"syn String SimpleElement.value() = \"\";");
pStream.println(ind(1)+"eq StringElement.value() = getIDENTIFIER();");
pStream.println(ind(1)+"eq IntElement.value() = getINTEGER_LITERAL();");
pStream.println(ind(1)+"eq FloatElement.value() = getFLOAT_LITERAL();");
super.genMisc(pStream);
pStream.println("}");
}
}
aspect ParserGen {
public void Start.genParser(PrintStream pStream) {
......
......@@ -175,7 +175,7 @@ SPECIAL_TOKEN : /* COMMENTS */
<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */
{
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|":")* >
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
|
< #LETTER:
[
......@@ -191,7 +191,10 @@ SPECIAL_TOKEN : /* COMMENTS */
"\u3300"-"\u337f",
"\u3400"-"\u3d2d",
"\u4e00"-"\u9fff",
"\uf900"-"\ufaff"
"\uf900"-"\ufaff",
"+",
"-",
"/"
]
>
|
......@@ -249,10 +252,10 @@ SPECIAL_TOKEN : /* COMMENTS */
// | < SC_AND : "&&" >
// | < INCR : "++" >
// | < DECR : "--" >
| < PLUS : "+" >
| < MINUS : "-" >
// | < PLUS : "+" >
// | < MINUS : "-" >
// | < STAR : "*" >
| < SLASH : "/" >
// | < SLASH : "/" >
// | < BIT_AND : "&" >
// | < BIT_OR : "|" >
// | < XOR : "^" >
......@@ -311,11 +314,11 @@ void Identifier() #OwlIdentifier : {Token t;}
{jjtThis.setIDENTIFIER(t.image);}
}
void OtherToken() #OwlIdentifier : {Token t;}
{
t=<PLUS> | t=<MINUS> | t=<SLASH> | t=<COMMA> | t=<DOT>
{jjtThis.setIDENTIFIER(t.image);}
}
// void OtherToken() #OwlIdentifier : {Token t;}
// {
// t=<PLUS> | t=<MINUS> | t=<SLASH> | t=<COMMA> | t=<DOT>
// {jjtThis.setIDENTIFIER(t.image);}
// }
......@@ -345,9 +348,11 @@ void FloatElement() #FloatElement : { Token t; }
}
void StringElement() #StringElement : {}
void StringElement() #StringElement : {Token t;}
{
Identifier() | OtherToken()
t = <IDENTIFIER>
{jjtThis.setIDENTIFIER(t.image);}
// Identifier() | OtherToken()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment