clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject svn commit: r1460522 [2/2] - in /clerezza/trunk/rdf.core/src: main/java/org/apache/clerezza/rdf/core/sparql/ main/java/org/apache/clerezza/rdf/core/sparql/query/ main/java/org/apache/clerezza/rdf/core/sparql/query/impl/ main/java/org/apache/clerezza/rd...
Date Mon, 25 Mar 2013 05:05:11 GMT
Copied: clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj (from r1454966, clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj)
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj?p2=clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj&p1=clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj&r1=1454966&r2=1460522&rev=1460522&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj (original)
+++ clerezza/trunk/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj Mon Mar 25 05:05:11 2013
@@ -19,7 +19,6 @@
 options
 {
    STATIC=false;
-   SUPPORT_CLASS_VISIBILITY_PUBLIC=false;
    UNICODE_INPUT=true;
    IGNORE_CASE=false;
    JAVA_UNICODE_ESCAPE=false;
@@ -27,7 +26,7 @@ options
    JDK_VERSION="1.6";
 }
 
-PARSER_BEGIN(JavaCCGeneratedQueryParser)
+PARSER_BEGIN(JavaCCGeneratedSparqlPreParser)
 
 package org.apache.clerezza.rdf.core.sparql;
 
@@ -48,31 +47,37 @@ import org.apache.clerezza.rdf.core.Type
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
 import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
-import org.apache.clerezza.rdf.core.sparql.query.GroupGraphPattern;
-import org.apache.clerezza.rdf.core.sparql.query.BinaryOperation;
-import org.apache.clerezza.rdf.core.sparql.query.Variable;
-import org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable;
-import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable;
-import org.apache.clerezza.rdf.core.sparql.query.FunctionCall;
-import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
-import org.apache.clerezza.rdf.core.sparql.query.Query;
-import org.apache.clerezza.rdf.core.sparql.query.LiteralExpression;
 import org.apache.clerezza.rdf.core.sparql.query.AlternativeGraphPattern;
+import org.apache.clerezza.rdf.core.sparql.query.BinaryOperation;
 import org.apache.clerezza.rdf.core.sparql.query.BuiltInCall;
 import org.apache.clerezza.rdf.core.sparql.query.Expression;
-import org.apache.clerezza.rdf.core.sparql.query.UriRefExpression;
+import org.apache.clerezza.rdf.core.sparql.query.FunctionCall;
+import org.apache.clerezza.rdf.core.sparql.query.GroupGraphPattern;
+import org.apache.clerezza.rdf.core.sparql.query.InlineData;
+import org.apache.clerezza.rdf.core.sparql.query.LiteralExpression;
+import org.apache.clerezza.rdf.core.sparql.query.Query;
+import org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable;
+import org.apache.clerezza.rdf.core.sparql.query.RhsListBinaryOperation;
+import org.apache.clerezza.rdf.core.sparql.query.SparqlUnit;
+import org.apache.clerezza.rdf.core.sparql.query.TriplePattern;
 import org.apache.clerezza.rdf.core.sparql.query.UnaryOperation;
+import org.apache.clerezza.rdf.core.sparql.query.UriRefExpression;
+import org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable;
+import org.apache.clerezza.rdf.core.sparql.query.Variable;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleAlternativeGraphPattern;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleAskQuery;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleDescribeQuery;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleGraphGraphPattern;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleGroupGraphPattern;
+import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleInlineData;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleOrderCondition;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleQuery;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleQueryWithSolutionModifier;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSelectQuery;
+import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSparqlUnit;
 import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern;
+import org.apache.clerezza.rdf.core.sparql.update.Update;
 
 /**
  *
@@ -80,163 +85,159 @@ import org.apache.clerezza.rdf.core.spar
  *            - for initial grammar of this file (available in mulgara project).
  * Modified by: Hasan <hasan@trialox.org>
  */
