Commit 9d9e1a0a authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Added small hand-written aspect Statistics.jrag to visualize how one can...

Added small hand-written aspect Statistics.jrag to visualize how one can easily get information from the AST
parent a930ea26
......@@ -9,3 +9,4 @@ siaras/Parser.java
siaras/Siaras.ast
siaras/PrettyPrinter.jrag
siaras/Rewrites.jrag
siaras/log.tmp
......@@ -62,7 +62,6 @@ aspect AbsGrammarGeneration {
}
void OwlRestriction.genAbsGrammar(PrintStream pStream) {
// pStream.print(getRestrictionPropertyId());
pStream.print(getRestrictionClassId().substring(0,1).toLowerCase()+
getRestrictionClassId().substring(1));
pStream.print(":");
......@@ -159,22 +158,37 @@ aspect GenRewrites {
pStream.println("}");
}
// public void OwlClassDecl.genRewrites(PrintStream pStream) {
// String ind = " ";
// int ix = 0;
// pStream.println(ind(1)+"rewrite ComplexElement {");
// pStream.println(ind(2)+"when (getOwlIdentifier().getIDENTIFIER().equals(\""+
// name()+"\") && !(this instanceof Thing))");
// pStream.println(ind(3)+"to "+name()+" {");
public void OwlClassDecl.genRewrites(PrintStream pStream) {
String ind = " ";
int ix = 0;
pStream.println(ind(1)+"rewrite ComplexElement {");
pStream.println(ind(2)+"when (getOwlIdentifier().getIDENTIFIER().equals(\""+
name()+"\") && !(this instanceof Thing))");
pStream.println(ind(3)+"to "+name()+" {");
// pStream.println(ind(3)+"System.out.println(\"rewriting: \"+getOwlIdentifier().getIDENTIFIER());");
// pStream.println(ind(3)+name()+" node = new "+name()+"();");
// pStream.println(ind(3)+"node.setOwlIdentifier(getOwlIdentifier());");
// pStream.println(ind(3)+"node.setAttributeList(getAttributeList());");
// pStream.println(ind(3)+"node.setElementList(getElementList());");
// pStream.println(ind(3)+"return node;");
// pStream.println(ind(2)+"}");
// pStream.println(ind(1)+"}");
// }
pStream.println(ind(3)+name()+" node = new "+name()+"();");
pStream.println(ind(3)+"node.setOwlIdentifier(getOwlIdentifier());");
pStream.println(ind(3)+"node.setAttributeList(getAttributeList());");
pStream.println(ind(3)+"node.setElementList(getElementList());");
// Very temporary solution just so that DumpTree will not
// crasch from NullPointerException. Children should be filled
// in from rewrites instead
Restrictions restr = getRestrictions();
for (int i=0; i<restr.getNumOwlRestriction(); i++) {
OwlRestriction r = restr.getOwlRestriction(i);
if (r.allValuesFrom()) {
pStream.println(ind(3)+"node.set"+r.name().substring(0,1).toLowerCase()+
r.name().substring(1)+"List(new List());");
} else {
pStream.println(ind(3)+r.name()+" c"+ix+" = new "+r.name()+"();");
pStream.println(ind(3)+"node.set"+r.name().substring(0,1).toLowerCase()+
r.name().substring(1)+"(c"+(ix++)+");");
}
}
pStream.println(ind(3)+"return node;");
pStream.println(ind(2)+"}");
pStream.println(ind(1)+"}");
}
}
......
import AST.Start;
public class Statistics extends Parser {
public static void main(String args[]) {
Start ast = parse(args);
// PrettyPrint all OWL instances found in input
ast.getManipulationDevices(System.out);
}
}
import java.io.PrintStream;
aspect Statistics {
public void ASTNode.getManipulationDevices(PrintStream pStream) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).getManipulationDevices(pStream);
}
}
public void Thing.getManipulationDevices(PrintStream pStream) {
for (int i=0; i<getNumElement(); i++) {
getElement(i).getManipulationDevices(pStream);
}
}
public void ManipulationAndHandling.getManipulationDevices(PrintStream pStream) {
pStream.println(getOwlIdentifier().getIDENTIFIER()+
" : "+getAttribute(0).getValue().getSTRING_LITERAL());
super.getManipulationDevices(pStream);
}
}
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