From cd2d4ee6f90f8ad3104e6387da153e3938e6a3f5 Mon Sep 17 00:00:00 2001 From: Anders Nilsson <anders.nilsson@cs.lth.se> Date: Wed, 6 Dec 2006 14:02:29 +0100 Subject: [PATCH] Generated prettyprinter now prints all(?) information. Now need to rearrange the tree from current diagonal shape --- CompilerGeneration.jrag | 49 +++++++++++++++++++++++++++++++++++++---- siaras/Siaras.jjt | 29 ++++++++++++++---------- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag index 1eec5a0..ce6772f 100644 --- a/CompilerGeneration.jrag +++ b/CompilerGeneration.jrag @@ -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) { diff --git a/siaras/Siaras.jjt b/siaras/Siaras.jjt index 3e51e0d..55d562f 100644 --- a/siaras/Siaras.jjt +++ b/siaras/Siaras.jjt @@ -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() } -- GitLab