-class JavaCCGeneratedQueryParser {
+class JavaCCGeneratedSparqlPreParser {
 
-	private static final UriRef RDF_TYPE =
-		new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
-	private static final UriRef RDF_FIRST =
-		new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#first");
-	private static final UriRef RDF_REST =
-		new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
-	private static final UriRef RDF_NIL =
-		new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
-
-	/** A RegEx pattern for separating out a namespace from a prefixed name. */
-	private static final Pattern pfxNamePattern = Pattern.compile("([^:]*):(.*)");
-
-	private Query query;
-	private String base;
-	private Map<String, String> prefixes;
-	private Map<String, ResourceOrVariable> bNodes;
-	private int count;
-	private Map<String, Variable> vars;
-
-	void initialize() {
-		query = null;
-		base = null;
-		prefixes = new HashMap<String, String>();
-		bNodes = new HashMap<String, ResourceOrVariable>();
-		count = 0;
-		vars = new HashMap<String, Variable>();
-	}
-
-	Query parse() throws ParseException {
-		initialize();
-		this.Query();
-		return this.query;
-	}
-
-	private static String unquote(String s) {
-		return s.substring(1, s.length() - 1);
-	}
-
-	private static String unTripleQuote(String s) {
-		return s.substring(3, s.length() - 3);
-	}
-
-	private Variable getVariable(String name) {
-		name = name.substring(1);
-		Variable v = vars.get(name);
-		if (v == null) {
-			v = new Variable(name);
-			vars.put(name, v);
-			if (query instanceof SimpleSelectQuery) {
-				SimpleSelectQuery sq = (SimpleSelectQuery) query;
-				if (sq.isSelectAll()) {
-					sq.addSelection(v);
-				}
-			} else if (query instanceof SimpleDescribeQuery) {
-				SimpleDescribeQuery dq = (SimpleDescribeQuery) query;
-				if (dq.isDescribeAll()) {
-					dq.addResourceToDescribe(new ResourceOrVariable(v));
-				}
-			}
-		}
-		return v;
-	}
-
-	private void addTriplePatterns(Set<TriplePattern> triplePatterns,
-			ResourceOrVariable subject,
-			UriRefOrVariable predicate,
-			Set<ResourceOrVariable> objects) {
-
-		for (ResourceOrVariable object : objects) {
-			triplePatterns.add(
-				new SimpleTriplePattern(subject, predicate, object));
-		}
-	}
-
-	// nodes contain at least one element
-	private ResourceOrVariable addTriplePatterns(
-			Set<TriplePattern> triplePatterns,
-			List<ResourceOrVariable> nodes) {
-
-		ResourceOrVariable head = null;
-		UriRefOrVariable rdfFirst = new UriRefOrVariable(RDF_FIRST);
-		UriRefOrVariable rdfRest = new UriRefOrVariable(RDF_REST);
-		UriRefOrVariable rdfNil = new UriRefOrVariable(RDF_NIL);
-
-		ResourceOrVariable prevSubject = null;
-		for (ResourceOrVariable node : nodes) {
-			ResourceOrVariable currentSubject = getNewBNode();
-			if (prevSubject != null) {
-				triplePatterns.add(
-					new SimpleTriplePattern(prevSubject, rdfRest, currentSubject));
-			} else {
-				head = currentSubject;
-			}
-			triplePatterns.add(
-				new SimpleTriplePattern(currentSubject, rdfFirst, node));
-			prevSubject = currentSubject;
-		}
-		if (prevSubject != null) {
-			triplePatterns.add(
-				new SimpleTriplePattern(prevSubject, rdfRest, rdfNil));
-		}
-		return head;
-	}
-
-	private ResourceOrVariable getNewBNode() {
-		ResourceOrVariable bNode = new ResourceOrVariable(new BNode());
-		bNodes.put("*" + count++, bNode);
-		return bNode;
-	}
-
-	private ResourceOrVariable getBNode(String label) {
-		ResourceOrVariable bNode = bNodes.get(label);
-		if (bNode == null) {
-			bNode = new ResourceOrVariable(new BNode());
-			bNodes.put(label, bNode);
-		}
-		return bNode;
-	}
-
-	private UriRef createUriRef(String r) throws ParseException {
-		// Create an IRI directly if the string does not start with a prefix
-		Matcher m = pfxNamePattern.matcher(r);
-		if (!m.matches()) {
-			// either a normal IRI, or one with a BASE
-			return isRelative(r) ? new UriRef(base + r) : new UriRef(r);
-		}
-		// extract the prefix, and attempt to convert to a URI before creating the reference
-		String ns = prefixes.get(m.group(1));
-		return ns == null ? new UriRef(r) : new UriRef(ns + m.group(2));
-	}
-
-	/**
-	 * Tests if the string for a URI is relative or absolute. The test is based on a scheme existing
-	 * in the string, which in turn expects a : character to follow it. If there is no colon, then
-	 * it is presumed to be relative. Otherwise, if there are special characters preceding the first
-	 * colon these are presumed to not be in a scheme.
-	 * @param u A string for a URI.
-	 * @return <code>true</code> if the URI appears to be relative, <code>false</code> otherwise.
-	 */
-	private static boolean isRelative(String u) {
-		int colon = u.indexOf(':');
-		if (colon < 0) {
-			return true;
-		}
-		for (int c = 0; c < colon; c++) {
-			// if there a non-alphanum characters then this is not a scheme, so the URI is relative
-			if (!Character.isLetterOrDigit(u.charAt(c))) {
-				return true;
-			}
-		}
-		// found a (probably) valid scheme, so the URI is absolute
-		return false;
-	}
+    private static final UriRef RDF_TYPE =
+        new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+    private static final UriRef RDF_FIRST =
+        new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#first");
+    private static final UriRef RDF_REST =
+        new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
+    private static final UriRef RDF_NIL =
+        new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
+
+    /** A RegEx pattern for separating out a namespace from a prefixed name. */
+    private static final Pattern pfxNamePattern = Pattern.compile("([^:]*):(.*)");
+
+    private String base;
+    private Map<String, String> prefixes;
+    private Map<String, ResourceOrVariable> bNodes;
+    private int count;
+
+    void initialize() {
+        base = null;
+        prefixes = new HashMap<String, String>();
+        bNodes = new HashMap<String, ResourceOrVariable>();
+        count = 0;
+    }
+
+    SparqlUnit parse() throws ParseException {
+        SparqlUnit sparqlUnit;
+        initialize();
+        sparqlUnit = this.SparqlUnit();
+        return sparqlUnit;
+    }
+
+    Query parseQuery() throws ParseException {
+        Query query;
+        initialize();
+        query = this.QueryUnit();
+        return query;
+    }
+
+    Update parseUpdate() throws ParseException {
+        Update update;
+        initialize();
+        update = this.UpdateUnit();
+        return update;
+    }
+
+    private static String unquote(String s) {
+        return s.substring(1, s.length() - 1);
+    }
+
+    private static String unTripleQuote(String s) {
+        return s.substring(3, s.length() - 3);
+    }
+
+    private Variable createVariable(String name) {
+        name = name.substring(1);
+        Variable v = new Variable(name);
+        return v;
+    }
+
+    private void addTriplePatterns(Set<TriplePattern> triplePatterns,
+            ResourceOrVariable subject,
+            UriRefOrVariable predicate,
+            Set<ResourceOrVariable> objects) {
+
+        for (ResourceOrVariable object : objects) {
+            triplePatterns.add(
+                new SimpleTriplePattern(subject, predicate, object));
+        }
+    }
+
+    // nodes contain at least one element
+    private ResourceOrVariable addTriplePatterns(
+            Set<TriplePattern> triplePatterns,
+            List<ResourceOrVariable> nodes) {
+
+        ResourceOrVariable head = null;
+        UriRefOrVariable rdfFirst = new UriRefOrVariable(RDF_FIRST);
+        UriRefOrVariable rdfRest = new UriRefOrVariable(RDF_REST);
+        UriRefOrVariable rdfNil = new UriRefOrVariable(RDF_NIL);
+
+        ResourceOrVariable prevSubject = null;
+        for (ResourceOrVariable node : nodes) {
+            ResourceOrVariable currentSubject = getNewBNode();
+            if (prevSubject != null) {
+                triplePatterns.add(
+                    new SimpleTriplePattern(prevSubject, rdfRest, currentSubject));
+            } else {
+                head = currentSubject;
+            }
+            triplePatterns.add(
+                new SimpleTriplePattern(currentSubject, rdfFirst, node));
+            prevSubject = currentSubject;
+        }
+        if (prevSubject != null) {
+            triplePatterns.add(
+                new SimpleTriplePattern(prevSubject, rdfRest, rdfNil));
+        }
+        return head;
+    }
+
+    private ResourceOrVariable getNewBNode() {
+        ResourceOrVariable bNode = new ResourceOrVariable(new BNode());
+        bNodes.put("*" + count++, bNode);
+        return bNode;
+    }
+
+    private ResourceOrVariable getBNode(String label) {
+        ResourceOrVariable bNode = bNodes.get(label);
+        if (bNode == null) {
+            bNode = new ResourceOrVariable(new BNode());
+            bNodes.put(label, bNode);
+        }
+        return bNode;
+    }
+
+    private UriRef createUriRef(String r) throws ParseException {
+        // Create an IRI directly if the string does not start with a prefix
+        Matcher m = pfxNamePattern.matcher(r);
+        if (!m.matches()) {
+            // either a normal IRI, or one with a BASE
+            return isRelative(r) ? new UriRef(base + r) : new UriRef(r);
+        }
+        // extract the prefix, and attempt to convert to a URI before creating the reference
+        String ns = prefixes.get(m.group(1));
+        return ns == null ? new UriRef(r) : new UriRef(ns + m.group(2));
+    }
+
+    /**
+     * Tests if the string for a URI is relative or absolute. The test is based on a scheme existing
+     * in the string, which in turn expects a : character to follow it. If there is no colon, then
+     * it is presumed to be relative. Otherwise, if there are special characters preceding the first
+     * colon these are presumed to not be in a scheme.
+     * @param u A string for a URI.
+     * @return <code>true</code> if the URI appears to be relative, <code>false</code> otherwise.
+     */
+    private static boolean isRelative(String u) {
+        int colon = u.indexOf(':');
+        if (colon < 0) {
+            return true;
+        }
+        for (int c = 0; c < colon; c++) {
+            // if there a non-alphanum characters then this is not a scheme, so the URI is relative
+            if (!Character.isLetterOrDigit(u.charAt(c))) {
+                return true;
+            }
+        }
+        // found a (probably) valid scheme, so the URI is absolute
+        return false;
+    }
 }
-PARSER_END(JavaCCGeneratedQueryParser)
+PARSER_END(JavaCCGeneratedSparqlPreParser)
 
 SKIP :
 {
@@ -262,939 +263,1120 @@ TOKEN [IGNORE_CASE] :
 |   < BY : "BY" >
 |   < FROM : "FROM" >
 |   < GRAPH : "GRAPH" >
-|   < STR : "STR" >
-|   < IS_URI : "isURI" >
 |   < PREFIX : "PREFIX" >
 |   < CONSTRUCT : "CONSTRUCT" >
 |   < LIMIT : "LIMIT" >
 |   < NAMED : "NAMED" >
 |   < OPTIONAL : "OPTIONAL" >
-|   < LANG : "lang" >
-|   < IS_IRI : "isIRI" >
 |   < DESCRIBE : "DESCRIBE" >
 |   < OFFSET : "OFFSET" >
 |   < WHERE : "WHERE" >
 |   < UNION : "UNION" >
-|   < LANGMATCHES : "langMatches" >
-|   < IS_BLANK : "isBlank" >
-|   < IS_LITERAL : "isLiteral" >
 |   < ASK : "ASK" >
 |   < DISTINCT : "DISTINCT" >
 |   < FILTER : "FILTER" >
-|   < DATATYPE : "datatype" >
-|   < REGEX : "regex" >
 |   < REDUCED : "REDUCED" >
+|   < GROUP_CONCAT : "GROUP_CONCAT" >
 |   < BOUND : "bound" >
 |   < TRUE : "TRUE" >
-|   < SAME_TERM : "sameTerm" >
 |   < FALSE : "FALSE" >
+|   < VALUES : "VALUES" >
+|   < UNDEF : "UNDEF" >
+|   < AS : "AS" >
+|   < GROUP : "GROUP" >
+|   < HAVING : "HAVING" >
+|   < LOAD : "LOAD" >
+|   < SILENT : "SILENT" >
+|   < INTO : "INTO" >
+|   < CLEAR : "CLEAR" >
+|   < DROP : "DROP" >
+|   < CREATE : "CREATE" >
+|   < ADD : "ADD" >
+|   < TO : "TO" >
+|   < MOVE : "MOVE" >
+|   < COPY : "COPY" >
+|   < INSERT_DATA : "INSERT DATA" >
+|   < DELETE_DATA : "DELETE DATA" >
+|   < DELETE_WHERE : "DELETE WHERE" >
+|   < WITH : "WITH" >
+|   < DELETE : "DELETE" >
+|   < INSERT : "INSERT" >
+|   < USING : "USING" >
+|   < DEFAULT_T : "DEFAULT" >
+|   < ALL : "ALL" >
+|   < IN : "IN" >
+|   < NOT : "NOT" >
+|   < BNODE : "BNODE" >
+|   < RAND : "RAND" >
+|   < CONCAT : "CONCAT" >
+|   < NOW : "NOW" >
+|   < UUID : "UUID" >
+|   < STRUUID : "STRUUID" >
+|   < COALESCE : "COALESCE" >
+|   < SEPARATOR : "SEPARATOR" >
+}
+
+/* SparqlUnit ::= Prologue ( Query | Update ) */
+private SparqlUnit SparqlUnit() : {
+    Query query;
+    Update update; } {
+    Prologue()
+    (
+        query=Query() {
+        return new SimpleSparqlUnit(query); }
+    |
+        update=Update() {
+        return new SimpleSparqlUnit(update); }
+    )
+}
+
+/* [1]    QueryUnit ::= Query */
+/* [1]    QueryUnit ::= Prologue Query */
+private Query QueryUnit() : {
+    Query query; } {
+    Prologue()
+    query=Query() {
+    return query; }
+}
+
+/* [2]    Query ::= Prologue ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery ) ValuesClause */
+/* [2]    Query ::= ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery ) ValuesClause */
+private Query Query() : {
+    Query query; } {
+    (
+        query = SelectQuery()
+    |
+        query = ConstructQuery()
+    |
+        query = DescribeQuery()
+    |
+        query = AskQuery()
+    ) {
+    return query;
+    }
+}
+
+/* [3]    UpdateUnit ::= Update */
+/* [3]    UpdateUnit ::= Prologue Update */
+private Update UpdateUnit() : {
+    Update update; } {
+    Prologue()
+    update=Update() {
+    return update; }
 }
 
-
-/* [1]      Query      ::=      Prologue ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery ) */
-private void Query() : {} {
-	Prologue() ( SelectQuery() | ConstructQuery() | DescribeQuery() | AskQuery() ) <EOF>
-}
-
-/* [2]      Prologue      ::=      BaseDecl? PrefixDecl* */
+/* [4]    Prologue ::= ( BaseDecl | PrefixDecl )* */
 private void Prologue() : {} {
-	( BaseDecl() )? ( PrefixDecl() )*
+    ( BaseDecl() | PrefixDecl() )*
 }
 
-/* [3]      BaseDecl      ::=      'BASE' IRI_REF */
+/* [5]    BaseDecl ::= 'BASE' IRIREF */
 private void BaseDecl() : {
-	Token iriRef; } {
+    Token iriRef; } {
 
-	<BASE> iriRef=<IRI_REF> { base = unquote(iriRef.image); }
+    <BASE> iriRef=<IRIREF> { base = unquote(iriRef.image); }
 }
 
-/* [4]      PrefixDecl      ::=      'PREFIX' PNAME_NS IRI_REF */
+/* [6]    PrefixDecl ::= 'PREFIX' PNAME_NS IRIREF */
 private void PrefixDecl() : {
-	Token ns, iriRef; } {
+    Token ns, iriRef; } {
 
-	<PREFIX> ns=<PNAME_NS> iriRef=<IRI_REF> {
-	String pfx = ns.image;
-	prefixes.put(pfx.substring(0, pfx.length() - 1), unquote(iriRef.image)); }
-}
-
-/* [5]      SelectQuery   ::=   'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( Var+ | '*' ) DatasetClause* WhereClause SolutionModifier */
-private void SelectQuery() : {
-	Variable v; } {
-
-	<SELECT> {
-	query = new SimpleSelectQuery(); }
-	(
-		<DISTINCT> {
-		((SimpleSelectQuery) query).setDistinct(); }
-	|
-		<REDUCED> {
-		((SimpleSelectQuery) query).setReduced(); }
-	)?
-	(
-		( v=Var() {
-			((SimpleSelectQuery) query).addSelection(v); } )+
-		|
-		"*" {
-			((SimpleSelectQuery) query).setSelectAll(); }
-	)
-	( DatasetClause() )*
-	WhereClause()
-	SolutionModifier()
-}
-
-/* [6]      ConstructQuery    ::=   'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier */
-private void ConstructQuery() : {
-	Set<TriplePattern> triplePatterns = null; } {
-
-	<CONSTRUCT>
-	triplePatterns=ConstructTemplate() {
-	query = new SimpleConstructQuery(triplePatterns); }
-	( DatasetClause() )*
-	WhereClause()
-	SolutionModifier()
-}
-
-/* [7]      DescribeQuery      ::=      'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier */
-private void DescribeQuery() : {
-	UriRefOrVariable node; } {
-
-	<DESCRIBE> {
-	query = new SimpleDescribeQuery(); }
-	(
-		( node=VarOrIRIref() {
-			((SimpleDescribeQuery) query).addResourceToDescribe(node); } )+
-		|
-		"*" {
-			((SimpleDescribeQuery) query).setDescribeAll(); }
-	)
-	( DatasetClause() )*
-	( WhereClause() )?
-	SolutionModifier()
-}
-
-/* [8]      AskQuery      ::=   'ASK' DatasetClause* WhereClause */
-private void AskQuery() : {} {
-	<ASK> {
-	query = new SimpleAskQuery(); }
-	( DatasetClause() )*
-	WhereClause()
-}
-
-/* [9]   DatasetClause   ::=   'FROM' ( DefaultGraphClause | NamedGraphClause ) */
-private void DatasetClause() : {} {
-	<FROM> (DefaultGraphClause() | NamedGraphClause())
-}
-
-/* [10]    DefaultGraphClause    ::=    SourceSelector */
-private void DefaultGraphClause() : {
-	UriRef defaultGraph; } {
-
-	defaultGraph=SourceSelector() {
-	((SimpleQuery) query).addDefaultGraph(defaultGraph); }
-}
-
-/* [11]    NamedGraphClause    ::=    'NAMED' SourceSelector */
-private void NamedGraphClause() : {
-	UriRef namedGraph; } {
-
-	<NAMED> namedGraph=SourceSelector() {
-	((SimpleQuery) query).addNamedGraph(namedGraph); }
+    <PREFIX> ns=<PNAME_NS> iriRef=<IRIREF> {
+    String pfx = ns.image;
+    prefixes.put(pfx.substring(0, pfx.length() - 1), unquote(iriRef.image)); }
 }
 
-/* [12]    SourceSelector    ::=    IRIref */
-private UriRef SourceSelector() : {
-	UriRef graph; } {
-
-	graph=IRIref() {
-	return graph; }
-}
-
-/* [13]    WhereClause    ::=    'WHERE'? GroupGraphPattern */
-private void WhereClause() : {
-	GroupGraphPattern queryPattern; } {
-
-	(<WHERE>)? queryPattern=GroupGraphPattern() {
-	((SimpleQuery) query).setQueryPattern(queryPattern); }
-}
-
-/* [14]    SolutionModifier    ::=    OrderClause? LimitOffsetClauses? */
-private void SolutionModifier() : {} {
-	( OrderClause() )?
-	( LimitOffsetClauses() )?
-}
-
-/* [15]    LimitOffsetClauses    ::=    ( LimitClause OffsetClause? | OffsetClause LimitClause? ) */
-private void LimitOffsetClauses() : {} {
-	( LimitClause() (OffsetClause())? )
-	|
-	( OffsetClause() (LimitClause())? )
-}
-
-/* [16]    OrderClause    ::=    'ORDER' 'BY' OrderCondition+ */
-private void OrderClause() : {} {
-	<ORDER> <BY> ( OrderCondition() )+
-}
-
-/* [17]    OrderCondition    ::=     ( ( 'ASC' | 'DESC' ) BrackettedExpression ) | ( Constraint | Var ) */
-private void OrderCondition() : {
-	boolean asc = true;
-	Expression e; } {
-
-	(
-		( ( "ASC" | "DESC" { asc = false; } ) e=BrackettedExpression() )
-		|
-		( e=Constraint() | e=Var() )
-	) {
-	((SimpleQueryWithSolutionModifier) query).addOrderCondition(new SimpleOrderCondition(e, asc)); }
-}
-
-/* [18]    LimitClause    ::=    'LIMIT' INTEGER */
-private void LimitClause() : {
-	Token t; } {
-
-	<LIMIT> t=<INTEGER> {
-	((SimpleQueryWithSolutionModifier) query).setLimit(Integer.parseInt(t.image)); }
-}
-
-/* [19]    OffsetClause    ::=    'OFFSET' INTEGER */
-private void OffsetClause() : {
-	Token t; } {
-
-	<OFFSET> t=<INTEGER> {
-	((SimpleQueryWithSolutionModifier) query).setOffset(Integer.parseInt(t.image)); }
-}
-
-/* [20]    GroupGraphPattern    ::=    '{' TriplesBlock? ( ( GraphPatternNotTriples | Filter ) '.'? TriplesBlock? )* '}' */
-private GroupGraphPattern GroupGraphPattern() : {
-	GroupGraphPattern groupGraphPattern = new SimpleGroupGraphPattern();
-	Expression constraint; } {
-
-	"{"
-	( TriplesBlock(groupGraphPattern) )?
-	(
-		(
-		GraphPatternNotTriples(groupGraphPattern)
-		|
-		constraint=Filter() {
-		((SimpleGroupGraphPattern) groupGraphPattern).addConstraint(constraint); }
-		)
-
-		(".")?
-
-		(
-		TriplesBlock(groupGraphPattern)
-		)?
-	)*
-	"}" {
-	return groupGraphPattern; }
+/* [7]    SelectQuery ::= SelectClause DatasetClause* WhereClause SolutionModifier */
+private Query SelectQuery() : {
+    Query query; } {
+    query = SelectClause()
+    ( DatasetClause(query) )* {
+    return query; }
 }
 
-/* [21]    TriplesBlock    ::=    TriplesSameSubject ( '.' TriplesBlock? )? */
-private void TriplesBlock(GroupGraphPattern groupGraphPattern) : {
-	Set<TriplePattern> triplePatterns; } {
+/* [8]    SubSelect ::= SelectClause WhereClause SolutionModifier ValuesClause */
 
-	triplePatterns=TriplesSameSubject() {
-	((SimpleGroupGraphPattern) groupGraphPattern).addTriplePatterns(triplePatterns); }
+/* [9]    SelectClause ::= 'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( ( Var | ( '(' Expression 'AS' Var ')' ) )+ | '*' ) */
+private Query SelectClause() : {
+    Query query;
+    Variable v; 
+    Expression e; } {
 
-	( "." (TriplesBlock(groupGraphPattern) )?
-	)?
-}
+    <SELECT> {
+    query = new SimpleSelectQuery(); }
+    (
+        <DISTINCT> {
+        ((SimpleSelectQuery) query).setDistinct(); }
+    |
+        <REDUCED> {
+        ((SimpleSelectQuery) query).setReduced(); }
+    )?
+    (
+        (
+            v=Var() {
+            ((SimpleSelectQuery) query).addSelection(v); }
+        |
+            (
+                "("
+                e=Expression()
+                <AS>
+                v=Var() {
+                v.setBoundExpression(e); 
+                ((SimpleSelectQuery) query).addSelection(v); }
+                ")"
+            )
+        )+
+    |
+        "*" {
+        ((SimpleSelectQuery) query).setSelectAll(); }
+    ) {
+    return query; }
+}
+
+/* [10]    ConstructQuery ::= 'CONSTRUCT' ( ConstructTemplate DatasetClause* WhereClause SolutionModifier | DatasetClause* 'WHERE' '{' TriplesTemplate? '}' SolutionModifier ) */
+private Query ConstructQuery() : {
+    Query query;
+    Set<TriplePattern> triplePatterns = null; } {
 
-/* [22]    GraphPatternNotTriples    ::=    OptionalGraphPattern | GroupOrUnionGraphPattern | GraphGraphPattern */
-private void GraphPatternNotTriples(GroupGraphPattern groupGraphPattern) : {} {
+    <CONSTRUCT>
+    (
+        triplePatterns=ConstructTemplate() {
+        query = new SimpleConstructQuery(triplePatterns); }
+        ( DatasetClause(query) )*
+    |
+        {
+        query = new SimpleConstructQuery(triplePatterns); }
+        ( DatasetClause(query) )*
+    ) {
+    return query; }
+}
+
+/* [11]    DescribeQuery ::= 'DESCRIBE' ( VarOrIri+ | '*' ) DatasetClause* WhereClause? SolutionModifier */
+private Query DescribeQuery() : {
+    Query query;
+    UriRefOrVariable node; } {
 
-	(
-	OptionalGraphPattern(groupGraphPattern)
-	|
-	GroupOrUnionGraphPattern(groupGraphPattern)
-	|
-	GraphGraphPattern(groupGraphPattern)
-	)
+    <DESCRIBE> {
+    query = new SimpleDescribeQuery(); }
+    (
+        ( node=VarOrIri() {
+            ((SimpleDescribeQuery) query).addResourceToDescribe(node); } )+
+        |
+        "*" {
+            ((SimpleDescribeQuery) query).setDescribeAll(); }
+    )
+    ( DatasetClause(query) )* {
+    return query; }
 }
 
-/* [23]    OptionalGraphPattern    ::=    'OPTIONAL' GroupGraphPattern */
-private void OptionalGraphPattern(GroupGraphPattern groupGraphPattern) : {
-	GroupGraphPattern optional; } {
+/* [12]    AskQuery ::= 'ASK' DatasetClause* WhereClause SolutionModifier */
+private Query AskQuery() : {
+    Query query; } {
 
-	<OPTIONAL>
-	optional=GroupGraphPattern() {
-	((SimpleGroupGraphPattern) groupGraphPattern).addOptionalGraphPattern(optional); }
+    <ASK> {
+    query = new SimpleAskQuery(); }
+    ( DatasetClause(query) )* {
+    return query; }
 }
 
-/* [24]    GraphGraphPattern    ::=    'GRAPH' VarOrIRIref GroupGraphPattern */
-private void GraphGraphPattern(GroupGraphPattern groupGraphPattern) : {
-	UriRefOrVariable graph;
-	GroupGraphPattern g; } {
-
-	<GRAPH>
-	graph=VarOrIRIref()
-	g=GroupGraphPattern() {
-	((SimpleGroupGraphPattern) groupGraphPattern).addGraphPattern(
-		new SimpleGraphGraphPattern(graph, g)); }
+/* [13]    DatasetClause ::= 'FROM' ( DefaultGraphClause | NamedGraphClause ) */
+private void DatasetClause(Query query) : {} {
+    <FROM> (DefaultGraphClause(query) | NamedGraphClause(query))
 }
 
-/* [25]    GroupOrUnionGraphPattern    ::=    GroupGraphPattern ( 'UNION' GroupGraphPattern )* */
-private void GroupOrUnionGraphPattern(GroupGraphPattern groupGraphPattern) : {
-	GroupGraphPattern g;
-	AlternativeGraphPattern unionGraphPattern = null; } {
+/* [14]    DefaultGraphClause ::= SourceSelector */
+private void DefaultGraphClause(Query query) : {
+    UriRef defaultGraph; } {
 
-	g=GroupGraphPattern()
-	(
-		<UNION> {
-		if (unionGraphPattern == null) {
-			unionGraphPattern = new SimpleAlternativeGraphPattern(g);
-		} }
-		g=GroupGraphPattern() {
-		((SimpleAlternativeGraphPattern) unionGraphPattern).addAlternativeGraphPattern(g); }
-	)* {
-	if (unionGraphPattern != null) {
-		((SimpleGroupGraphPattern) groupGraphPattern).addGraphPattern(unionGraphPattern);
-	} else {
-		((SimpleGroupGraphPattern) groupGraphPattern).addGraphPattern(g);
-	} }
+    defaultGraph=SourceSelector() {
+    ((SimpleQuery) query).addDefaultGraph(defaultGraph); }
 }
 
-/* [26]    Filter    ::=    'FILTER' Constraint */
-private Expression Filter() : {
-	Expression c; } {
+/* [15]    NamedGraphClause ::= 'NAMED' SourceSelector */
+private void NamedGraphClause(Query query) : {
+    UriRef namedGraph; } {
 
-	<FILTER>
-	c=Constraint() {
-	return c; }
+    <NAMED> namedGraph=SourceSelector() {
+    ((SimpleQuery) query).addNamedGraph(namedGraph); }
 }
 
-/* [27]    Constraint    ::=    BrackettedExpression | BuiltInCall | FunctionCall */
-private Expression Constraint() : {
-	Expression c; } {
+/* [16]    SourceSelector ::= iri */
+private UriRef SourceSelector() : {
+    UriRef graph; } {
 
-    ( c=BrackettedExpression() | c=BuiltInCall() | c=FunctionCall() ) {
-	return c; }
+    graph=Iri() {
+    return graph; }
 }
 
-/* [28]    FunctionCall    ::=    IRIref ArgList */
-private FunctionCall FunctionCall() : {
-	UriRef name;
-	List<Expression> arguments;} {
-
-	name=IRIref()
-	arguments=ArgList() {
-	return new FunctionCall(name, arguments); }
-}
+/*
+[17] WhereClause ::= 'WHERE'? GroupGraphPattern
+[18] SolutionModifier ::= GroupClause? HavingClause? OrderClause? LimitOffsetClauses?
+[19] GroupClause ::= 'GROUP' 'BY' GroupCondition+
+[20] GroupCondition ::= BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var
+[21] HavingClause ::= 'HAVING' HavingCondition+
+[22] HavingCondition ::= Constraint
+[23] OrderClause ::= 'ORDER' 'BY' OrderCondition+
+[24] OrderCondition ::= ( ( 'ASC' | 'DESC' ) BrackettedExpression ) | ( Constraint | Var )
+[25] LimitOffsetClauses ::= LimitClause OffsetClause? | OffsetClause LimitClause?
+[26] LimitClause ::= 'LIMIT' INTEGER
+[27] OffsetClause ::= 'OFFSET' INTEGER
+[28] ValuesClause ::= ( 'VALUES' DataBlock )?
+*/
+
+/* [29]    Update ::= Prologue ( Update1 ( ';' Update )? )? */
+/* [29]    Update ::= ( Update1 ( ';' UpdateUnit )? )? */
+private Update Update() : {
+    Update update; } {
+    <LOAD> {
+    return null; }
+}
+
+/* [30]    Update1 ::= Load | Clear | Drop | Add | Move | Copy | Create | InsertData | DeleteData | DeleteWhere | Modify */
+/* [31]    Load ::= 'LOAD' 'SILENT'? iri ( 'INTO' GraphRef )? */
+/* [32]    Clear ::= 'CLEAR' 'SILENT'? GraphRefAll */
+/* [33]    Drop ::= 'DROP' 'SILENT'? GraphRefAll */
+/* [34]    Create ::= 'CREATE' 'SILENT'? GraphRef */
+/* [35]    Add ::= 'ADD' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+/* [36]    Move ::= 'MOVE' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+/* [37]    Copy ::= 'COPY' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault */
+/* [38]    InsertData ::= 'INSERT DATA' QuadData */
+/* [39]    DeleteData ::= 'DELETE DATA' QuadData */
+/* [40]    DeleteWhere ::= 'DELETE WHERE' QuadPattern */
+/* [41]    Modify ::= ( 'WITH' iri )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern */
+/* [42]    DeleteClause ::= 'DELETE' QuadPattern */
+/* [43]    InsertClause ::= 'INSERT' QuadPattern */
+/* [44]    UsingClause ::= 'USING' ( iri | 'NAMED' iri ) */
+/* [45]    GraphOrDefault ::= 'DEFAULT_T' | 'GRAPH'? iri */
+/* [46]    GraphRef ::= 'GRAPH' iri */
+/* [47]    GraphRefAll ::= GraphRef | 'DEFAULT_T' | 'NAMED' | 'ALL' */
+/* [48]    QuadPattern ::= '{' Quads '}' */
+/* [49]    QuadData ::= '{' Quads '}' */
+/* [50]    Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )* */
+/* [51]    QuadsNotTriples ::= 'GRAPH' VarOrIri '{' TriplesTemplate? '}' */
+/* [52]    TriplesTemplate ::= TriplesSameSubject ( '.' TriplesTemplate? )? */
+
+/* [53]    GroupGraphPattern ::= '{' ( SubSelect | GroupGraphPatternSub ) '}' */
+/* [54]    GroupGraphPatternSub ::= TriplesBlock? ( GraphPatternNotTriples '.'? TriplesBlock? )* */
+/* [55]    TriplesBlock ::= TriplesSameSubjectPath ( '.' TriplesBlock? )? */
+/* [56]    GraphPatternNotTriples ::= GroupOrUnionGraphPattern | OptionalGraphPattern | MinusGraphPattern | GraphGraphPattern | ServiceGraphPattern | Filter | Bind | InlineData */
+/* [57]    OptionalGraphPattern ::= 'OPTIONAL' GroupGraphPattern */
+/* [58]    GraphGraphPattern ::= 'GRAPH' VarOrIri GroupGraphPattern */
+/* [59]    ServiceGraphPattern ::= 'SERVICE' 'SILENT'? VarOrIri GroupGraphPattern */
+/* [60]    Bind ::= 'BIND' '(' Expression 'AS' Var ')' */
+/* [61]    InlineData ::= 'VALUES' DataBlock */
+/* [62]    DataBlock ::= InlineDataOneVar | InlineDataFull */
+/* [63]    InlineDataOneVar ::= Var '{' DataBlockValue* '}' */
+/* [64]    InlineDataFull ::= ( NIL | '(' Var* ')' ) '{' ( '(' DataBlockValue* ')' | NIL )* '}' */
+/* [65]    DataBlockValue ::= iri |    RDFLiteral |    NumericLiteral |    BooleanLiteral |    'UNDEF' */
+/* [66]    MinusGraphPattern ::= 'MINUS' GroupGraphPattern */
+/* [67]    GroupOrUnionGraphPattern ::= GroupGraphPattern ( 'UNION' GroupGraphPattern )* */
+/* [68]    Filter ::= 'FILTER' Constraint */
+/* [69]    Constraint ::= BrackettedExpression | BuiltInCall | FunctionCall */
+/* [70]    FunctionCall ::= iri ArgList */
 
-/* [29]    ArgList    ::=    ( NIL | '(' Expression ( ',' Expression )* ')' ) */
+/* [71]    ArgList ::= NIL | '(' 'DISTINCT'? Expression ( ',' Expression )* ')' */
 private List<Expression> ArgList() : {
-	List<Expression> args = new ArrayList<Expression>();
-	Expression e; } {
+    List<Expression> args = new ArrayList<Expression>();
+    Expression e; } {
 
-	(
-		<NIL>
-		|
-		(
-			"("
-			e=Expression() {
-			args.add(e); }
-				( ","
-				e=Expression() {
-				args.add(e); }
-				)*
-			")"
-		)
-	) {
-	return args; }
+    (
+        <NIL>
+    |
+        (
+            "("
+            (
+                <DISTINCT>
+            )?
+            e=Expression() {
+            args.add(e); }
+            (
+                ","
+                e=Expression() {
+                args.add(e); }
+            )*
+            ")"
+        )
+    ) {
+    return args; }
+}
+
+/* [72]    ExpressionList ::= NIL | '(' Expression ( ',' Expression )* ')' */
+private List<Expression> ExpressionList() : {
+    List<Expression> args = new ArrayList<Expression>();
+    Expression e; } {
+
+    (
+        <NIL>
+    |
+        (
+            "("
+            e=Expression() {
+            args.add(e); }
+            (
+                ","
+                e=Expression() {
+                args.add(e); }
+            )*
+            ")"
+        )
+    ) {
+    return args; }
 }
 
-/* [30]    ConstructTemplate    ::=    '{' ConstructTriples? '}' */
+/* [73]    ConstructTemplate ::= '{' ConstructTriples? '}' */
 private Set<TriplePattern> ConstructTemplate() : {
-	Set<TriplePattern> triplePatterns = null; } {
+    Set<TriplePattern> triplePatterns = null; } {
 
-	"{" (
-	triplePatterns=ConstructTriples()
-	)? "}" {
-	return triplePatterns; }
+    "{" (
+    triplePatterns=ConstructTriples()
+    )? "}" {
+    return triplePatterns; }
 }
 
-/* [31]    ConstructTriples    ::=    TriplesSameSubject ( '.' ConstructTriples? )? */
+/* [74]    ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )? */
 private Set<TriplePattern> ConstructTriples() : {
-	Set<TriplePattern> triplePatterns, t; } {
+    Set<TriplePattern> triplePatterns, t; } {
 
-	triplePatterns=TriplesSameSubject()
-	( "."
-		(
-		t=ConstructTriples() {
-		triplePatterns.addAll(t); }
-		)?
-	)? {
-	return triplePatterns; }
+    triplePatterns=TriplesSameSubject()
+    ( "."
+        (
+        t=ConstructTriples() {
+        triplePatterns.addAll(t); }
+        )?
+    )? {
+    return triplePatterns; }
 }
 
-/* [32]    TriplesSameSubject    ::=    VarOrTerm PropertyListNotEmpty |  TriplesNode PropertyList */
+/* [75]    TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty |  TriplesNode PropertyList */
 private Set<TriplePattern> TriplesSameSubject() : {
-	Set<TriplePattern> triplePatterns = new LinkedHashSet<TriplePattern>();
-	ResourceOrVariable subject; } {
+    Set<TriplePattern> triplePatterns = new LinkedHashSet<TriplePattern>();
+    ResourceOrVariable subject; } {
 
-	( subject=VarOrTerm() PropertyListNotEmpty(subject, triplePatterns) {
-		return triplePatterns; }
-	)
-	|
-	( subject=TriplesNode(triplePatterns) PropertyList(subject, triplePatterns) {
-		return triplePatterns; }
-	)
-}
-
-/* [33]    PropertyListNotEmpty    ::=    Verb ObjectList ( ';' ( Verb ObjectList )? )* */
-private void PropertyListNotEmpty(ResourceOrVariable subject,
-		Set<TriplePattern> triplePatterns) : {
-	UriRefOrVariable predicate;
-	Set<ResourceOrVariable> objects; } {
-	predicate=Verb()
-	objects=ObjectList(triplePatterns) {
-	addTriplePatterns(triplePatterns, subject, predicate, objects); }
-
-	( ";"
-		( predicate=Verb() objects=ObjectList(triplePatterns) {
-			addTriplePatterns(triplePatterns, subject, predicate, objects); }
-		)?
-	)*
-}
-
-/* [34]    PropertyList    ::=    PropertyListNotEmpty? */
-private void PropertyList(ResourceOrVariable subject,
-		Set<TriplePattern> triplePatterns) : { } {
-	( PropertyListNotEmpty(subject, triplePatterns) )?
+    ( subject=VarOrTerm() PropertyListNotEmpty(subject, triplePatterns) {
+        return triplePatterns; }
+    )
+    |
+    ( subject=TriplesNode(triplePatterns) PropertyList(subject, triplePatterns) {
+        return triplePatterns; }
+    )
+}
+
+/* [76]    PropertyList ::= PropertyListNotEmpty? */
+private void PropertyList(ResourceOrVariable subject, Set<TriplePattern> triplePatterns) : { } {
+    ( PropertyListNotEmpty(subject, triplePatterns) )?
+}
+
+/* [77]    PropertyListNotEmpty ::= Verb ObjectList ( ';' ( Verb ObjectList )? )* */
+private void PropertyListNotEmpty(ResourceOrVariable subject, Set<TriplePattern> triplePatterns) : {
+    UriRefOrVariable predicate;
+    Set<ResourceOrVariable> objects; } {
+    predicate=Verb()
+    objects=ObjectList(triplePatterns) {
+    addTriplePatterns(triplePatterns, subject, predicate, objects); }
+
+    ( ";"
+        ( predicate=Verb() objects=ObjectList(triplePatterns) {
+            addTriplePatterns(triplePatterns, subject, predicate, objects); }
+        )?
+    )*
 }
 
-/* [35]    ObjectList    ::=    Object ( ',' Object )* */
-private Set<ResourceOrVariable> ObjectList(Set<TriplePattern> triplePatterns) : {
-	ResourceOrVariable object; } {
+/* [78]    Verb ::= VarOrIri | 'a' */
+private UriRefOrVariable Verb() : {
+    UriRefOrVariable predicate; } {
 
-	{
-	Set<ResourceOrVariable> objects = new LinkedHashSet<ResourceOrVariable>();
-	}
-	object=Object(triplePatterns) {
-	objects.add(object); }
-
-	( ","
-		object=Object(triplePatterns) {
-			objects.add(object); }
-	)* {
-	return objects; }
+    predicate=VarOrIri() {
+    return predicate; }
+    | "a" {
+    return new UriRefOrVariable(RDF_TYPE); }
 }
 
-/* [36]    Object    ::=    GraphNode */
-private ResourceOrVariable Object(Set<TriplePattern> triplePatterns) : {
-	ResourceOrVariable object; } {
+/* [79]    ObjectList ::= Object ( ',' Object )* */
+private Set<ResourceOrVariable> ObjectList(Set<TriplePattern> triplePatterns) : {
+    ResourceOrVariable object; } {
 
-	object=GraphNode(triplePatterns) {
-	return object; }
+    {
+    Set<ResourceOrVariable> objects = new LinkedHashSet<ResourceOrVariable>();
+    }
+    object=Object(triplePatterns) {
+    objects.add(object); }
+
+    ( ","
+        object=Object(triplePatterns) {
+            objects.add(object); }
+    )* {
+    return objects; }
 }
 
-/* [37]    Verb    ::=    VarOrIRIref | 'a' */
-private UriRefOrVariable Verb() : {
-	UriRefOrVariable predicate; } {
+/* [80]    Object ::= GraphNode */
+private ResourceOrVariable Object(Set<TriplePattern> triplePatterns) : {
+    ResourceOrVariable object; } {
 
-	predicate=VarOrIRIref() {
-	return predicate; }
-	| "a" {
-	return new UriRefOrVariable(RDF_TYPE); }
+    object=GraphNode(triplePatterns) {
+    return object; }
 }
 
+/*
+[81]    TriplesSameSubjectPath ::= VarOrTerm PropertyListPathNotEmpty |    TriplesNodePath PropertyListPath
+[82]    PropertyListPath ::= PropertyListPathNotEmpty?
+[83]    PropertyListPathNotEmpty ::= ( VerbPath | VerbSimple ) ObjectListPath ( ';' ( ( VerbPath | VerbSimple ) ObjectList )? )*
+[84]    VerbPath ::= Path
+[85]    VerbSimple ::= Var
+[86]    ObjectListPath ::= ObjectPath ( ',' ObjectPath )*
+[87]    ObjectPath ::= GraphNodePath
+[88]    Path ::= PathAlternative
+[89]    PathAlternative ::= PathSequence ( '|' PathSequence )*
+[90]    PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )*
+[91]    PathElt ::= PathPrimary PathMod?
+[92]    PathEltOrInverse ::= PathElt | '^' PathElt
+[93]    PathMod ::= '?' | '*' | '+'
+[94]    PathPrimary ::= iri | 'a' | '!' PathNegatedPropertySet | '(' Path ')'
+[95]    PathNegatedPropertySet ::= PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')'
+[96]    PathOneInPropertySet ::= iri | 'a' | '^' ( iri | 'a' )
+[97]    Integer ::= INTEGER
+*/
+
 // Fill in the specified set of TriplePattern and returns the subject node
-/* [38]    TriplesNode    ::=    Collection |  BlankNodePropertyList */
+/* [98]    TriplesNode ::= Collection |  BlankNodePropertyList */
 private ResourceOrVariable TriplesNode(Set<TriplePattern> triplePatterns) : {
-	ResourceOrVariable subject; } {
-	(
-		subject=Collection(triplePatterns)
-	|
-		subject=BlankNodePropertyList(triplePatterns)
-	) {
-	return subject; }
+    ResourceOrVariable subject; } {
+    (
+        subject=Collection(triplePatterns)
+    |
+        subject=BlankNodePropertyList(triplePatterns)
+    ) {
+    return subject; }
 }
 
-/* [39]    BlankNodePropertyList    ::=    '[' PropertyListNotEmpty ']' */
+/* [99]    BlankNodePropertyList ::= '[' PropertyListNotEmpty ']' */
 private ResourceOrVariable BlankNodePropertyList(Set<TriplePattern> triplePatterns) : { } {
-	{
-	ResourceOrVariable subject = getNewBNode();
-	}
-	"[" PropertyListNotEmpty(subject, triplePatterns) "]" {
-	return subject; }
+    {
+    ResourceOrVariable subject = getNewBNode();
+    }
+    "[" PropertyListNotEmpty(subject, triplePatterns) "]" {
+    return subject; }
 }
 
-/* [40]    Collection    ::=    '(' GraphNode+ ')' */
+/*
+[100] TriplesNodePath ::= CollectionPath |    BlankNodePropertyListPath
+[101] BlankNodePropertyListPath ::= '[' PropertyListPathNotEmpty ']'
+*/
+
+/* [102]    Collection ::= '(' GraphNode+ ')' */
 private ResourceOrVariable Collection(Set<TriplePattern> triplePatterns) : {
-	ResourceOrVariable node;
-	List<ResourceOrVariable> nodes = new ArrayList<ResourceOrVariable>(); } {
+    ResourceOrVariable node;
+    List<ResourceOrVariable> nodes = new ArrayList<ResourceOrVariable>(); } {
 
-	"("
-		(
-		node=GraphNode(triplePatterns) {
-		nodes.add(node); }
-		)+
-	")" {
-	return addTriplePatterns(triplePatterns, nodes); }
+    "("
+        (
+        node=GraphNode(triplePatterns) {
+        nodes.add(node); }
+        )+
+    ")" {
+    return addTriplePatterns(triplePatterns, nodes); }
 }
 
-/* [41]    GraphNode    ::=    VarOrTerm |  TriplesNode */
+/* [103]    CollectionPath ::= '(' GraphNodePath+ ')' */
+
+
+/* [104]    GraphNode ::= VarOrTerm |  TriplesNode */
 private ResourceOrVariable GraphNode(Set<TriplePattern> triplePatterns) : {
-	ResourceOrVariable node; } {
+    ResourceOrVariable node; } {
 
-	(
-	node=VarOrTerm()
-	|
-	node=TriplesNode(triplePatterns)
-	) {
-	return node; }
+    (
+    node=VarOrTerm()
+    |
+    node=TriplesNode(triplePatterns)
+    ) {
+    return node; }
 }
 
-/* [42]    VarOrTerm    ::=    Var | GraphTerm */
+/* [105]    GraphNodePath ::= VarOrTerm |    TriplesNodePath */
+
+/* [106]    VarOrTerm ::= Var | GraphTerm */
 private ResourceOrVariable VarOrTerm() : {
-	ResourceOrVariable r;
-	Variable v; } {
+    ResourceOrVariable r;
+    Variable v; } {
 
     (
-	v=Var() {
-	return new ResourceOrVariable(v); }
-	|
-	r=GraphTerm() {
-	return r; }
-	)
+    v=Var() {
+    return new ResourceOrVariable(v); }
+    |
+    r=GraphTerm() {
+    return r; }
+    )
 }
 
-/* [43]    VarOrIRIref    ::=    Var | IRIref */
-private UriRefOrVariable VarOrIRIref() : {
-	Variable var;
-	UriRef uriRef; } {
+/* [107]    VarOrIri ::= Var | iri */
+private UriRefOrVariable VarOrIri() : {
+    Variable var;
+    UriRef uriRef; } {
 
-	(
-	var=Var() {
-	return new UriRefOrVariable(var); }
-	|
-	uriRef=IRIref() {
-	return new UriRefOrVariable(uriRef); }
-	)
+    (
+    var=Var() {
+    return new UriRefOrVariable(var); }
+    |
+    uriRef=Iri() {
+    return new UriRefOrVariable(uriRef); }
+    )
 }
 
-/* [44]    Var    ::=    VAR1 | VAR2 */
+/* [108]    Var ::= VAR1 | VAR2 */
 private Variable Var() : {
-	Token t;} {
+    Token t;} {
 
-	(t=<VAR1> | t=<VAR2>) {
-	return getVariable(t.image); }
+    (t=<VAR1> | t=<VAR2>) {
+    return createVariable(t.image); }
 }
 
-/* [45]    GraphTerm    ::=    IRIref |  RDFLiteral |  NumericLiteral |  BooleanLiteral |  BlankNode |  NIL */
+private String BuiltInCallName() : {
+    Token t;} {
+
+    t=<BUILT_IN_CALL_NAME> {
+    return t.image; }
+}
+
+/* [109]    GraphTerm ::= Iri | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL */
 private ResourceOrVariable GraphTerm() : {
-	ResourceOrVariable bNode = null;
-	Resource r = null; } {
+    ResourceOrVariable bNode = null;
+    Resource r = null; } {
 
-	(r=IRIref() | r=RDFLiteral() | r=NumericLiteral() | r=BooleanLiteral() | bNode=BlankNode() | <NIL> {
-		r = RDF_NIL; }) {
-	if (bNode == null) {
-		return new ResourceOrVariable(r);
-	}
-	return bNode; }
+    (r=Iri() | r=RDFLiteral() | r=NumericLiteral() | r=BooleanLiteral() | bNode=BlankNode() | <NIL> {
+        r = RDF_NIL; }) {
+    if (bNode == null) {
+        return new ResourceOrVariable(r);
+    }
+    return bNode; }
 }
 
-/* [46]    Expression    ::=    ConditionalOrExpression */
+/* [110]    Expression ::= ConditionalOrExpression */
 private Expression Expression() : {
-	Expression e; } {
+    Expression e; } {
 
-	e=ConditionalOrExpression() {
-	return e; }
+    e=ConditionalOrExpression() {
+    return e; }
 }
 
-/* [47]    ConditionalOrExpression    ::=    ConditionalAndExpression ( '||' ConditionalAndExpression )* */
+/* [111]    ConditionalOrExpression ::= ConditionalAndExpression ( '||' ConditionalAndExpression )* */
 private Expression ConditionalOrExpression() : {
-	Expression e, ae; } {
+    Expression e, ae; } {
 
-	e=ConditionalAndExpression()
-	( "||"
-		ae=ConditionalAndExpression() {
-		e = new BinaryOperation("||", e, ae); }
-	)* {
-	return e; }
+    e=ConditionalAndExpression()
+    (
+        "||" ae=ConditionalAndExpression() {
+        e = new BinaryOperation("||", e, ae); }
+    )* {
+    return e; }
 }
 
-/* [48]    ConditionalAndExpression    ::=    ValueLogical ( '&&' ValueLogical )* */
+/* [112]    ConditionalAndExpression ::= ValueLogical ( '&&' ValueLogical )* */
 private Expression ConditionalAndExpression() : {
-	Expression e, e2; } {
+    Expression e, e2; } {
 
-	e=ValueLogical()
-	( "&&"
-		e2=ValueLogical() {
-		e = new BinaryOperation("&&", e, e2); }
-	)* {
-	return e; }
+    e=ValueLogical()
+    (
+        "&&" e2=ValueLogical() {
+        e = new BinaryOperation("&&", e, e2); }
+    )* {
+    return e; }
 }
 
-/* [49]    ValueLogical    ::=    RelationalExpression */
+/* [113]    ValueLogical ::= RelationalExpression */
 private Expression ValueLogical() : {
-	Expression e; } {
+    Expression e; } {
 
-	e=RelationalExpression() {
-	return e; }
+    e=RelationalExpression() {
+    return e; }
 }
 
-/* [50]    RelationalExpression    ::=    NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression )? */
+/* [114]    RelationalExpression ::= NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression | 'IN' ExpressionList | 'NOT' 'IN' ExpressionList )? */
 private Expression RelationalExpression() : {
-	Expression e, e2; } {
+    Expression e, e2; 
+    List<Expression> l; } {
 
-	e=NumericExpression()
-	(
-		"=" e2=NumericExpression() {
-			e = new BinaryOperation("=", e, e2); }
-		| "!=" e2=NumericExpression() {
-			e = new BinaryOperation("!=", e, e2); }
-		| "<" e2=NumericExpression() {
-			e = new BinaryOperation("<", e, e2); }
-		| ">" e2=NumericExpression() {
-			e = new BinaryOperation(">", e, e2); }
-		| "<=" e2=NumericExpression() {
-			e = new BinaryOperation("<=", e, e2); }
-		| ">=" e2=NumericExpression() {
-			e = new BinaryOperation(">=", e, e2); }
-	)? {
-	return e; }
+    e=NumericExpression()
+    (
+        "=" e2=NumericExpression() {
+        e = new BinaryOperation("=", e, e2); }
+    |
+        "!=" e2=NumericExpression() {
+        e = new BinaryOperation("!=", e, e2); }
+    |
+        "<" e2=NumericExpression() {
+        e = new BinaryOperation("<", e, e2); }
+    |
+        ">" e2=NumericExpression() {
+        e = new BinaryOperation(">", e, e2); }
+    |
+        "<=" e2=NumericExpression() {
+        e = new BinaryOperation("<=", e, e2); }
+    |
+        ">=" e2=NumericExpression() {
+        e = new BinaryOperation(">=", e, e2); }
+    |
+        <IN> l=ExpressionList() {
+        e = new RhsListBinaryOperation("IN", e, l); }
+    |
+        <NOT> <IN> l=ExpressionList() {
+        e = new RhsListBinaryOperation("NOT IN", e, l); }
+    )? {
+    return e; }
 }
 
-/* [51]    NumericExpression    ::=    AdditiveExpression */
+/* [115]    NumericExpression ::= AdditiveExpression */
 private Expression NumericExpression() : {
-	Expression e; } {
+    Expression e; } {
 
-	e=AdditiveExpression() {
-	return e; }
+    e=AdditiveExpression() {
+    return e; }
 }
 
-/* [52]    AdditiveExpression    ::=    MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | NumericLiteralPositive | NumericLiteralNegative )* */
+/* [116]    AdditiveExpression ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( ( '*' UnaryExpression ) | ( '/' UnaryExpression ) )* )* */
 private Expression AdditiveExpression() : {
-	Expression e, e2;
-	TypedLiteral l; } {
+    Expression e, e2, u;
+    TypedLiteral l; } {
 
-	e=MultiplicativeExpression()
-	(
-		"+" e2=MultiplicativeExpression() {
-			e = new BinaryOperation("+", e, e2); }
-		| "-" e2=MultiplicativeExpression() {
-			e = new BinaryOperation("-", e, e2); }
-		| l=NumericLiteralPositive() {
-			e = new BinaryOperation("+", e, new LiteralExpression(l)); }
-		| l=NumericLiteralNegative() {
-			e = new BinaryOperation("-", e, new LiteralExpression(l)); }
-	)* {
-	return e; }
+    e=MultiplicativeExpression()
+    (
+        "+" e2=MultiplicativeExpression() {
+        e = new BinaryOperation("+", e, e2); }
+    |
+        "-" e2=MultiplicativeExpression() {
+        e = new BinaryOperation("-", e, e2); }
+    |
+        (
+            (
+                l=NumericLiteralPositive()
+            |
+                l=NumericLiteralNegative()
+            ) {
+            e2 = new LiteralExpression(l); }
+            (
+                "*" u=UnaryExpression() {
+                e2 = new BinaryOperation("*", e2, u); }
+            |
+                "/" u=UnaryExpression() {
+                e2 = new BinaryOperation("/", e2, u); }
+            )*
+        ) {
+        e = new BinaryOperation("+", e, e2); }
+    )* {
+    return e; }
 }
 
-/* [53]    MultiplicativeExpression    ::=    UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )* */
+/* [117]    MultiplicativeExpression ::= UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )* */
 private Expression MultiplicativeExpression() : {
-	Expression e, e2; } {
+    Expression e, e2; } {
 
-	e=UnaryExpression()
-	(
-		"*" e2=UnaryExpression() {
-			e = new BinaryOperation("*", e, e2); }
-		| "/" e2=UnaryExpression() {
-			e = new BinaryOperation("/", e, e2); }
-	)* {
-	return e; }
+    e=UnaryExpression()
+    (
+        "*" e2=UnaryExpression() {
+        e = new BinaryOperation("*", e, e2); }
+    |
+        "/" e2=UnaryExpression() {
+        e = new BinaryOperation("/", e, e2); }
+    )* {
+    return e; }
 }
 
-/* [54]    UnaryExpression    ::=      '!' PrimaryExpression  |  '+' PrimaryExpression  | '-' PrimaryExpression  | PrimaryExpression */
+/* [118]    UnaryExpression ::=   '!' PrimaryExpression  |  '+' PrimaryExpression  | '-' PrimaryExpression  | PrimaryExpression */
 private Expression UnaryExpression() : {
-	Expression e; } {
+    Expression e; } {
 
-	"!" e=PrimaryExpression() {
-		return new UnaryOperation("!", e); }
-    | "+" e=PrimaryExpression() {
-		return new UnaryOperation("+", e); }
-    | "-" e=PrimaryExpression() {
-		return new UnaryOperation("-", e); }
-    | e=PrimaryExpression() {
-		return e; }
+        "!" e=PrimaryExpression() {
+        return new UnaryOperation("!", e); }
+    |
+        "+" e=PrimaryExpression() {
+        return new UnaryOperation("+", e); }
+    |
+        "-" e=PrimaryExpression() {
+        return new UnaryOperation("-", e); }
+    |
+        e=PrimaryExpression() {
+        return e; }
 }
 
-/* [55]    PrimaryExpression    ::=    BrackettedExpression | BuiltInCall | IRIrefOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var */
+/* [119]    PrimaryExpression ::= BrackettedExpression | BuiltInCall | iriOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var */
 private Expression PrimaryExpression() : {
-	Expression e = null;
-	Literal l = null; } {
+    Expression e = null;
+    Literal l = null; } {
 
-	(
-	e=BrackettedExpression() | e=BuiltInCall() | e=IRIrefOrFunction() | l=RDFLiteral() | l=NumericLiteral() | l=BooleanLiteral() | e=Var()
-	) {
-	if (l != null) {
-		return new LiteralExpression(l);
-	}
-	return e; }
+    (
+        e=BrackettedExpression()
+/* There is a capture all names in BuiltInCall, so put it last
+    |
+        e=BuiltInCall()
+*/
+    |
+        e=IriOrFunction()
+    |
+        l=RDFLiteral()
+    |
+        l=NumericLiteral()
+    |
+        l=BooleanLiteral()
+    |
+        e=Var()
+    |
+        e=BuiltInCall()
+    ) {
+    if (l != null) {
+        return new LiteralExpression(l);
+    }
+    return e; }
 }
 
-/* [56]    BrackettedExpression    ::=    '(' Expression ')' */
+/* [120]    BrackettedExpression ::= '(' Expression ')' */
 private Expression BrackettedExpression() : {
-	Expression e; } {
+    Expression e; } {
+
+    "("
+    e=Expression()
+    ")" {
+    return e; }
+}
+
+/* [121]    BuiltInCall ::= Aggregate 
+|    'STR' '(' Expression ')' 
+|    'LANG' '(' Expression ')' 
+|    'LANGMATCHES' '(' Expression ',' Expression ')' 
+|    'DATATYPE' '(' Expression ')' 
+|    'BOUND' '(' Var ')' 
+|    'IRI' '(' Expression ')' 
+|    'URI' '(' Expression ')' 
+|    'BNODE' ( '(' Expression ')' | NIL ) 
+|    'RAND' NIL 
+|    'ABS' '(' Expression ')' 
+|    'CEIL' '(' Expression ')' 
+|    'FLOOR' '(' Expression ')' 
+|    'ROUND' '(' Expression ')' 
+|    'CONCAT' ExpressionList 
+|    SubstringExpression 
+|    'STRLEN' '(' Expression ')' 
+|    StrReplaceExpression 
+|    'UCASE' '(' Expression ')' 
+|    'LCASE' '(' Expression ')' 
+|    'ENCODE_FOR_URI' '(' Expression ')' 
+|    'CONTAINS' '(' Expression ',' Expression ')' 
+|    'STRSTARTS' '(' Expression ',' Expression ')' 
+|    'STRENDS' '(' Expression ',' Expression ')' 
+|    'STRBEFORE' '(' Expression ',' Expression ')' 
+|    'STRAFTER' '(' Expression ',' Expression ')' 
+|    'YEAR' '(' Expression ')' 
+|    'MONTH' '(' Expression ')' 
+|    'DAY' '(' Expression ')' 
+|    'HOURS' '(' Expression ')' 
+|    'MINUTES' '(' Expression ')' 
+|    'SECONDS' '(' Expression ')' 
+|    'TIMEZONE' '(' Expression ')' 
+|    'TZ' '(' Expression ')' 
+|    'NOW' NIL 
+|    'UUID' NIL 
+|    'STRUUID' NIL 
+|    'MD5' '(' Expression ')' 
+|    'SHA1' '(' Expression ')' 
+|    'SHA256' '(' Expression ')' 
+|    'SHA384' '(' Expression ')' 
+|    'SHA512' '(' Expression ')' 
+|    'COALESCE' ExpressionList 
+|    'IF' '(' Expression ',' Expression ',' Expression ')' 
+|    'STRLANG' '(' Expression ',' Expression ')' 
+|    'STRDT' '(' Expression ',' Expression ')' 
+|    'sameTerm' '(' Expression ',' Expression ')' 
+|    'isIRI' '(' Expression ')' 
+|    'isURI' '(' Expression ')' 
+|    'isBLANK' '(' Expression ')' 
+|    'isLITERAL' '(' Expression ')' 
+|    'isNUMERIC' '(' Expression ')' 
+|    RegexExpression 
+|    ExistsFunc 
+|    NotExistsFunc
+
+[122]    RegexExpression ::= 'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
+[123]    SubstringExpression ::= 'SUBSTR' '(' Expression ',' Expression ( ',' Expression )? ')'
+[124]    StrReplaceExpression ::= 'REPLACE' '(' Expression ',' Expression ',' Expression ( ',' Expression )? ')'
+
+[127]    Aggregate ::= 'COUNT' '(' 'DISTINCT'? ( '*' | Expression ) ')' 
+| 'SUM' '(' 'DISTINCT'? Expression ')' 
+| 'MIN' '(' 'DISTINCT'? Expression ')' 
+| 'MAX' '(' 'DISTINCT'? Expression ')' 
+| 'AVG' '(' 'DISTINCT'? Expression ')' 
+| 'SAMPLE' '(' 'DISTINCT'? Expression ')' 
+| 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
+
+*/
 
-	"("
-	e=Expression()
-	")" {
-	return e; }
-}
-
-/* [57]    BuiltInCall    ::=      'STR' '(' Expression ')' */
-/* |  'LANG' '(' Expression ')' */
-/* |  'LANGMATCHES' '(' Expression ',' Expression ')' */
-/* |  'DATATYPE' '(' Expression ')' */
-/* |  'BOUND' '(' Var ')' */
-/* |  'sameTerm' '(' Expression ',' Expression ')' */
-/* |  'isIRI' '(' Expression ')' */
-/* |  'isURI' '(' Expression ')' */
-/* |  'isBLANK' '(' Expression ')' */
-/* |  'isLITERAL' '(' Expression ')' */
-/* |  RegexExpression */
 private BuiltInCall BuiltInCall() : {
-	List<Expression> args = new ArrayList<Expression>();
-	String name;
-	Expression e; } {
-	(
-	<STR> {
-		name = "STR"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <LANG> {
-		name = "LANG"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <LANGMATCHES> {
-		name = "LANGMATCHES"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		","
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <DATATYPE> {
-		name = "DATATYPE"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <BOUND> {
-		name = "BOUND"; }
-		"("
-		e=Var() {
-		args.add(e); }
-		")"
-	| <SAME_TERM> {
-		name = "sameTerm"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		","
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <IS_IRI> {
-		name = "isIRI"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <IS_URI> {
-		name = "isURI"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <IS_BLANK> {
-		name = "isBLANK"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| <IS_LITERAL> {
-		name = "isLITERAL"; }
-		"("
-		e=Expression() {
-		args.add(e); }
-		")"
-	| e=RegexExpression() {
-		return (BuiltInCall) e; }
-	) {
-		return new BuiltInCall(name, args);
-	}
-}
-
-/* [58]    RegexExpression    ::=    'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')' */
-private BuiltInCall RegexExpression() : {
-	List<Expression> args = new ArrayList<Expression>();
-	Expression e = null; } {
-
-	<REGEX>
-	"("
-	e=Expression() {
-	args.add(e); }
-	","
-	e=Expression() {
-	args.add(e); }
-	(
-		","
-		e=Expression() {
-		args.add(e); }
-	)?
-	")" {
-	return new BuiltInCall("REGEX", args); }
-}
-
-/* [59]    IRIrefOrFunction    ::=    IRIref ArgList? */
-private Expression IRIrefOrFunction() : {
-	UriRef uriRef;
-	List<Expression> args; } {
-
-	uriRef=IRIref()
-	(
-		args=ArgList() {
-		return new FunctionCall(uriRef, args); }
-	)? {
-	return new UriRefExpression(uriRef); }
+    List<Expression> args = new ArrayList<Expression>();
+    String name, s;
+    Expression e; } {
+    (
+        <GROUP_CONCAT> {
+        name = "GROUP_CONCAT"; }
+        "("
+        (
+            <DISTINCT>
+        )?
+        (
+            e=Expression() {
+            args.add(e); }
+            (
+                ";"
+                <SEPARATOR>
+                "="
+                s = String()
+            )?
+        )
+        ")"
+    |
+        <BOUND> {
+        name = "BOUND"; }
+        "("
+        e=Var() {
+        args.add(e); }
+        ")"
+    |
+        <BNODE> {
+        name = "BNODE"; }
+        (
+            (
+                "("
+                e=Expression() {
+                args.add(e); }
+                ")"
+            )
+        |
+            <NIL>
+        )
+    |
+        <RAND> {
+        name = "RAND"; }
+        <NIL>
+    |
+        <CONCAT> {
+        name = "CONCAT"; }
+        args=ExpressionList()
+    |
+        <NOW> {
+        name = "NOW"; }
+        <NIL>
+    |
+        <UUID> {
+        name = "UUID"; }
+        <NIL>
+    |
+        <STRUUID> {
+        name = "STRUUID"; }
+        <NIL>
+    |
+        <COALESCE> {
+        name = "COALESCE"; }
+        args=ExpressionList()
+/*
+    |
+        e=NotExistsFunc() {
+        return (BuiltInCall) e; }
+*/
+    |
+        name=BuiltInCallName()
+        "("
+        (
+            <DISTINCT>
+        )?
+        (
+            "*"
+        |
+            (
+                e=Expression() {
+                args.add(e); }
+                (
+                    ","
+                    e=Expression() {
+                    args.add(e); }
+                )*
+            )
+        )
+        ")"
+    ) {
+    return new BuiltInCall(name, args); }
+}
+
+/*
+[125]    ExistsFunc ::= 'EXISTS' GroupGraphPattern
+[126]    NotExistsFunc ::= 'NOT' 'EXISTS' GroupGraphPattern
+*/
+
+/* [128]    IriOrFunction ::= iri ArgList? */
+private Expression IriOrFunction() : {
+    UriRef uriRef;
+    List<Expression> args; } {
+
+    uriRef=Iri()
+    (
+        args=ArgList() {
+        return new FunctionCall(uriRef, args); }
+    )? {
+    return new UriRefExpression(uriRef); }
 }
 
-/* [60]    RDFLiteral    ::=    String ( LANGTAG | ( '^^' IRIref ) )? */
+/* [129]    RDFLiteral ::= String ( LANGTAG | ( '^^' iri ) )? */
 private Literal RDFLiteral() : {
-	Token t;
-	String s;
-	UriRef type; } {
-
-	s = String()
-	(
-		t=<LANGTAG> {
-		return new PlainLiteralImpl(s, new Language(t.image.substring(1))); }
-		|
-		( "^^"
-			type=IRIref() {
-			return new TypedLiteralImpl(s, type); }
-		)
-	)? {
-	return new PlainLiteralImpl(s); }
+    Token t;
+    String s;
+    UriRef type; } {
+
+    s = String()
+    (
+        t=<LANGTAG> {
+        return new PlainLiteralImpl(s, new Language(t.image.substring(1))); }
+    |
+        (
+            "^^"
+            type=Iri() {
+            return new TypedLiteralImpl(s, type); }
+        )
+    )? {
+    return new PlainLiteralImpl(s); }
 }
 
-/* [61]    NumericLiteral    ::=    NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative */
+/* [130]    NumericLiteral ::= NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative */
 private TypedLiteral NumericLiteral() : {
-	TypedLiteral l; } {
+    TypedLiteral l; } {
 
-	( l=NumericLiteralUnsigned() | l=NumericLiteralPositive() | l=NumericLiteralNegative() ) {
-	return l; }
+    (
+        l=NumericLiteralUnsigned()
+    |
+        l=NumericLiteralPositive()
+    |
+        l=NumericLiteralNegative()
+    ) {
+    return l; }
 }
 
-/* [62]    NumericLiteralUnsigned    ::=    INTEGER |  DECIMAL |  DOUBLE */
+/* [131]    NumericLiteralUnsigned ::= INTEGER |  DECIMAL |  DOUBLE */
 private TypedLiteral NumericLiteralUnsigned() : {
-	Token t; } {
+    Token t; } {
 
-	t=<INTEGER> {
-		return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
-	| t=<DECIMAL> {
-		return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
-	| t=<DOUBLE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
+        t=<INTEGER> {
+        return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
+    |
+        t=<DECIMAL> {
+        return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
+    |
+        t=<DOUBLE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
 }
 
-/* [63]    NumericLiteralPositive    ::=    INTEGER_POSITIVE |  DECIMAL_POSITIVE |  DOUBLE_POSITIVE */
+/* [132]    NumericLiteralPositive ::= INTEGER_POSITIVE |  DECIMAL_POSITIVE |  DOUBLE_POSITIVE */
 private TypedLiteral NumericLiteralPositive() : {
-	Token t; } {
+    Token t; } {
 
-	t=<INTEGER_POSITIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
-	| t=<DECIMAL_POSITIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
-	| t=<DOUBLE_POSITIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
+        t=<INTEGER_POSITIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
+    |
+        t=<DECIMAL_POSITIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
+    |
+        t=<DOUBLE_POSITIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
 }
 
-/* [64]    NumericLiteralNegative    ::=    INTEGER_NEGATIVE |  DECIMAL_NEGATIVE |  DOUBLE_NEGATIVE */
+/* [133]    NumericLiteralNegative ::= INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE */
 private TypedLiteral NumericLiteralNegative() : {
-	Token t; } {
+    Token t; } {
 
-	t=<INTEGER_NEGATIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
-	| t=<DECIMAL_NEGATIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
-	| t=<DOUBLE_NEGATIVE> {
-		return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
+        t=<INTEGER_NEGATIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); }
+    |
+        t=<DECIMAL_NEGATIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); }
+    |
+        t=<DOUBLE_NEGATIVE> {
+        return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); }
 }
 
-/* [65]    BooleanLiteral    ::=    'true' |  'false' */
+/* [134]    BooleanLiteral ::= 'true' | 'false' */
 private TypedLiteral BooleanLiteral() : {} {
 
-	<TRUE> {
-		return LiteralFactory.getInstance().createTypedLiteral(true); }
-	| <FALSE> {
-		return LiteralFactory.getInstance().createTypedLiteral(false); }
+        <TRUE> {
+        return LiteralFactory.getInstance().createTypedLiteral(true); }
+    |
+        <FALSE> {
+        return LiteralFactory.getInstance().createTypedLiteral(false); }
 }
 
-/* [66]    String    ::=    STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 */
+/* [135]    String ::= STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 */
 private String String() : {
-	Token t; } {
-	t=<STRING_LITERAL1> {
-		return unquote(t.image) ; }
-	| t=<STRING_LITERAL2> {
-		return unquote(t.image) ; }
-	| t=<STRING_LITERAL_LONG1> {
-		return unTripleQuote(t.image) ; }
-	| t=<STRING_LITERAL_LONG2> {
-		return unTripleQuote(t.image) ; }
-}
-
-/* [67]    IRIref    ::=    IRI_REF |  PrefixedName */
-private UriRef IRIref() : {
-	UriRef uriRef;
-	Token t; } {
-
-	t=<IRI_REF> {
-	return createUriRef(unquote(t.image)); }
-	|
-	uriRef=PrefixedName() {
-	return uriRef; }
+    Token t; } {
+
+        t=<STRING_LITERAL1> {
+        return unquote(t.image) ; }
+    |
+        t=<STRING_LITERAL2> {
+        return unquote(t.image) ; }
+    |
+        t=<STRING_LITERAL_LONG1> {
+        return unTripleQuote(t.image) ; }
+    |
+        t=<STRING_LITERAL_LONG2> {
+        return unTripleQuote(t.image) ; }
+}
+
+/* [136]    iri ::= IRIREF |  PrefixedName */
+private UriRef Iri() : {
+    UriRef uriRef;
+    Token t; } {
+
+        t=<IRIREF> {
+        return createUriRef(unquote(t.image)); }
+    |
+        uriRef=PrefixedName() {
+        return uriRef; }
 }
 
-/* [68]    PrefixedName    ::=    PNAME_LN | PNAME_NS */
+/* [137]    PrefixedName ::= PNAME_LN | PNAME_NS */
 private UriRef PrefixedName() : {
-	Token t; } {
+    Token t; } {
 
-	( t=<PNAME_LN> | t=<PNAME_NS> ) {
-	return createUriRef(t.image); }
+    ( t=<PNAME_LN> | t=<PNAME_NS> ) {
+    return createUriRef(t.image); }
 }
 
-/* [69]    BlankNode    ::=    BLANK_NODE_LABEL |  ANON */
+/* [138]    BlankNode ::= BLANK_NODE_LABEL | ANON */
 private ResourceOrVariable BlankNode() : {
-	Token t; } {
+    Token t; } {
 
-	t=<BLANK_NODE_LABEL> {
-	return getBNode(t.image); }
-	| <ANON> {
-	return getNewBNode(); }
+        t=<BLANK_NODE_LABEL> {
+        return getBNode(t.image); }
+    |
+        <ANON> {
+        return getNewBNode(); }
 }
 
 
 TOKEN : {
-  /* [70]    IRI_REF    ::=    '<' ([^<>"{}|^`\]-[#x00-#x20])* '>' */
-  < IRI_REF : "<" ( ~["<", ">", "\"", "{", "}", "|", "^", "`", "\\", "\u0000"-"\u0020"] )* ">" >
+  /* [139]    IRIREF ::= '<' ([^<>"{}|^`\]-[#x00-#x20])* '>' */
+  < IRIREF : "<" ( ~["<", ">", "\"", "{", "}", "|", "^", "`", "\\", "\u0000"-"\u0020"] )* ">" >
   |
-  /* [71]    PNAME_NS    ::=    PN_PREFIX? ':' */
+  /* [140]    PNAME_NS ::= PN_PREFIX? ':' */
   < PNAME_NS : (<PN_PREFIX>)? ":" >
   |
-  /* [72]    PNAME_LN    ::=    PNAME_NS PN_LOCAL */
+  /* [141]    PNAME_LN ::= PNAME_NS PN_LOCAL */
   < PNAME_LN : <PNAME_NS> <PN_LOCAL> >
   |
-  /* [73]    BLANK_NODE_LABEL    ::=    '_:' PN_LOCAL */
-  < BLANK_NODE_LABEL : "_:" <PN_LOCAL> >
+  /* [142]    BLANK_NODE_LABEL ::= '_:' ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)? */
+  < BLANK_NODE_LABEL : "_:" ( <PN_CHARS_U> | ["0"-"9"] ) ( ( <PN_CHARS> | "." )* <PN_CHARS> )? >
   |
-  /* [74]    VAR1    ::=    '?' VARNAME */
+  /* [143]    VAR1 ::= '?' VARNAME */
   < VAR1 : "?" <VARNAME> >
   |
-  /* [75]    VAR2    ::=    '$' VARNAME */
+  /* [144]    VAR2 ::= '$' VARNAME */
   < VAR2 : "$" <VARNAME> >
   |
-  /* [76]    LANGTAG    ::=    '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)* */
+  /* [145]    LANGTAG ::= '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)* */
   < LANGTAG : "@" (["a"-"z", "A"-"Z"])+ ( "-" (["a"-"z", "A"-"Z", "0"-"9"])+ )* >
+  |
+  < BUILT_IN_CALL_NAME : ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "0"-"9", "_"])* >
 }
 
 TOKEN : {
@@ -1202,84 +1384,96 @@ TOKEN : {
   |
   < #Z_9r : (<Z_9>)+ >
   |
-   < #Z_9o : (<Z_9>)* >
+  < #Z_9o : (<Z_9>)* >
   |
-  /* [77]    INTEGER    ::=    [0-9]+ */
+  /* [146]    INTEGER ::= [0-9]+ */
   < INTEGER : <Z_9r> >
   |
-  /* [78]    DECIMAL    ::=    [0-9]+ '.' [0-9]* | '.' [0-9]+ */
-  < DECIMAL : ( <Z_9r> "." <Z_9o> ) | ( "." <Z_9r> ) >
+  /* [147]    DECIMAL ::= [0-9]* '.' [0-9]+ */
+  < DECIMAL : <Z_9o> "." <Z_9r> >
   |
-  /* [79]    DOUBLE    ::=    [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT */
+  /* [148]    DOUBLE ::= [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT */
   < DOUBLE : ( <Z_9r> "." <Z_9o>  <EXPONENT> ) | ( "." <Z_9r> <EXPONENT> ) | ( <Z_9r> <EXPONENT> ) >
   |
-  /* [80]    INTEGER_POSITIVE    ::=    '+' INTEGER */
+  /* [149]    INTEGER_POSITIVE ::= '+' INTEGER */
   < INTEGER_POSITIVE : "+" <INTEGER> >
   |
-  /* [81]    DECIMAL_POSITIVE    ::=    '+' DECIMAL */
+  /* [150]    DECIMAL_POSITIVE ::= '+' DECIMAL */
   < DECIMAL_POSITIVE : "+" <DECIMAL> >
   |
-  /* [82]    DOUBLE_POSITIVE    ::=    '+' DOUBLE */
+  /* [151]    DOUBLE_POSITIVE ::= '+' DOUBLE */
   < DOUBLE_POSITIVE : "+" <DOUBLE> >
   |
-  /* [83]    INTEGER_NEGATIVE    ::=    '-' INTEGER */
+  /* [152]    INTEGER_NEGATIVE ::= '-' INTEGER */
   < INTEGER_NEGATIVE : "-" <INTEGER> >
   |
-  /* [84]    DECIMAL_NEGATIVE    ::=    '-' DECIMAL */
+  /* [153]    DECIMAL_NEGATIVE ::= '-' DECIMAL */
   < DECIMAL_NEGATIVE : "-" <DECIMAL> >
   |
-  /* [85]    DOUBLE_NEGATIVE    ::=    '-' DOUBLE */
+  /* [154]    DOUBLE_NEGATIVE ::= '-' DOUBLE */
   < DOUBLE_NEGATIVE : "-" <DOUBLE> >
   |
-  /* [86]    EXPONENT    ::=    [eE] [+-]? [0-9]+ */
+  /* [155]    EXPONENT ::= [eE] [+-]? [0-9]+ */
   < #EXPONENT : ["e","E"] (["+","-"])? <Z_9r> >
 }
 
 TOKEN : {
-  /* [87]    STRING_LITERAL1    ::=    "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'" */
+  /* [156]    STRING_LITERAL1 ::= "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'" */
   < STRING_LITERAL1 : "'" ( ~["'", "\\", "\r", "\n"] | <ECHAR> )* "'" >
   |
-  /* [88]    STRING_LITERAL2    ::=    '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"' */
+  /* [157]    STRING_LITERAL2 ::= '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"' */
   < STRING_LITERAL2 : "\"" ( ~["\"", "\\", "\r", "\n"] | <ECHAR> )* "\"" >
   |
-  /* [89]    STRING_LITERAL_LONG1    ::=    "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''" */
+  /* [158]    STRING_LITERAL_LONG1 ::= "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''" */
   < STRING_LITERAL_LONG1 : "'''" ( ( "'" | "''" )? ( ~["'","\\"] | <ECHAR> ) )* "'''" >
   |
-  /* [90]    STRING_LITERAL_LONG2    ::=    '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""' */
+  /* [159]    STRING_LITERAL_LONG2 ::= '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""' */
   < STRING_LITERAL_LONG2 : "\"\"\"" ( ( "\"" | "\"\"" )? ( ~["\"","\\"] | <ECHAR> ) )* "\"\"\"" >
   |
-  /* [91]    #ECHAR    ::=    '\' [tbnrf\"'] */
+  /* [160]    #ECHAR ::= '\' [tbnrf\"'] */
   < #ECHAR : "\\" ["t","b","n","r","f","\\","\"","'"] >
 }
 
 TOKEN : {
-  /* [92]    NIL    ::=    '(' WS* ')' */
+  /* [161]    NIL ::= '(' WS* ')' */
   < NIL : "(" (<WS>)* ")" >
   |
-  /* [93]    WS    ::=    #x20 | #x9 | #xD | #xA */
+  /* [162]    WS ::= #x20 | #x9 | #xD | #xA */
   < #WS : " " | "\t" | "\n" | "\r" >
   |
-  /* [94]   ANON    ::=    '[' WS* ']' */
+  /* [163]    ANON ::= '[' WS* ']' */
   < ANON : "[" (<WS>)* "]" >
 }
 
 TOKEN : {
-  /* [95]   #PN_CHARS_BASE ::=  [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] */
+  /* [164]    #PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] */
   < #PN_CHARS_BASE : ["A"-"Z", "a"-"z", "\u00C0"-"\u00D6", "\u00D8"-"\u00F6", "\u00F8"-"\u02FF", "\u0370"-"\u037D", "\u037F"-"\u1FFF", "\u200C"-"\u200D", "\u2070"-"\u218F", "\u2C00"-"\u2FEF", "\u3001"-"\uD7FF", "\uF900"-"\uFDCF", "\uFDF0"-"\uFFFD"] >
   |
-  /* [96]   #PN_CHARS_U    ::=  PN_CHARS_BASE | '_' */
+  /* [165]    #PN_CHARS_U ::= PN_CHARS_BASE | '_' */
   < #PN_CHARS_U : <PN_CHARS_BASE> | "_" >
   |
-  /* [97]   #VARNAME  ::=   ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )* */
-  < #VARNAME : (<PN_CHARS_U> | <Z_9>) ( <PN_CHARS_U> | <Z_9> | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"] )* >
+  /* [166]    #VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )* */
+  < #VARNAME : (<PN_CHARS_U> | <Z_9>) (<PN_CHARS_U> | <Z_9> | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"])* >
   |
-  /* [98]   #PN_CHARS  ::=  PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] */
+  /* [167]    #PN_CHARS ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] */
   < #PN_CHARS : <PN_CHARS_U> | "-" | <Z_9> | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"] >
   |
-  /* [99]   PN_PREFIX  ::=  PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)? */
-  < PN_PREFIX : <PN_CHARS_BASE> (( <PN_CHARS> | "." )* <PN_CHARS>)? >
+  /* [168]    PN_PREFIX ::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)? */
+  < PN_PREFIX : <PN_CHARS_BASE> ((<PN_CHARS> | "." )* <PN_CHARS>)? >
   |
-  /* [100]  PN_LOCAL  ::=   ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?  */
+  /* [169]    PN_LOCAL ::= ( PN_CHARS_U | ':' | [0-9] | PLX ) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX) )? */
   /* Note that SPARQL local names allow leading digits while XML local names do not. */
-  < PN_LOCAL : ( <PN_CHARS_U> | <Z_9> ) (( <PN_CHARS> | "." )* <PN_CHARS>)? >
+  < PN_LOCAL : (<PN_CHARS_U> | ":" | <Z_9> | <PLX>) ((<PN_CHARS> | "." | ":" | <PLX>)* (<PN_CHARS> | ":" | <PLX>) )? >
+  |
+  /* [170]    PLX ::= PERCENT | PN_LOCAL_ESC */
+  < PLX : <PERCENT> | <PN_LOCAL_ESC> >
+  |
+  /* [171]    PERCENT ::= '%' HEX HEX */
+  < PERCENT : "%" <HEX> <HEX> >
+  |
+  /* [172]    HEX ::= [0-9] | [A-F] | [a-f] */
+  < #HEX : <Z_9> | ["A"-"F", "a"-"f"] >
+  |
+  /* [173]    PN_LOCAL_ESC ::= '\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%' ) */
+  < PN_LOCAL_ESC : "\\" ( "_" | "~" | "." | "-" | "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "=" | "/" | "?" | "#" | "@" | "%" ) >
 }

Added: clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java?rev=1460522&view=auto
==============================================================================
--- clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java (added)
+++ clerezza/trunk/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java Mon Mar 25 05:05:11 2013
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.core.sparql;
+
+import java.util.Set;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.sparql.update.Update;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author hasan
+ */
+public class SparqlPreParserTest {
+
+    @Test
+    public void testDefaultGraphInSelectQuery() throws ParseException {
+
+        StringBuilder queryStrBuilder = new StringBuilder();
+        queryStrBuilder.append(
+                "PREFIX : <http://example/>\n" +
+                "SELECT ?x \n" +
+                "{\n" +
+                ":order :item/:price ?x\n" +
+                "}\n");
+
+        UriRef defaultGraph = new UriRef("http://example.org/default");
+        SparqlPreParser parser = new SparqlPreParser();
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), defaultGraph);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(defaultGraph));
+    }
+
+    @Test
+    public void testSelectQuery() throws ParseException {
+
+        StringBuilder queryStrBuilder = new StringBuilder();
+        queryStrBuilder.append(
+                "PREFIX : <http://example/>\n" +
+                "SELECT ?x (foo(2*3, ?x < ?y) AS ?f) (GROUP_CONCAT(?x ; separator=\"|\") AS ?gc) (sum(distinct *) AS ?total)\n" +
+                "FROM <http://example.org/test>\n" +
+                "{\n" +
+                ":order :item/:price ?x\n" +
+                "}\n");
+
+        UriRef defaultGraph = new UriRef("http://example.org/default");
+        SparqlPreParser parser = new SparqlPreParser();
+        Set<UriRef> referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), defaultGraph);
+        Assert.assertTrue(referredGraphs.toArray()[0].equals(new UriRef("http://example.org/test")));
+    }
+}



Mime
View raw message