You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/05/08 09:33:45 UTC

[7/7] git commit: Some improvements in the ldpath-syntax definition

Some improvements in the ldpath-syntax definition


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/ad984178
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/ad984178
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/ad984178

Branch: refs/heads/develop
Commit: ad98417822e03298a4c37b11b014a8b3b652c1cf
Parents: 2841bf3
Author: Jakob Frank <ja...@apache.org>
Authored: Wed May 8 08:36:50 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Wed May 8 09:33:06 2013 +0200

----------------------------------------------------------------------
 .../javacc/at/newmedialab/ldpath/parser/rdfpath.jj |  105 +++++++++-----
 1 files changed, 67 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/ad984178/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
index 66223f5..bf2a24b 100644
--- a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
+++ b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
@@ -374,17 +374,46 @@ MORE:
 }
 
 
+TOKEN : /* LDPATH */
+{
+  < COMMA:  "," >  |
+  < SCOLON: ";" >  |
+  < COLON:  ":" >  |
+  < DCOLON: "::" > |
+  < ASSIGN: "=" >  |
+  < K_PREFIX: "@prefix" > |
+  < K_FILTER: "@filter" > |
+  < K_BOOST:  "@boost" >  |
+  < K_GRAPH:  "@graph" >
+}
 TOKEN : /* OPERATORS */
 {
+    < SELF: "." >    |
 	< AND:  "&" >    |
 	< OR:   "|" >    |
+    < P_SEP:"/" >    |
+    < PLUS: "+" >    |
+    < STAR: "*" >    |
 	< NOT:  "!" >    |
+    < INVERSE: "^" > |
 	< IS:   "is" >   |
 	< IS_A: "is-a" > |
+    < FUNC: "fn:" >  |
   	< TYPE: "^^" >   |
   	< LANG: "@" >
 }
 
