From f9dc4449244f24979f8b9d37b5961dc21e7499b7 Mon Sep 17 00:00:00 2001
From: Anders Nilsson <andersn@fiol>
Date: Mon, 13 Feb 2006 15:39:20 +0100
Subject: [PATCH] Rewrites to ClassDecl and ClassUse. Dump class decls.

---
 CompilerGeneration.jrag | 19 +++++++----
 Rewrites.jrag           | 74 +++++++++++++++++++++++++++++++++++++----
 owl.ast                 |  2 +-
 3 files changed, 81 insertions(+), 14 deletions(-)

diff --git a/CompilerGeneration.jrag b/CompilerGeneration.jrag
index a4c7a3c..3ab9fc7 100644
--- a/CompilerGeneration.jrag
+++ b/CompilerGeneration.jrag
@@ -9,15 +9,20 @@ aspect CompilerGeneration {
 	}
     }
 
-    public void Start.genAbsGrammar(PrintStream p) {
-	super.genAbsGrammar(p);
+    public void Start.genAbsGrammar(PrintStream pStream) {
+	super.genAbsGrammar(pStream);
     }
 
-    void OwlClass.genAbsGrammar(PrintStream pStream) {
-	pStream.println(getAttribute(0).getValue().getSTRING_LITERAL());
+    void OwlClassDecl.genAbsGrammar(PrintStream pStream) {
+	pStream.print("OwlClassDecl: ");
+	pStream.println(getId());
+	super.genAbsGrammar(pStream);
+    }
+
+    void OwlClassUse.genAbsGrammar(PrintStream pStream) {
+// 	pStream.print("OwlClassUse: ");
+// 	pStream.println(getId());
+	super.genAbsGrammar(pStream);
     }
 }
 
-aspect Name {
-//     syn String Element
-}
\ No newline at end of file
diff --git a/Rewrites.jrag b/Rewrites.jrag
index 8713d33..906b52a 100644
--- a/Rewrites.jrag
+++ b/Rewrites.jrag
@@ -1,10 +1,72 @@
 /* -*-Java-*- */
 
+aspect MiscUtilities {
+    boolean Element.isTopLevel() {
+	if ( getParent() != null ) {
+	    return getParent().getParent() instanceof RdfDeclaration;
+	} else {
+	    return  false;
+	}
+    }
+
+    String Element.trim(Attribute a) {
+	String s = a.getValue().getSTRING_LITERAL();
+	if (s.indexOf('"') == 0) {
+	    s = s.substring(1,s.length()-1).trim();
+	} 
+	if (s.indexOf('#') == 0) {
+	    s = s.substring(1,s.length()).trim();
+	} 
+	return s.trim();
+    }
+
+    boolean ComplexElement.hasRdfId() {
+	for (int i=0; i<getNumAttribute(); i++) {
+	    if (getAttribute(i) instanceof RdfId) {
+		return true;
+	    }
+	}
+	return false;
+    }
+
+    boolean ComplexElement.hasRdfAbout() {
+	for (int i=0; i<getNumAttribute(); i++) {
+	    if (getAttribute(i) instanceof RdfAbout) {
+		return true;
+	    }
+	}
+	return false;
+    }
+
+    String ComplexElement.getId() {
+	if (hasRdfId()) {
+	    for (int i=0; i<getNumAttribute(); i++) {
+		if (getAttribute(i) instanceof RdfId) {
+		    return trim(getAttribute(i));
+		}
+	    }
+	} else if (hasRdfAbout()) {
+	    for (int i=0; i<getNumAttribute(); i++) {
+		if (getAttribute(i) instanceof RdfAbout) {
+		    return trim(getAttribute(i));
+		}
+	    }
+	}
+	// Fall through. Could not find Id, so let's return something
+	// well known
+	return "_Unknown_";
+    }
+}
+
 aspect RewriteClasses {
-//     rewrite OwlClass {
-// 	when (isTopLevel())
-// 	    to OwlClassDecl {
-	    
-// 	}
-//     }
+    rewrite OwlClass {
+	when (isTopLevel())
+	    to OwlClassDecl {
+	    return new OwlClassDecl(new List(), getElementList(), getId());
+	}
+	when (!isTopLevel())
+	    to OwlClassUse {
+	    return new OwlClassUse(new List(), getElementList(), getId());
+	}
+    }
 }
\ No newline at end of file
diff --git a/owl.ast b/owl.ast
index 410d028..5f58266 100644
--- a/owl.ast
+++ b/owl.ast
@@ -52,6 +52,6 @@ Value ::= <STRING_LITERAL>;
 
 
 // Types generated by rewrite rules
-abstract Class;
+abstract Class : ComplexElement;
 OwlClassDecl : Class ::= <Id:String> ;
 OwlClassUse : Class ::= <Id:String> ;
-- 
GitLab