Commit 849be243 authored by Anders Nilsson's avatar Anders Nilsson
Browse files

Generalized JavaCC generation a bit

parent dcb4a4c1
......@@ -19,7 +19,7 @@ aspect AbsGrammarGeneration {
pStream.print(getId());
pStream.print(" : "+getSuperClass().getId());
pStream.print(" ::=");
Restrictions restrs = getRestrictions();
Restrictions restrs = getOwnRestrictions();
for (int i=0; i<restrs.getNumOwlRestriction(); i++) {
pStream.print(" ");
restrs.getOwlRestriction(i).genAbsGrammar(pStream);
......@@ -138,13 +138,25 @@ aspect JavaCCGen {
pStream.println("void "+getId()+"() : {}");
pStream.println("{");
if (getId().equals("Device")) {
pStream.print("\"<\" <DEVICE> \">\"");
pStream.print("(Property())* (Skill())* MainFunction() #");
pStream.println("Device("+getNumRestriction()+")");
pStream.print("\"<\" ( <DEVICE> \">\"");
Restrictions restr = getRestrictions();
for (int i=0; i< getNumRestriction(); i++) {
OwlRestriction res = restr.getOwlRestriction(i);
pStream.print("("+res.getRestrictionClassId()+")"+
(res.allValuesFrom()?"*":"")+" ");
}
pStream.println(" #Device("+getNumRestriction()+")");
// List all subclasses
pStream.println(")");
} else {
pStream.print(" <"+getId().toUpperCase()+"> \">\"");
pStream.print("(Property())* (Skill())* MainFunction() #");
pStream.println(getId()+"("+getNumRestriction()+")");
Restrictions restr = getRestrictions();
for (int i=0; i< getNumRestriction(); i++) {
OwlRestriction res = restr.getOwlRestriction(i);
pStream.print("("+res.getRestrictionClassId()+")"+
(res.allValuesFrom()?"*":"")+" ");
}
pStream.println(" #"+getId()+"("+getNumRestriction()+")");
}
pStream.println("}");
}
......
......@@ -56,12 +56,12 @@ aspect Types {
aspect Restrictions {
Restrictions OwlClassDecl.restrictions;
Restrictions OwlClassDecl.ownRestrictions;
syn lazy Restrictions OwlClassDecl.getRestrictions() {
if (restrictions == null) {
List l = new List();
collectRestrictions(l);
getSuperClass().decl().collectRestrictions(l);
restrictions = new Restrictions(l);
}
return restrictions;
......@@ -72,12 +72,41 @@ aspect Restrictions {
getChild(i).collectRestrictions(l);
}
}
void OwlClassDecl.collectRestrictions(List l) {
if (!getSuperClass().getId().equals("Thing")) {
getSuperClass().decl().collectRestrictions(l);
}
super.collectRestrictions(l);
}
void OwlRestriction.collectRestrictions(List l) {
l.add(this);
}
syn int OwlClassDecl.getNumRestriction() = getRestrictions().getNumOwlRestriction();
syn lazy Restrictions OwlClassDecl.getOwnRestrictions() {
if (ownRestrictions == null) {
List l = new List();
collectOwnRestrictions(l);
ownRestrictions = new Restrictions(l);
}
return ownRestrictions;
}
void ASTNode.collectOwnRestrictions(List l) {
for (int i=0; i<getNumChild(); i++) {
getChild(i).collectOwnRestrictions(l);
}
}
void OwlRestriction.collectOwnRestrictions(List l) {
l.add(this);
}
syn int OwlClassDecl.getNumOwnRestriction() =
getOwnRestrictions().getNumOwlRestriction();
}
aspect Properties {
......
......@@ -64,9 +64,9 @@ Value ::= <STRING_LITERAL>;
// Types used by rewrite rules
abstract OClass : ComplexElement;
OwlClassDecl : OClass ::= <Id:String> ;
OwlClassUse : OClass ::= <Id:String> ;
abstract OClass : ComplexElement ::= <Id:String>;
OwlClassDecl : OClass;
OwlClassUse : OClass;
abstract OwlValuesFrom: ComplexElement;
......
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