+TOKEN : /* BRACKETS */
+{
+  < B_RO: "(" > |
+  < B_RC: ")" > |
+  < B_SO: "[" > |
+  < B_SC: "]" > |
+  < B_CO: "{" > |
+  < B_CC: "}" > |
+  < B_XO: "<" > |
+  < B_XC: ">" > 
+}
 TOKEN :
 {
     < URI: ["a"-"z","A"-"Z"](["a"-"z","A"-"Z","0"-"9","+","-","."])* "://"  (["a"-"z","A"-"Z","0"-"9",";","/","?",":","@","&","=","+","$",".","-","_","!","~","*","'","%"])+ ("#" (["a"-"z","A"-"Z","0"-"9",";","/","?",":","@","&","=","+","$",".","-","_","!","~","*","'","%"])*)? | "#" (["a"-"z","A"-"Z","0"-"9",";","/","?",":","@","&","=","+","$",".","-","_","!","~","*","'","%"])+> |
@@ -415,7 +444,7 @@ Entry<String, String> Namespace() :
 }
 {
   ( 
-    "@prefix" id = <IDENTIFIER> ":" "<" uri = <URI> ">" (";")? {
+    <K_PREFIX> id = <IDENTIFIER> <COLON> <B_XO> uri = <URI> <B_XC> (<SCOLON> )? {
     }
   ) { return new Namespace(id.image, uri.image); }
 }
@@ -439,13 +468,13 @@ Program Program() :
   )?
 
   (
-    "@filter" filter = NodeTest() ";" {
+    <K_FILTER> filter = NodeTest() <SCOLON> {
         program.setFilter(filter);
     }
   )?
 
   (
-    "@boost" boostSelector = Selector() ";" {
+    <K_BOOST> boostSelector = Selector() <SCOLON> {
     	NodeTransformer transformer = getTransformer(Program.DOCUMENT_BOOST_TYPE);
 		FieldMapping booster = new FieldMapping("@boost", Program.DOCUMENT_BOOST_TYPE, boostSelector, transformer, null);
 		program.setBooster(booster);  
@@ -475,7 +504,7 @@ FieldMapping Rule() :
     Map<String, String> conf = null;
 }
 {
-    name = <IDENTIFIER> "=" selector = Selector() ("::" type = Uri())? ("(" conf = FieldConfig() ")")? ";" {
+    name = <IDENTIFIER> <ASSIGN> selector = Selector() (<DCOLON> type = Uri())? (<B_RO> conf = FieldConfig() <B_RC>)? <SCOLON> {
         if(type != null) {
             transformer = getTransformer(type);
         } else {
@@ -487,7 +516,7 @@ FieldMapping Rule() :
         rule = new FieldMapping(name.image,type,selector,transformer, conf);
         return rule;
     }
-|   uri = Uri() "=" selector = Selector() ("::" type = Uri())? ("(" conf = FieldConfig() ")")? ";" {
+|   uri = Uri() <ASSIGN> selector = Selector() (<DCOLON> type = Uri())? (<B_RO> conf = FieldConfig() <B_RC>)? <SCOLON> {
         if(type != null) {
             transformer = getTransformer(type);
         } else {
@@ -499,7 +528,7 @@ FieldMapping Rule() :
         rule = new FieldMapping(uri,type,selector,transformer, conf);
         return rule;
     }
-|   selector = Selector() ("::" type = Uri())? ("(" conf = FieldConfig() ")")? (";")? {
+|   selector = Selector() (<DCOLON> type = Uri())? (<B_RO> conf = FieldConfig() <B_RC>)? (<SCOLON>)? {
         if(type != null) {
             transformer = getTransformer(type);
         } else {
@@ -531,7 +560,7 @@ Map<String,String> FieldConfig() : {
 	Map<String,String> more = null;
 }
 {
-	( key = <IDENTIFIER> "=" val = ConfVal() ("," more = FieldConfig() )? )? {
+	( key = <IDENTIFIER> <ASSIGN> val = ConfVal() ( <COMMA> more = FieldConfig() )? )? {
 		if (key == null || val == null) return null;
 		conf.put(key.image, val);
 		if (more != null) {
@@ -678,7 +707,7 @@ NodeSelector SelfSelector() :
 {
 }
 {
-	"." { return new SelfSelector(); }
+	<SELF> { return new SelfSelector(); }
 }
 
 NodeSelector GroupedSelector() :
@@ -687,7 +716,7 @@ NodeSelector GroupedSelector() :
 }
 {
     /* Other selector enclosed in braces */
-    "(" result = Selector() ")"
+    <B_RO> result = Selector() <B_RC>
     {
         return new GroupedSelector(result);
     }
@@ -700,12 +729,12 @@ RecursivePathSelector RecursivePathSelector() :
 	NodeSelector delegate        = null;
 }
 {
-	"(" delegate = Selector() ")" "+"
+	<B_RO> delegate = Selector() <B_RC> <PLUS>	
 	{
 		result = RecursivePathSelector.getPathSelectorPlused(delegate);
 		return result;
 	} |
-    "(" delegate = Selector() ")" "*"
+    <B_RO> delegate = Selector() <B_RC> <STAR>
     {
         result = RecursivePathSelector.getPathSelectorStared(delegate);
         return result;
@@ -719,7 +748,7 @@ PathSelector PathSelector() :
     NodeSelector right  = null;
 }
 {
-    left = AtomicOrTestingSelector() "/" right = AtomicOrTestingOrPathSelector()
+    left = AtomicOrTestingSelector() <P_SEP> right = AtomicOrTestingOrPathSelector()
     {
         result = new PathSelector(left,right);
         return result;
@@ -733,7 +762,7 @@ IntersectionSelector IntersectionSelector() :
     NodeSelector right  = null;
 }
 {
-    left = AtomicOrTestingOrPathSelector() "&" right = Selector()
+    left = AtomicOrTestingOrPathSelector() <AND> right = Selector()
     {
         result = new IntersectionSelector(left,right);
         return result;
@@ -747,7 +776,7 @@ UnionSelector UnionSelector() :
     NodeSelector right  = null;
 }
 {
-    left = AtomicOrTestingOrPathSelector() "|" right = Selector()
+    left = AtomicOrTestingOrPathSelector() <OR> right = Selector()
     {
         result = new UnionSelector(left,right);
         return result;
@@ -761,7 +790,7 @@ TestingSelector TestingSelector() :
     NodeTest test = null;
 }
 {
-    delegate = AtomicSelector() "[" test = NodeTest() "]" {
+    delegate = AtomicSelector() <B_SO> test = NodeTest() <B_SC> {
         result = new TestingSelector(delegate,test);
         return result;
     }
@@ -774,7 +803,7 @@ ReversePropertySelector ReversePropertySelector() :
     String uri;
 }
 {
-	"^" uri = Uri() {
+	<INVERSE> uri = Uri() {
         property = resolveResource(uri);
         result   = new ReversePropertySelector(property);
         return result;
@@ -800,7 +829,7 @@ WildcardSelector WildcardSelector() :
     WildcardSelector result = null;
 }
 {
-    "*" {
+    <STAR> {
         result = new WildcardSelector();
         return result;
     }
@@ -817,22 +846,22 @@ FunctionSelector FunctionSelector() :
 {
     /* Function-Calls without arguments can skip parenthesis */
     /* Does not work... why?
-    "fn:" fName = <IDENTIFIER> {
+    <FUNC> fName = <IDENTIFIER> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionSelector(getFunction(uri),Collections.emptyList());
            return result;
     } | */
     /* Functions do not need to have arguments */
-    "fn:" fName = <IDENTIFIER> "(" ")" {
+    <FUNC> fName = <IDENTIFIER> <B_RO> <B_RC> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionSelector(getFunction(uri),Collections.emptyList());
            return result;
     } |
     /* Sometimes arguments are required */
-    "fn:" fName = <IDENTIFIER> "("
+    <FUNC> fName = <IDENTIFIER> <B_RO>
             argument = Selector() { arguments.add(argument); }
-            ( "," argument = Selector() { arguments.add(argument); } )*
-    ")" {
+            ( <COMMA> argument = Selector() { arguments.add(argument); } )*
+    <B_RC> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionSelector(getFunction(uri),arguments);
            return result;
@@ -876,7 +905,7 @@ NodeTest GroupedTest() :
     NodeTest delegate;
 }
 {
-    "(" delegate = NodeTest() ")" {
+    <B_RO> delegate = NodeTest() <B_RC> {
        return delegate;
     }
 }
@@ -889,7 +918,7 @@ NodeTest AtomicNodeTest() :
     (
         result = LiteralLanguageTest()
     |   result = LiteralTypeTest()
-    |   result = TypeTest()
+    |   result = IsATest()
     |   result = PathEqualityTest()
     |   result = FunctionTest()
     |   result = PathTest()
@@ -911,20 +940,20 @@ FunctionTest FunctionTest() :
   (    
     /* Function-Calls without arguments can skip parenthesis */
     /* Does not work... why?
-    "fn:" fName = <IDENTIFIER> {
+    <FUNC> fName = <IDENTIFIER> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionSelector(getTestFunction(uri),Collections.emptyList());
     } | */
     /* Functions do not need to have arguments */
-    "fn:" fName = <IDENTIFIER> "(" ")" {
+    <FUNC> fName = <IDENTIFIER> <B_RO> <B_RC> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionTest(getTestFunction(uri),Collections.emptyList());
     } |
     /* Sometimes arguments are required */
-    "fn:" fName = <IDENTIFIER> "("
+    <FUNC> fName = <IDENTIFIER> <B_RO>
             argument = Selector() { arguments.add(argument); }
-            ( "," argument = Selector() { arguments.add(argument); } )*
-    ")" {
+            ( <COMMA> argument = Selector() { arguments.add(argument); } )*
+    <B_RC> {
            uri = namespaces.get("fn") + fName.image;
            result = new FunctionTest(getTestFunction(uri),arguments);
     }
@@ -939,7 +968,7 @@ LiteralLanguageTest LiteralLanguageTest():
     Token lang;
 }
 {
-    "@" lang = <IDENTIFIER> {
+    <LANG> lang = <IDENTIFIER> {
         return new LiteralLanguageTest(lang.image);
     }
 }
@@ -949,7 +978,7 @@ LiteralTypeTest LiteralTypeTest():
     String type;
 }
 {
-    "^^" type = Uri() {
+    <TYPE> type = Uri() {
         return new LiteralTypeTest(type);
     }
 }
@@ -959,12 +988,12 @@ NotTest NotTest() :
     NodeTest delegate;
 }
 {
-    "!" delegate = NodeTest() {
+    <NOT>  delegate = NodeTest() {
         return new NotTest(delegate);
     }
 }
 
-PathEqualityTest TypeTest() :
+IsATest IsATest() :
 {
     Node node;
 }
@@ -980,7 +1009,7 @@ AndTest AndTest():
     NodeTest left, right;
 }
 {
-    left = AtomicNodeTest() "&" right = NodeTest() {
+    left = AtomicNodeTest() <AND> right = NodeTest() {
         return new AndTest(left,right);
     }
 }
@@ -990,7 +1019,7 @@ OrTest OrTest():
     NodeTest left, right;
 }
 {
-    left = AtomicNodeTest() "|" right = NodeTest() {
+    left = AtomicNodeTest() <OR> right = NodeTest() {
         return new OrTest(left,right);
     }
 }
@@ -1001,7 +1030,7 @@ PathEqualityTest PathEqualityTest():
     Node node;
 }
 {
-    path = Selector() "is" node = Node() {
+    path = Selector() <IS> node = Node() {
         return new PathEqualityTest(path,node);
     }
 }
@@ -1016,14 +1045,14 @@ Node Node():
     uri = Uri() {
         return resolveResource(uri);
     }
-|   literal = <STRLIT>  ("^^" type = Uri() )? {
+|   literal = <STRLIT>  (<TYPE> type = Uri() )? {
         try {
             return backend.createLiteral(literal.image.substring(1, literal.image.length()-1),null,type == null ? null : new URI(type));
         } catch(java.net.URISyntaxException ex) {
             throw new ParseException("could not parse type URI "+type+": "+ex.getMessage());
 	    }
     }
-|   literal = <STRLIT>  "@" language = <IDENTIFIER> {
+|   literal = <STRLIT>  <LANG> language = <IDENTIFIER> {
         return backend.createLiteral(literal.image.substring(1, literal.image.length()-1),new Locale(language.image),null);
     }
 }