Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2DC19F81E for ; Mon, 25 Mar 2013 05:05:46 +0000 (UTC) Received: (qmail 88089 invoked by uid 500); 25 Mar 2013 05:05:45 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 88057 invoked by uid 500); 25 Mar 2013 05:05:45 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 88047 invoked by uid 99); 25 Mar 2013 05:05:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Mar 2013 05:05:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Mar 2013 05:05:36 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id EC1A9238890D; Mon, 25 Mar 2013 05:05:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@clerezza.apache.org From: hasan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130325050512.EC1A9238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 */ -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 prefixes; - private Map bNodes; - private int count; - private Map vars; - - void initialize() { - query = null; - base = null; - prefixes = new HashMap(); - bNodes = new HashMap(); - count = 0; - vars = new HashMap(); - } - - 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 triplePatterns, - ResourceOrVariable subject, - UriRefOrVariable predicate, - Set objects) { - - for (ResourceOrVariable object : objects) { - triplePatterns.add( - new SimpleTriplePattern(subject, predicate, object)); - } - } - - // nodes contain at least one element - private ResourceOrVariable addTriplePatterns( - Set triplePatterns, - List 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 true if the URI appears to be relative, false 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 prefixes; + private Map bNodes; + private int count; + + void initialize() { + base = null; + prefixes = new HashMap(); + bNodes = new HashMap(); + 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 triplePatterns, + ResourceOrVariable subject, + UriRefOrVariable predicate, + Set objects) { + + for (ResourceOrVariable object : objects) { + triplePatterns.add( + new SimpleTriplePattern(subject, predicate, object)); + } + } + + // nodes contain at least one element + private ResourceOrVariable addTriplePatterns( + Set triplePatterns, + List 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 true if the URI appears to be relative, false 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() ) -} - -/* [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; } { - iriRef= { base = unquote(iriRef.image); } + 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; } { - ns= iriRef= { - 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; } { - - { + query = new SimpleSelectQuery(); } + ( + { + ((SimpleSelectQuery) query).setDistinct(); } + | + { + ((SimpleSelectQuery) query).setReduced(); } + )? + ( + ( + v=Var() { + ((SimpleSelectQuery) query).addSelection(v); } + | + ( + "(" + e=Expression() + + 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 triplePatterns = null; } { -/* [22] GraphPatternNotTriples ::= OptionalGraphPattern | GroupOrUnionGraphPattern | GraphGraphPattern */ -private void GraphPatternNotTriples(GroupGraphPattern groupGraphPattern) : {} { + + ( + 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) - ) + { + 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=GroupGraphPattern() { - ((SimpleGroupGraphPattern) groupGraphPattern).addOptionalGraphPattern(optional); } + { + query = new SimpleAskQuery(); } + ( DatasetClause(query) )* { + return query; } } -/* [24] GraphGraphPattern ::= 'GRAPH' VarOrIRIref GroupGraphPattern */ -private void GraphGraphPattern(GroupGraphPattern groupGraphPattern) : { - UriRefOrVariable graph; - GroupGraphPattern g; } { - - - graph=VarOrIRIref() - g=GroupGraphPattern() { - ((SimpleGroupGraphPattern) groupGraphPattern).addGraphPattern( - new SimpleGraphGraphPattern(graph, g)); } +/* [13] DatasetClause ::= 'FROM' ( DefaultGraphClause | NamedGraphClause ) */ +private void DatasetClause(Query query) : {} { + (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() - ( - { - 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; } { - - c=Constraint() { - return c; } + 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 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; } { + { + 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 ArgList() : { - List args = new ArrayList(); - Expression e; } { + List args = new ArrayList(); + Expression e; } { - ( - - | - ( - "(" - e=Expression() { - args.add(e); } - ( "," - e=Expression() { - args.add(e); } - )* - ")" - ) - ) { - return args; } + ( + + | + ( + "(" + ( + + )? + e=Expression() { + args.add(e); } + ( + "," + e=Expression() { + args.add(e); } + )* + ")" + ) + ) { + return args; } +} + +/* [72] ExpressionList ::= NIL | '(' Expression ( ',' Expression )* ')' */ +private List ExpressionList() : { + List args = new ArrayList(); + Expression e; } { + + ( + + | + ( + "(" + e=Expression() { + args.add(e); } + ( + "," + e=Expression() { + args.add(e); } + )* + ")" + ) + ) { + return args; } } -/* [30] ConstructTemplate ::= '{' ConstructTriples? '}' */ +/* [73] ConstructTemplate ::= '{' ConstructTriples? '}' */ private Set ConstructTemplate() : { - Set triplePatterns = null; } { + Set triplePatterns = null; } { - "{" ( - triplePatterns=ConstructTriples() - )? "}" { - return triplePatterns; } + "{" ( + triplePatterns=ConstructTriples() + )? "}" { + return triplePatterns; } } -/* [31] ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )? */ +/* [74] ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )? */ private Set ConstructTriples() : { - Set triplePatterns, t; } { + Set 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 TriplesSameSubject() : { - Set triplePatterns = new LinkedHashSet(); - ResourceOrVariable subject; } { + Set triplePatterns = new LinkedHashSet(); + 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 triplePatterns) : { - UriRefOrVariable predicate; - Set 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 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 triplePatterns) : { } { + ( PropertyListNotEmpty(subject, triplePatterns) )? +} + +/* [77] PropertyListNotEmpty ::= Verb ObjectList ( ';' ( Verb ObjectList )? )* */ +private void PropertyListNotEmpty(ResourceOrVariable subject, Set triplePatterns) : { + UriRefOrVariable predicate; + Set 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 ObjectList(Set triplePatterns) : { - ResourceOrVariable object; } { +/* [78] Verb ::= VarOrIri | 'a' */ +private UriRefOrVariable Verb() : { + UriRefOrVariable predicate; } { - { - Set objects = new LinkedHashSet(); - } - 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 triplePatterns) : { - ResourceOrVariable object; } { +/* [79] ObjectList ::= Object ( ',' Object )* */ +private Set ObjectList(Set triplePatterns) : { + ResourceOrVariable object; } { - object=GraphNode(triplePatterns) { - return object; } + { + Set objects = new LinkedHashSet(); + } + 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 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 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 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 triplePatterns) : { - ResourceOrVariable node; - List nodes = new ArrayList(); } { + ResourceOrVariable node; + List nodes = new ArrayList(); } { - "(" - ( - 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 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= | t=) { - return getVariable(t.image); } + (t= | t=) { + return createVariable(t.image); } } -/* [45] GraphTerm ::= IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL */ +private String BuiltInCallName() : { + Token t;} { + + t= { + 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() | { - r = RDF_NIL; }) { - if (bNode == null) { - return new ResourceOrVariable(r); - } - return bNode; } + (r=Iri() | r=RDFLiteral() | r=NumericLiteral() | r=BooleanLiteral() | bNode=BlankNode() | { + 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 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); } + | + l=ExpressionList() { + e = new RhsListBinaryOperation("IN", e, l); } + | + 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 args = new ArrayList(); - String name; - Expression e; } { - ( - { - name = "STR"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - name = "LANG"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - name = "LANGMATCHES"; } - "(" - e=Expression() { - args.add(e); } - "," - e=Expression() { - args.add(e); } - ")" - | { - name = "DATATYPE"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - name = "BOUND"; } - "(" - e=Var() { - args.add(e); } - ")" - | { - name = "sameTerm"; } - "(" - e=Expression() { - args.add(e); } - "," - e=Expression() { - args.add(e); } - ")" - | { - name = "isIRI"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - name = "isURI"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - name = "isBLANK"; } - "(" - e=Expression() { - args.add(e); } - ")" - | { - 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 args = new ArrayList(); - Expression e = null; } { - - - "(" - 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 args; } { - - uriRef=IRIref() - ( - args=ArgList() { - return new FunctionCall(uriRef, args); } - )? { - return new UriRefExpression(uriRef); } + List args = new ArrayList(); + String name, s; + Expression e; } { + ( + { + name = "GROUP_CONCAT"; } + "(" + ( + + )? + ( + e=Expression() { + args.add(e); } + ( + ";" + + "=" + s = String() + )? + ) + ")" + | + { + name = "BOUND"; } + "(" + e=Var() { + args.add(e); } + ")" + | + { + name = "BNODE"; } + ( + ( + "(" + e=Expression() { + args.add(e); } + ")" + ) + | + + ) + | + { + name = "RAND"; } + + | + { + name = "CONCAT"; } + args=ExpressionList() + | + { + name = "NOW"; } + + | + { + name = "UUID"; } + + | + { + name = "STRUUID"; } + + | + { + name = "COALESCE"; } + args=ExpressionList() +/* + | + e=NotExistsFunc() { + return (BuiltInCall) e; } +*/ + | + name=BuiltInCallName() + "(" + ( + + )? + ( + "*" + | + ( + 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 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= { - 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= { + 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= { - return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); } + t= { + return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } + | + t= { + return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } + | + t= { + 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= { - return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); } + t= { + return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } + | + t= { + return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } + | + t= { + 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= { - return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } - | t= { - return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); } + t= { + return LiteralFactory.getInstance().createTypedLiteral(Long.valueOf(t.image)); } + | + t= { + return LiteralFactory.getInstance().createTypedLiteral(Float.valueOf(t.image)); } + | + t= { + return LiteralFactory.getInstance().createTypedLiteral(Double.valueOf(t.image)); } } -/* [65] BooleanLiteral ::= 'true' | 'false' */ +/* [134] BooleanLiteral ::= 'true' | 'false' */ private TypedLiteral BooleanLiteral() : {} { - { - return LiteralFactory.getInstance().createTypedLiteral(true); } - | { - return LiteralFactory.getInstance().createTypedLiteral(false); } + { + return LiteralFactory.getInstance().createTypedLiteral(true); } + | + { + 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= { - return unquote(t.image) ; } - | t= { - return unquote(t.image) ; } - | t= { - return unTripleQuote(t.image) ; } - | t= { - return unTripleQuote(t.image) ; } -} - -/* [67] IRIref ::= IRI_REF | PrefixedName */ -private UriRef IRIref() : { - UriRef uriRef; - Token t; } { - - t= { - return createUriRef(unquote(t.image)); } - | - uriRef=PrefixedName() { - return uriRef; } + Token t; } { + + t= { + return unquote(t.image) ; } + | + t= { + return unquote(t.image) ; } + | + t= { + return unTripleQuote(t.image) ; } + | + t= { + return unTripleQuote(t.image) ; } +} + +/* [136] iri ::= IRIREF | PrefixedName */ +private UriRef Iri() : { + UriRef uriRef; + Token t; } { + + t= { + 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= | t= ) { - return createUriRef(t.image); } + ( t= | t= ) { + return createUriRef(t.image); } } -/* [69] BlankNode ::= BLANK_NODE_LABEL | ANON */ +/* [138] BlankNode ::= BLANK_NODE_LABEL | ANON */ private ResourceOrVariable BlankNode() : { - Token t; } { + Token t; } { - t= { - return getBNode(t.image); } - | { - return getNewBNode(); } + t= { + return getBNode(t.image); } + | + { + 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 : ()? ":" > | - /* [72] PNAME_LN ::= PNAME_NS PN_LOCAL */ + /* [141] PNAME_LN ::= PNAME_NS PN_LOCAL */ < PNAME_LN : > | - /* [73] BLANK_NODE_LABEL ::= '_:' PN_LOCAL */ - < BLANK_NODE_LABEL : "_:" > + /* [142] BLANK_NODE_LABEL ::= '_:' ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)? */ + < BLANK_NODE_LABEL : "_:" ( | ["0"-"9"] ) ( ( | "." )* )? > | - /* [74] VAR1 ::= '?' VARNAME */ + /* [143] VAR1 ::= '?' VARNAME */ < VAR1 : "?" > | - /* [75] VAR2 ::= '$' VARNAME */ + /* [144] VAR2 ::= '$' VARNAME */ < VAR2 : "$" > | - /* [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_9o : ()* > + < #Z_9o : ()* > | - /* [77] INTEGER ::= [0-9]+ */ + /* [146] INTEGER ::= [0-9]+ */ < INTEGER : > | - /* [78] DECIMAL ::= [0-9]+ '.' [0-9]* | '.' [0-9]+ */ - < DECIMAL : ( "." ) | ( "." ) > + /* [147] DECIMAL ::= [0-9]* '.' [0-9]+ */ + < DECIMAL : "." > | - /* [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 : ( "." ) | ( "." ) | ( ) > | - /* [80] INTEGER_POSITIVE ::= '+' INTEGER */ + /* [149] INTEGER_POSITIVE ::= '+' INTEGER */ < INTEGER_POSITIVE : "+" > | - /* [81] DECIMAL_POSITIVE ::= '+' DECIMAL */ + /* [150] DECIMAL_POSITIVE ::= '+' DECIMAL */ < DECIMAL_POSITIVE : "+" > | - /* [82] DOUBLE_POSITIVE ::= '+' DOUBLE */ + /* [151] DOUBLE_POSITIVE ::= '+' DOUBLE */ < DOUBLE_POSITIVE : "+" > | - /* [83] INTEGER_NEGATIVE ::= '-' INTEGER */ + /* [152] INTEGER_NEGATIVE ::= '-' INTEGER */ < INTEGER_NEGATIVE : "-" > | - /* [84] DECIMAL_NEGATIVE ::= '-' DECIMAL */ + /* [153] DECIMAL_NEGATIVE ::= '-' DECIMAL */ < DECIMAL_NEGATIVE : "-" > | - /* [85] DOUBLE_NEGATIVE ::= '-' DOUBLE */ + /* [154] DOUBLE_NEGATIVE ::= '-' DOUBLE */ < DOUBLE_NEGATIVE : "-" > | - /* [86] EXPONENT ::= [eE] [+-]? [0-9]+ */ + /* [155] EXPONENT ::= [eE] [+-]? [0-9]+ */ < #EXPONENT : ["e","E"] (["+","-"])? > } TOKEN : { - /* [87] STRING_LITERAL1 ::= "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'" */ + /* [156] STRING_LITERAL1 ::= "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'" */ < STRING_LITERAL1 : "'" ( ~["'", "\\", "\r", "\n"] | )* "'" > | - /* [88] STRING_LITERAL2 ::= '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"' */ + /* [157] STRING_LITERAL2 ::= '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"' */ < STRING_LITERAL2 : "\"" ( ~["\"", "\\", "\r", "\n"] | )* "\"" > | - /* [89] STRING_LITERAL_LONG1 ::= "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''" */ + /* [158] STRING_LITERAL_LONG1 ::= "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''" */ < STRING_LITERAL_LONG1 : "'''" ( ( "'" | "''" )? ( ~["'","\\"] | ) )* "'''" > | - /* [90] STRING_LITERAL_LONG2 ::= '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""' */ + /* [159] STRING_LITERAL_LONG2 ::= '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""' */ < STRING_LITERAL_LONG2 : "\"\"\"" ( ( "\"" | "\"\"" )? ( ~["\"","\\"] | ) )* "\"\"\"" > | - /* [91] #ECHAR ::= '\' [tbnrf\"'] */ + /* [160] #ECHAR ::= '\' [tbnrf\"'] */ < #ECHAR : "\\" ["t","b","n","r","f","\\","\"","'"] > } TOKEN : { - /* [92] NIL ::= '(' WS* ')' */ + /* [161] NIL ::= '(' WS* ')' */ < NIL : "(" ()* ")" > | - /* [93] WS ::= #x20 | #x9 | #xD | #xA */ + /* [162] WS ::= #x20 | #x9 | #xD | #xA */ < #WS : " " | "\t" | "\n" | "\r" > | - /* [94] ANON ::= '[' WS* ']' */ + /* [163] ANON ::= '[' WS* ']' */ < ANON : "[" ()* "]" > } 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 : | "_" > | - /* [97] #VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )* */ - < #VARNAME : ( | ) ( | | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"] )* > + /* [166] #VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )* */ + < #VARNAME : ( | ) ( | | "\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 : | "-" | | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"] > | - /* [99] PN_PREFIX ::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)? */ - < PN_PREFIX : (( | "." )* )? > + /* [168] PN_PREFIX ::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)? */ + < PN_PREFIX : (( | "." )* )? > | - /* [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_LOCAL : ( | ":" | | ) (( | "." | ":" | )* ( | ":" | ) )? > + | + /* [170] PLX ::= PERCENT | PN_LOCAL_ESC */ + < PLX : | > + | + /* [171] PERCENT ::= '%' HEX HEX */ + < PERCENT : "%" > + | + /* [172] HEX ::= [0-9] | [A-F] | [a-f] */ + < #HEX : | ["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 : \n" + + "SELECT ?x \n" + + "{\n" + + ":order :item/:price ?x\n" + + "}\n"); + + UriRef defaultGraph = new UriRef("http://example.org/default"); + SparqlPreParser parser = new SparqlPreParser(); + Set 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 : \n" + + "SELECT ?x (foo(2*3, ?x < ?y) AS ?f) (GROUP_CONCAT(?x ; separator=\"|\") AS ?gc) (sum(distinct *) AS ?total)\n" + + "FROM \n" + + "{\n" + + ":order :item/:price ?x\n" + + "}\n"); + + UriRef defaultGraph = new UriRef("http://example.org/default"); + SparqlPreParser parser = new SparqlPreParser(); + Set referredGraphs = parser.getReferredGraphs(queryStrBuilder.toString(), defaultGraph); + Assert.assertTrue(referredGraphs.toArray()[0].equals(new UriRef("http://example.org/test"))); + } +}