You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2014/11/10 11:51:17 UTC
[18/50] [abbrv] jena git commit: Avoid C-related material getting
into cpp/javacc output.
Avoid C-related material getting into cpp/javacc output.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/5b8a7b85
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/5b8a7b85
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/5b8a7b85
Branch: refs/heads/hadoop-rdf
Commit: 5b8a7b85b612edfb9d14b19cbb4284ff692477d1
Parents: 47c7f4b
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Nov 1 19:02:17 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Nov 1 19:02:17 2014 +0000
----------------------------------------------------------------------
jena-arq/Grammar/arq.jj | 275 ++-----------------------------------
jena-arq/Grammar/grammar | 6 +-
jena-arq/Grammar/master.jj | 34 +++--
jena-arq/Grammar/sparql_11.jj | 247 ++-------------------------------
4 files changed, 41 insertions(+), 521 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/5b8a7b85/jena-arq/Grammar/arq.jj
----------------------------------------------------------------------
diff --git a/jena-arq/Grammar/arq.jj b/jena-arq/Grammar/arq.jj
index 10c6419..a7cedc1 100644
--- a/jena-arq/Grammar/arq.jj
+++ b/jena-arq/Grammar/arq.jj
@@ -1,85 +1,10 @@
-/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-/* This header is separate from features.h so that the compiler can
- include it implicitly at the start of every compilation. It must
- not itself include <features.h> or any other header that includes
- <features.h> because the implicit include comes before any feature
- test macros that may be defined in a source file before it first
- explicitly includes a system header. GCC knows the name of this
- header in order to preinclude it. */
-/* glibc's intent is to support the IEC 559 math functionality, real
- and complex. If the GCC (4.9 and later) predefined macros
- specifying compiler intent are available, use them to determine
- whether the overall intent is to support these features; otherwise,
- presume an older compiler has intent to support these features and
- define these macros by default. */
-/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /
- Unicode 6.0. */
-/* We do not support C11 <threads.h>. */
-/**
- * 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.
- */
-// ARQ/SPARQL 1.1 Grammar - native syntax for the query engine
options
{
- // \ u processed in the input stream
- // SPARQL 1.0
JAVA_UNICODE_ESCAPE = true ;
UNICODE_INPUT = false ;
-// // \ u processed after parsing.
-// // strings, prefix names, IRIs
-// JAVA_UNICODE_ESCAPE = false ;
-// UNICODE_INPUT = true ;
STATIC = false ;
-// DEBUG_PARSER = true ;
-// DEBUG_TOKEN_MANAGER = true ;
}
PARSER_BEGIN(ARQParser)
-/**
- * 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 com.hp.hpl.jena.sparql.lang.arq ;
import com.hp.hpl.jena.graph.* ;
import com.hp.hpl.jena.query.* ;
@@ -95,13 +20,6 @@ public class ARQParser extends ARQParserBase
boolean allowAggregatesInExpressions = false ;
}
PARSER_END(ARQParser)
-// // Common top for single entry point.
-// void Top(): {}
-// {
-// ( Query() | Update() )
-// <EOF>
-// }
-// Query only entry point
void QueryUnit(): { }
{
ByteOrderMark()
@@ -113,9 +31,6 @@ void Query() : { }
{
Prologue()
( SelectQuery() | ConstructQuery() | DescribeQuery() | AskQuery()
-// #ifdef ARQ
-// | JsonTemplateQuery()
-// #endif
)
ValuesClause()
}
@@ -146,7 +61,6 @@ void PrefixDecl() : { Token t ; String iri ; }
{ String s = fixupPrefix(t.image, t.beginLine, t.beginColumn) ;
getPrologue().setPrefix(s, iri) ; }
}
-// ---- Query type clauses
void SelectQuery() : { }
{
SelectClause()
@@ -173,7 +87,6 @@ void SelectClause() : { Var v ; Expr expr ; Node n ; }
(
v = Var() { getQuery().addResultVar(v) ; }
|
- // Expressions without ()
( LOOKAHEAD(2)
expr = BuiltInCall() { getQuery().addResultVar((Var)null, expr) ; }
| expr = FunctionCall() { getQuery().addResultVar((Var)null, expr) ; }
@@ -181,12 +94,7 @@ void SelectClause() : { Var v ; Expr expr ; Node n ; }
| n = NumericLiteral() { getQuery().addResultVar((Var)null, NodeValue.makeNode(n)) ; }
| n = BooleanLiteral() { getQuery().addResultVar((Var)null, NodeValue.makeNode(n)) ; }
)
- // @@ PROBLEMS: expr = FunctionCall()
- // <uri>(?x)
- // looks like a function call and also a "<uri> ( ?v )"
- //| expr = FunctionCall() { getQuery().addResultVar((Var)null, expr) ; }
|
- // Expressions with ()
(
{ v = null ; }
<LPAREN>
@@ -205,29 +113,17 @@ void SelectClause() : { Var v ; Expr expr ; Node n ; }
void ConstructQuery() : { Template t ;
TripleCollectorBGP acc = new TripleCollectorBGP() ; }
{
-// #ifndef ARQ
-// <CONSTRUCT>
-// { getQuery().setQueryConstructType() ; }
-// t = ConstructTemplate()
-// { getQuery().setConstructTemplate(t) ; }
-// ( DatasetClause() )*
-// WhereClause()
-// SolutionModifier()
-// #else
<CONSTRUCT>
{ getQuery().setQueryConstructType() ; }
(
- // Full form.
t = ConstructTemplate()
{ getQuery().setConstructTemplate(t) ; }
( DatasetClause() )*
WhereClause()
SolutionModifier()
|
- // Abbreviated CONSTRUCT WHERE {}
( DatasetClause() )*
<WHERE>
- // Should have been "ConstructTemplate()"
<LBRACE>
(TriplesTemplate(acc))?
<RBRACE>
@@ -235,14 +131,12 @@ void ConstructQuery() : { Template t ;
{
t = new Template(acc.getBGP()) ;
getQuery().setConstructTemplate(t) ;
- // Create a query in the same shape as the query created by writing out in full.
ElementPathBlock epb = new ElementPathBlock(acc.getBGP()) ;
ElementGroup elg = new ElementGroup() ;
elg.addElement(epb) ;
getQuery().setQueryPattern(elg) ;
}
)
-//#endif
}
void DescribeQuery() : { Node n ; }
{
@@ -266,7 +160,6 @@ void AskQuery() : {}
WhereClause()
SolutionModifier()
}
-// ----
void DatasetClause() : {}
{
<FROM>
@@ -276,7 +169,6 @@ void DefaultGraphClause() : { String iri ; }
{
iri = SourceSelector()
{
- // This checks for duplicates
getQuery().addGraphURI(iri) ;
}
}
@@ -285,7 +177,6 @@ void NamedGraphClause() : { String iri ; }
<NAMED>
iri = SourceSelector()
{
- // This checks for duplicates
getQuery().addNamedGraphURI(iri) ;
}
}
@@ -347,14 +238,14 @@ void OrderCondition() :
{
{ direction = Query.ORDER_DEFAULT ; }
(
- ( // These are for clarity in the HTML
+ (
( <ASC> { direction = Query.ORDER_ASCENDING ; }
| <DESC> { direction = Query.ORDER_DESCENDING ; } )
expr = BrackettedExpression()
)
|
( expr = Constraint()
- | v = Var() //{ expr = asExpr(v) ; }
+ | v = Var()
)
)
{ if ( v == null )
@@ -364,9 +255,6 @@ void OrderCondition() :
}
void LimitOffsetClauses() : { }
{
- // SPARQL does not care about the order here.
- // SQL (where implemented) does (it's LIMIT then OFFSET generally)
- // But that is counter intuitive as it's applied the other way round
(
LimitClause() (OffsetClause())?
|
@@ -392,16 +280,12 @@ void ValuesClause() : { Token t ; }
{ finishValuesClause(t.beginLine, t.beginColumn) ; }
)?
}
-// SPARQL Update + transitional extensions for SPARQL/Update (the W3C submission)
-// Update only entry point
void Update() : { }
{
- // Rewrite for no recursion - grammar is not LL(1)
Prologue()
(
Update1()
(
- // This syntactic lookahead is necessitated by the optional trailing semicolon and prologue
LOOKAHEAD( <SEMICOLON> Prologue() ( <LOAD> | <CLEAR> | <DROP> | <ADD> |
<MOVE> | <COPY> | <CREATE> | <WITH> | <DELETE> | <INSERT> |
<USING> | <INSERT_DATA> | <DELETE_DATA> | <DELETE_WHERE> ) )
@@ -437,7 +321,6 @@ void Update1() : { Update up = null ; }
}
Update Load() : { String url ; Node dest = null ; boolean silent = false ; }
{
- // <LOAD> ( iri() )+
<LOAD> (<SILENT> { silent = true ; })? url = iri()
(<INTO> dest = GraphRef() )?
{ return new UpdateLoad(url, dest, silent) ; }
@@ -472,13 +355,6 @@ Update Copy() : { Target src ; Target dest ; boolean silent = false ; }
<COPY> (<SILENT> { silent=true ; } )? src = GraphOrDefault() <TO> dest = GraphOrDefault()
{ return new UpdateCopy(src, dest, silent) ; }
}
-// #ifdef ARQ
-// void Meta() : { QuadDataAccSink qd = new QuadDataAccSink() ; }
-// {
-// <META>
-// QuadData(qd)
-// }
-// #endif
void InsertData() : { QuadDataAccSink qd = createInsertDataSink() ; Token t ; }
{
t = <INSERT_DATA>
@@ -519,7 +395,6 @@ Update Modify() : { Element el ; String iri = null ;
| InsertClause(up)
)
(UsingClause(up))*
- // WHERE is mandatory here.
<WHERE>
{ startWherePattern() ; }
el = GroupGraphPattern() { up.setElement(el) ; }
@@ -582,7 +457,6 @@ void QuadPattern(QuadAcc acc) : { }
Quads(acc)
<RBRACE>
}
-//Ground data : As QuadPattern but don't allow variables.
void QuadData(QuadDataAccSink acc) : { }
{
<LBRACE>
@@ -608,13 +482,11 @@ void QuadsNotTriples(QuadAccSink acc) : {Node gn ; Node prev = acc.getGraph() ;
{ setAccGraph(acc, prev) ; }
}
void TriplesTemplate(TripleCollector acc) : { }
-{ // same as ConstructTriples
- // Rewrite for no recursion - grammar is not LL(1)
+{
TriplesSameSubject(acc)
(LOOKAHEAD(2) (<DOT>) TriplesSameSubject(acc))*
(<DOT>)?
}
-// ---- General Graph Pattern
Element GroupGraphPattern() : { Element el = null ; Token t ; }
{
t = <LBRACE>
@@ -635,9 +507,6 @@ Element GroupGraphPatternSub() : { Element el = null ; }
{
{ ElementGroup elg = new ElementGroup() ; }
{ startGroup(elg) ; }
- // Ensure two BGP's can't be next to each other
- // Done by seeing if there is a non-BGP and recursing
- // if there is an intermediate
(
{ startTriplesBlock() ; }
el = TriplesBlock(null)
@@ -667,14 +536,9 @@ Element TriplesBlock(ElementPathBlock acc) : { }
( <DOT> (TriplesBlock(acc))? )?
{ return acc ; }
}
-// -----
Element GraphPatternNotTriples() : { Element el = null ; }
{
(
-// el = GroupGraphPattern()
-// |
-// el = UnionGraphPattern()
-// |
el = GroupOrUnionGraphPattern()
|
el = OptionalGraphPattern()
@@ -699,7 +563,6 @@ Element GraphPatternNotTriples() : { Element el = null ; }
)
{ return el ; }
}
-// ---- Definitions of each pattern element
Element OptionalGraphPattern() : { Element el ; }
{ <OPTIONAL> el = GroupGraphPattern()
{ return new ElementOptional(el) ; }
@@ -821,16 +684,6 @@ Element MinusGraphPattern() : { Element el ; }
el = GroupGraphPattern()
{ return new ElementMinus(el) ; }
}
-// Element UnionGraphPattern() : { Element el ; }
-// {
-// <UNION>
-// el = GroupGraphPattern()
-// { return new ElementUnion(el) ; }
-// }
-// SPARQL 1.0: {pattern} UNION {pattern} UNION {pattern} ... ::
-// SPARQL 1.1 may introduce: { pattern UNION pattern UNION ... }
-// G (union G)* can be a single group pattern
-// or a group pattern as part of an union.
Element GroupOrUnionGraphPattern() :
{ Element el = null ; ElementUnion el2 = null ; }
{
@@ -899,7 +752,6 @@ ExprList ExpressionList() : { Expr expr = null ; ExprList args = new ExprList()
)
{ return args ; }
}
-// -------- Construct patterns
Template ConstructTemplate() : { TripleCollectorBGP acc = new TripleCollectorBGP();
Template t = new Template(acc.getBGP()) ; }
{
@@ -911,20 +763,16 @@ Template ConstructTemplate() : { TripleCollectorBGP acc = new TripleCollectorBGP
return t ; }
}
void ConstructTriples(TripleCollector acc) : { }
-{ // Same as TriplesTemplate, but retain for 1.0 legacy
- // Rewrite for no recursion - grammar is not LL(1)
+{
TriplesSameSubject(acc)
(LOOKAHEAD(2) (<DOT>) TriplesSameSubject(acc))*
(<DOT>)?
}
-// -------- Triple lists with property and object lists
-// -------- Without paths: entry: TriplesSameSubject
void TriplesSameSubject(TripleCollector acc) : { Node s ; }
{
s = VarOrTerm()
PropertyListNotEmpty(s, acc)
|
- // Any of the triple generating syntax elements
{ ElementPathBlock tempAcc = new ElementPathBlock() ; }
s = TriplesNode(tempAcc)
PropertyList(s, tempAcc)
@@ -948,8 +796,6 @@ void PropertyListNotEmpty(Node s, TripleCollector acc) :
}
Node Verb() : { Node p ;}
{
-// Blank nodes as predicates
-// ( p = VarOrBlankNodeOriri() | <KW_A> { p = nRDFtype ; } )
( p = VarOrIri() | <KW_A> { p = nRDFtype ; } )
{ return p ; }
}
@@ -964,14 +810,11 @@ void Object(Node s, Node p, Path path, TripleCollector acc): { Node o ; }
o = GraphNode(tempAcc)
{ insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
}
-// -------- BGPs with paths.
-// -------- Entry point: TriplesSameSubjectPath
void TriplesSameSubjectPath(TripleCollector acc) : { Node s ; }
{
s = VarOrTerm()
PropertyListPathNotEmpty(s, acc)
|
- // Any of the triple generating syntax elements
{ ElementPathBlock tempAcc = new ElementPathBlock() ; }
s = TriplesNodePath(tempAcc)
PropertyListPath(s, tempAcc)
@@ -1004,8 +847,6 @@ Path VerbPath() : {Node p ; Path path ; }
}
Node VerbSimple() : { Node p ; }
{
- // "a" now allowed in paths.
- //( p = Var() | <KW_A> { p = nRDFtype ; } )
p = Var()
{ return p ; }
}
@@ -1020,8 +861,6 @@ void ObjectPath(Node s, Node p, Path path, TripleCollector acc): { Node o ; }
o = GraphNodePath(tempAcc)
{ insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
}
-// End paths stuff.
-// -------- Paths
Path PathUnit() : { Path p ; }
{
ByteOrderMark()
@@ -1029,7 +868,6 @@ Path PathUnit() : { Path p ; }
<EOF>
{ return p ; }
}
-// Weakest outermost
Path Path() : { Path p ; }
{
p = PathAlternative() { return p ; }
@@ -1048,20 +886,17 @@ Path PathSequence() : { Path p1 , p2 ; }
p1 = PathEltOrInverse()
( <SLASH> p2 = PathEltOrInverse()
{ p1 = PathFactory.pathSeq(p1, p2) ; }
- // :p^:q -- Not in SPARQL 1.1
| <CARAT> p2 = PathElt()
{ p1 = PathFactory.pathSeq(p1, new P_Inverse(p2)) ; }
)*
{ return p1; }
}
-// Path unit element, no inverse
Path PathElt() : { String str ; Node n ; Path p ; }
{
p = PathPrimary()
( p = PathMod(p) )?
{ return p ; }
}
-// Path unit element, including inverse.
Path PathEltOrInverse() : { String str ; Node n ; Path p ; }
{
( p = PathElt()
@@ -1077,25 +912,23 @@ Path PathMod(Path p) : { long i1 ; long i2 ; }
| <STAR> { return PathFactory.pathZeroOrMore1(p) ; }
| <PLUS> { return PathFactory.pathOneOrMore1(p) ; }
| <LBRACE>
- //{*}
( <STAR> <RBRACE> { return PathFactory.pathZeroOrMoreN(p) ; }
- // {+}
| <PLUS> <RBRACE> { return PathFactory.pathOneOrMoreN(p) ; }
- | // {N} {N,M} {N,}
+ |
i1 = Integer()
( <COMMA>
- ( // case {N,}
+ (
<RBRACE>
{ return PathFactory.pathMod(p, i1, PathFactory.UNSET) ; }
- | // case {N,M}
- i2 = Integer() <RBRACE> // case {N,M}
+ |
+ i2 = Integer() <RBRACE>
{ return PathFactory.pathMod(p, i1, i2) ; }
)
|
- <RBRACE> // {N}
+ <RBRACE>
{ return PathFactory.pathFixedLength(p, i1) ; }
)
- | // {,N}
+ |
<COMMA>
i2 = Integer()
<RBRACE>
@@ -1147,7 +980,6 @@ P_Path0 PathOneInPropertySet() : { String str ; Node n ; }
{
( str = iri() { n = createNode(str) ; return new P_Link(n) ; }
| <KW_A> { return new P_Link(nRDFtype) ; }
- // This is the !(^:property) form.
| <CARAT>
( str = iri() { n = createNode(str) ; return new P_ReverseLink(n) ; }
| <KW_A> { return new P_ReverseLink(nRDFtype) ; }
@@ -1159,9 +991,6 @@ long Integer() : {Token t ;}
t = <INTEGER>
{ return integerValue(t.image) ; }
}
-// -------- Triple expansions
-// Anything that can stand in a node slot and which is
-// a number of triples
Node TriplesNode(TripleCollectorMark acc) : { Node n ; }
{
n = Collection(acc) { return n ; }
@@ -1190,7 +1019,6 @@ Node BlankNodePropertyListPath(TripleCollector acc) : { Token t ; }
<RBRACKET>
{ return n ; }
}
-// ------- RDF collections
Node Collection(TripleCollectorMark acc) :
{ Node listHead = nRDFnil ; Node lastCell = null ; int mark ; Node n ; Token t ; }
{
@@ -1210,7 +1038,6 @@ Node Collection(TripleCollectorMark acc) :
lastCell = cell ;
}
) +
- // Not * here - "()" is handled separately.
<RPAREN>
{ if ( lastCell != null )
insert(acc, lastCell, nRDFrest, nRDFnil) ;
@@ -1235,13 +1062,11 @@ Node CollectionPath(TripleCollectorMark acc) :
lastCell = cell ;
}
) +
- // Not * here - "()" is handled separately.
<RPAREN>
{ if ( lastCell != null )
insert(acc, lastCell, nRDFrest, nRDFnil) ;
return listHead ; }
}
-// -------- Nodes in a graph pattern or template
Node GraphNode(TripleCollectorMark acc) : { Node n ; }
{
n = VarOrTerm() { return n ; }
@@ -1259,7 +1084,6 @@ Node VarOrTerm() : {Node n = null ; }
( n = Var() | n = GraphTerm() )
{ return n ; }
}
-// Property (if no bNodes) + DESCRIBE
Node VarOrIri() : {Node n = null ; String iri ; }
{
( n = Var() | iri = iri() { n = createNode(iri) ; } )
@@ -1277,10 +1101,8 @@ Node GraphTerm() : { Node n ; String iri ; }
| n = NumericLiteral() { return n ; }
| n = BooleanLiteral() { return n ; }
| n = BlankNode() { return n ; }
- // <LPAREN> <RPAREN> { return nRDFnil ; }
| <NIL> { return nRDFnil ; }
}
-// -------- Constraint syntax
Expr Expression() : { Expr expr ; }
{
expr = ConditionalOrExpression()
@@ -1378,8 +1200,6 @@ Expr MultiplicativeExpression() : { Expr expr1, expr2 ; }
{ expr1 = new E_Multiply(expr1, expr2) ; }
| <SLASH> expr2 = UnaryExpression()
{ expr1 = new E_Divide(expr1, expr2) ; }
-// | <REM> expr2 = UnaryExpression()
-// { expr1 = new E_Modulus(expr1, expr2) ; }
)*
{ return expr1 ; }
}
@@ -1396,16 +1216,10 @@ Expr PrimaryExpression() : { Expr expr ; Node gn ; }
( expr = BrackettedExpression() { return expr ; }
| expr = BuiltInCall() { return expr ; }
| expr = iriOrFunction() { return expr ; }
-// NOT | gn = VarOrTerm() { return asExpr(gn) ; }
-// Because of iriOrFunction
| gn = RDFLiteral() { return asExpr(gn) ; }
| gn = NumericLiteral() { return asExpr(gn) ; }
| gn = BooleanLiteral() { return asExpr(gn) ; }
| gn = Var() { return asExpr(gn) ; }
-// and not SPARQL 11
-// needs checking.
-// Use this for ?var(args)
-// | expr = VarOrFunction() { return expr ; }
)
}
Expr BrackettedExpression() : { Expr expr ; }
@@ -1479,11 +1293,7 @@ Expr BuiltInCall() : { Expr expr ; Expr expr1 = null ; Expr expr2 = null ;
| <VERSION> <NIL> { return new E_Version(); }
| <COALESCE> a = ExpressionList()
{ return new E_Coalesce(a) ; }
- // Maybe also allow ?func(?a1,?a2,...)
-// | <CALL> a = ExpressionList()
-// { return new E_Call(a) ; }
| <CALL>
- // at least one argument (the function to call).
{ a = new ExprList() ; }
<LPAREN>
expr = Expression() { a.add(expr) ; }
@@ -1510,7 +1320,7 @@ Expr BuiltInCall() : { Expr expr ; Expr expr1 = null ; Expr expr2 = null ;
{ return new E_IsLiteral(expr) ; }
| <IS_NUMERIC> <LPAREN> expr = Expression() <RPAREN>
{ return new E_IsNumeric(expr) ; }
- | // Regular expression matcher
+ |
expr = RegexExpression() { return expr ; }
| expr = ExistsFunc() { return expr ; }
| expr = NotExistsFunc() { return expr ; }
@@ -1570,8 +1380,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
ExprList ordered = new ExprList() ;
Token t ; }
{
- // Count is special because of COUNT(*)
- // GROUP_CONCAT is special because of separator=
( t = <COUNT> <LPAREN>
( <DISTINCT> { distinct = true ; } )?
( <STAR> | expr = Expression() )
@@ -1593,7 +1401,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
<LPAREN>
(t = <DISTINCT> { distinct = true ; })?
expr = Expression() { a.add(expr) ; }
- // JavcaCC 5.0 - rewriting as LL(1) didn't work - code generated was wrong
(LOOKAHEAD(2)
( <SEMICOLON> <SEPARATOR> <EQ> sep=String()
(<SEMICOLON> <ORDER><BY> expr2 = Expression() { ordered.add(expr2) ; })?
@@ -1612,9 +1419,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
{ Expr exprAgg = getQuery().allocAggregate(agg) ;
return exprAgg ; }
}
-// See also FunctionCall.
-// The case of "q:name()" or "q:agg()" or just "q:name"
-// by expanding out FunctionCall()
Expr iriOrFunction() : { String iri ; ExprList a = null ;
ExprList params = null ;
boolean distinct = false ; }
@@ -1629,7 +1433,6 @@ Expr iriOrFunction() : { String iri ; ExprList a = null ;
Node RDFLiteral() : { Token t ; String lex = null ; }
{
lex = String()
- // Optional lang tag and datatype.
{ String lang = null ; String uri = null ; }
(
( t = <LANGTAG> { lang = stripChars(t.image, 1) ; } )
@@ -1703,7 +1506,6 @@ Node BlankNode() : { Token t = null ; }
t = <BLANK_NODE_LABEL>
{ return createBNode(t.image, t.beginLine, t.beginColumn) ; }
|
-// <LBRACKET> <RBRACKET> { return createBNode(t.beginLine, t.beginColumn) ; }
t = <ANON> { return createBNode(t.beginLine, t.beginColumn) ; }
}
String IRIREF() : { Token t ; }
@@ -1711,24 +1513,18 @@ String IRIREF() : { Token t ; }
t = <IRIref>
{ return resolveQuotedIRI(t.image, t.beginLine, t.beginColumn) ; }
}
-// ------------------------------------------
-// Tokens
-// Comments and whitespace
SKIP : { " " | "\t" | "\n" | "\r" | "\f" }
SPECIAL_TOKEN :
{ <SINGLE_LINE_COMMENT: "#" (~["\n","\r"])* ("\n"|"\r"|"\r\n")? > }
TOKEN: {
<#WS: " " | "\t" | "\n" | "\r" | "\f">
|
- // Whitespace or comment.
<#WSC: <WS> | <SINGLE_LINE_COMMENT> >
|
<BOM: "\uFEFF">
}
-// Main tokens */
TOKEN:
{
- // Includes # for relative URIs
<IRIref: "<" (~[ ">","<", "\"", "{", "}", "^", "\\", "|", "`",
"\u0000"-"\u0020"])* ">" >
| <PNAME_NS: (<PN_PREFIX>)? ":" >
@@ -1740,17 +1536,11 @@ TOKEN:
| <#A2Z: ["a"-"z","A"-"Z"]>
| <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]>
}
-// -------------------------------------------------
-// Keyworks : includes operators that are words and should be
-// before general things like IDENTIFIER which swallow almost
-// anything
TOKEN : { <KW_A: "a" > }
TOKEN [IGNORE_CASE] :
{
-// Prologue
< BASE: "base" >
| < PREFIX: "prefix" >
-// Result forms
| < SELECT: "select" >
| < DISTINCT: "distinct" >
| < REDUCED: "reduced" >
@@ -1765,10 +1555,8 @@ TOKEN [IGNORE_CASE] :
| < UNDEF: "undef" >
| < ASC: "asc" >
| < DESC: "desc" >
-// Dataset
| < NAMED: "named" >
| < FROM: "from" >
-// Graph pattern operators
| < WHERE: "where" >
| < AND: "and" >
| < GRAPH: "graph" >
@@ -1780,7 +1568,6 @@ TOKEN [IGNORE_CASE] :
| < LET: "let" >
| < EXISTS: "exists" >
| < NOT: "not" >
-//| < UNSAID: "unsaid" >
| < AS: "as" >
| < GROUP: "group" >
| < HAVING: "having" >
@@ -1795,7 +1582,6 @@ TOKEN [IGNORE_CASE] :
| < SAMPLE: "sample" >
| < GROUP_CONCAT: "group_concat" >
| < FILTER: "filter" >
-// Expression operators
| < BOUND: "bound" >
| < COALESCE: "coalesce" >
| < IN: "in" >
@@ -1858,7 +1644,6 @@ TOKEN [IGNORE_CASE] :
| < TRUE: "true" >
| < FALSE: "false" >
}
-// SPARQL/Update parts.
TOKEN [IGNORE_CASE] :
{
< DATA: "data" >
@@ -1879,22 +1664,16 @@ TOKEN [IGNORE_CASE] :
| < INTO: "into" >
| < TO: "to" >
| < DFT: "default" >
-//| < NAMED: "named" >
| < ALL: "all" >
| < WITH: "with" >
| < USING: "using" >
-//| < BEGIN: "begin" >
-//| < COMMIT: "commit" >
-//| < ABORT: "abort" >
}
-// -------------------------------------------------
TOKEN :
{
< #DIGITS: (["0"-"9"])+>
| < INTEGER: <DIGITS> >
-//| < DECIMAL: ( <DIGITS> "." (<DIGITS>)* | "." <DIGITS> ) >
| < DECIMAL: (<DIGITS>)? "." <DIGITS> >
-| < DOUBLE: // Required exponent.
+| < DOUBLE:
(
(["0"-"9"])+ "." (["0"-"9"])* <EXPONENT>
| "." (["0"-"9"])+ (<EXPONENT>)
@@ -1912,10 +1691,8 @@ TOKEN :
| < #QUOTE_3S: "'''">
| <ECHAR: "\\" ( "t"|"b"|"n"|"r"|"f"|"\\"|"\""|"'") >
| < STRING_LITERAL1:
- // Single quoted string
"'" ( (~["'","\\","\n","\r"]) | <ECHAR> )* "'" >
| < STRING_LITERAL2:
- // Double quoted string
"\"" ( (~["\"","\\","\n","\r"]) | <ECHAR> )* "\"" >
| < STRING_LITERAL_LONG1:
<QUOTE_3S>
@@ -1930,10 +1707,6 @@ TOKEN :
{
< LPAREN: "(" >
| < RPAREN: ")" >
-// All the stuff for NUL is needed just to make a
-// single list "() ." as a triple pattern illegal.
-// It leads to a lot of extra work.
-// Similarly [].
| <NIL: <LPAREN> (<WSC>)* <RPAREN> >
| < LBRACE: "{" >
| < RBRACE: "}" >
@@ -1947,8 +1720,8 @@ TOKEN :
| < NE: "!=" >
| < GT: ">" >
| < LT: "<" >
-| < LE: "<=" > // Maybe: | "=>" >
-| < GE: ">=" > // Maybe: | "=<" >
+| < LE: "<=" >
+| < GE: ">=" >
| < BANG: "!" >
| < TILDE: "~" >
| < COLON: ":" >
@@ -1958,22 +1731,17 @@ TOKEN :
| < MINUS: "-" >
| < STAR: "*" >
| < SLASH: "/" >
-//| < AMP: "&" >
-//| < REM: "%" >
| < DATATYPE: "^^">
| < AT: "@">
| < ASSIGN: ":=">
-// Path related
| < VBAR: "|" >
| < CARAT: "^" >
| < FPATH: "->" >
| < RPATH: "<-" >
| < QMARK: "?" >
}
-// See XML chars.txt for notes
TOKEN:
{
- // XML 1.1 NCNameStartChar without "_"
<#PN_CHARS_BASE:
["A"-"Z"] | ["a"-"z"] |
["\u00C0"-"\u00D6"] | ["\u00D8"-"\u00F6"] | ["\u00F8"-"\u02FF"] |
@@ -1981,18 +1749,14 @@ TOKEN:
["\u200C"-"\u200D"] | ["\u2070"-"\u218F"] | ["\u2C00"-"\u2FEF"] |
["\u3001"-"\uD7FF"] | ["\uF900"-"\uFFFD"]
>
- // [#x10000-#xEFFFF]
|
- // With underscore
<#PN_CHARS_U: <PN_CHARS_BASE> | "_" >
|
<#PN_CHARS: (<PN_CHARS_U> | "-" | ["0"-"9"] | "\u00B7" |
["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] ) >
|
- // No leading "_", no trailing ".", can have dot inside prefix name.
<#PN_PREFIX: <PN_CHARS_BASE> ((<PN_CHARS>|".")* <PN_CHARS>)? >
|
- // Local part.
<#PN_LOCAL: (<PN_CHARS_U> | ":" | ["0"-"9"] | <PLX> )
( (<PN_CHARS> | "." |":" | <PLX> )*
(<PN_CHARS> | ":" | <PLX>) )? >
@@ -2001,7 +1765,6 @@ TOKEN:
( <PN_CHARS_U> | ["0"-"9"] | "\u00B7" |
["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] )* >
|
- // Align with QueryParseBase unescapePName.
< #PN_LOCAL_ESC: "\\"
( "_" |
"~" | "." | "-" | "!" | "$" | "&" | "'" |
@@ -2014,17 +1777,7 @@ TOKEN:
|
< #PERCENT: "%" <HEX> <HEX> >
}
-// Catch-all tokens. Must be last.
-// Any non-whitespace. Causes a parser exception, rather than a
-// token manager error (which hides the line numbers).
TOKEN:
{
<#UNKNOWN: (~[" ","\t","\n","\r","\f" ])+ >
}
-/*
-# Local Variables:
-# tab-width: 4
-# indent-tabs-mode: nil
-# comment-default-style: "//"
-# End:
-*/
http://git-wip-us.apache.org/repos/asf/jena/blob/5b8a7b85/jena-arq/Grammar/grammar
----------------------------------------------------------------------
diff --git a/jena-arq/Grammar/grammar b/jena-arq/Grammar/grammar
index fbb3b89..c69909b 100755
--- a/jena-arq/Grammar/grammar
+++ b/jena-arq/Grammar/grammar
@@ -120,7 +120,7 @@ do
# SPARQL 1.0 - use a static copy.
# The parser that is exactly the working group grammar.
-## #### cat "$GRAMMAR" | cpp -P -C -DSPARQL -DSPARQL_10 > sparql_10.jj
+## #### cat "$GRAMMAR" | cpp -P -DSPARQL -DSPARQL_10 > sparql_10.jj
## grammar sparql_10.jj sparql_10 SPARQLParser10
## ;;
echo "SPARQL 1.0 - not rebuilt"
@@ -128,12 +128,12 @@ do
sparql11|sparql_11.jj)
# The parser that is exactly the working group grammar.
- cat "$GRAMMAR" | cpp -P -C -DSPARQL -DSPARQL_11 > sparql_11.jj
+ cat "$GRAMMAR" | cpp -P -DSPARQL -DSPARQL_11 > sparql_11.jj
grammar sparql_11.jj sparql_11 SPARQLParser11
;;
arq|arq.jj)
- cat "$GRAMMAR" | cpp -P -C -DARQ > arq.jj
+ cat "$GRAMMAR" | cpp -P -DARQ - > arq.jj
grammar arq.jj arq ARQParser
;;
http://git-wip-us.apache.org/repos/asf/jena/blob/5b8a7b85/jena-arq/Grammar/master.jj
----------------------------------------------------------------------
diff --git a/jena-arq/Grammar/master.jj b/jena-arq/Grammar/master.jj
index 6b958e1..2a21da4 100644
--- a/jena-arq/Grammar/master.jj
+++ b/jena-arq/Grammar/master.jj
@@ -1,20 +1,18 @@
-/**
- * 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.
- */
+// 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.
// ARQ/SPARQL 1.1 Grammar - native syntax for the query engine
#if 0
@@ -712,7 +710,7 @@ void TriplesTemplate(TripleCollector acc) : { }
#endif
}
-#endif // UPDATE
+#endif
// ---- General Graph Pattern
http://git-wip-us.apache.org/repos/asf/jena/blob/5b8a7b85/jena-arq/Grammar/sparql_11.jj
----------------------------------------------------------------------
diff --git a/jena-arq/Grammar/sparql_11.jj b/jena-arq/Grammar/sparql_11.jj
index 2bdd531..4813e00 100644
--- a/jena-arq/Grammar/sparql_11.jj
+++ b/jena-arq/Grammar/sparql_11.jj
@@ -1,85 +1,10 @@
-/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-/* This header is separate from features.h so that the compiler can
- include it implicitly at the start of every compilation. It must
- not itself include <features.h> or any other header that includes
- <features.h> because the implicit include comes before any feature
- test macros that may be defined in a source file before it first
- explicitly includes a system header. GCC knows the name of this
- header in order to preinclude it. */
-/* glibc's intent is to support the IEC 559 math functionality, real
- and complex. If the GCC (4.9 and later) predefined macros
- specifying compiler intent are available, use them to determine
- whether the overall intent is to support these features; otherwise,
- presume an older compiler has intent to support these features and
- define these macros by default. */
-/* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) /
- Unicode 6.0. */
-/* We do not support C11 <threads.h>. */
-/**
- * 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.
- */
-// ARQ/SPARQL 1.1 Grammar - native syntax for the query engine
options
{
- // \ u processed in the input stream
- // SPARQL 1.0
JAVA_UNICODE_ESCAPE = true ;
UNICODE_INPUT = false ;
-// // \ u processed after parsing.
-// // strings, prefix names, IRIs
-// JAVA_UNICODE_ESCAPE = false ;
-// UNICODE_INPUT = true ;
STATIC = false ;
-// DEBUG_PARSER = true ;
-// DEBUG_TOKEN_MANAGER = true ;
}
PARSER_BEGIN(SPARQLParser11)
-/**
- * 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 com.hp.hpl.jena.sparql.lang.sparql_11 ;
import com.hp.hpl.jena.graph.* ;
import com.hp.hpl.jena.query.* ;
@@ -95,13 +20,6 @@ public class SPARQLParser11 extends SPARQLParser11Base
boolean allowAggregatesInExpressions = false ;
}
PARSER_END(SPARQLParser11)
-// // Common top for single entry point.
-// void Top(): {}
-// {
-// ( Query() | Update() )
-// <EOF>
-// }
-// Query only entry point
void QueryUnit(): { }
{
ByteOrderMark()
@@ -113,9 +31,6 @@ void Query() : { }
{
Prologue()
( SelectQuery() | ConstructQuery() | DescribeQuery() | AskQuery()
-// #ifdef ARQ
-// | JsonTemplateQuery()
-// #endif
)
ValuesClause()
}
@@ -146,7 +61,6 @@ void PrefixDecl() : { Token t ; String iri ; }
{ String s = fixupPrefix(t.image, t.beginLine, t.beginColumn) ;
getPrologue().setPrefix(s, iri) ; }
}
-// ---- Query type clauses
void SelectQuery() : { }
{
SelectClause()
@@ -173,7 +87,6 @@ void SelectClause() : { Var v ; Expr expr ; Node n ; }
(
v = Var() { getQuery().addResultVar(v) ; }
|
- // Expressions with ()
(
{ v = null ; }
<LPAREN>
@@ -192,29 +105,17 @@ void SelectClause() : { Var v ; Expr expr ; Node n ; }
void ConstructQuery() : { Template t ;
TripleCollectorBGP acc = new TripleCollectorBGP() ; }
{
-// #ifndef ARQ
-// <CONSTRUCT>
-// { getQuery().setQueryConstructType() ; }
-// t = ConstructTemplate()
-// { getQuery().setConstructTemplate(t) ; }
-// ( DatasetClause() )*
-// WhereClause()
-// SolutionModifier()
-// #else
<CONSTRUCT>
{ getQuery().setQueryConstructType() ; }
(
- // Full form.
t = ConstructTemplate()
{ getQuery().setConstructTemplate(t) ; }
( DatasetClause() )*
WhereClause()
SolutionModifier()
|
- // Abbreviated CONSTRUCT WHERE {}
( DatasetClause() )*
<WHERE>
- // Should have been "ConstructTemplate()"
<LBRACE>
(TriplesTemplate(acc))?
<RBRACE>
@@ -222,14 +123,12 @@ void ConstructQuery() : { Template t ;
{
t = new Template(acc.getBGP()) ;
getQuery().setConstructTemplate(t) ;
- // Create a query in the same shape as the query created by writing out in full.
ElementPathBlock epb = new ElementPathBlock(acc.getBGP()) ;
ElementGroup elg = new ElementGroup() ;
elg.addElement(epb) ;
getQuery().setQueryPattern(elg) ;
}
)
-//#endif
}
void DescribeQuery() : { Node n ; }
{
@@ -253,7 +152,6 @@ void AskQuery() : {}
WhereClause()
SolutionModifier()
}
-// ----
void DatasetClause() : {}
{
<FROM>
@@ -263,7 +161,6 @@ void DefaultGraphClause() : { String iri ; }
{
iri = SourceSelector()
{
- // This checks for duplicates
getQuery().addGraphURI(iri) ;
}
}
@@ -272,7 +169,6 @@ void NamedGraphClause() : { String iri ; }
<NAMED>
iri = SourceSelector()
{
- // This checks for duplicates
getQuery().addNamedGraphURI(iri) ;
}
}
@@ -334,14 +230,14 @@ void OrderCondition() :
{
{ direction = Query.ORDER_DEFAULT ; }
(
- ( // These are for clarity in the HTML
+ (
( <ASC> { direction = Query.ORDER_ASCENDING ; }
| <DESC> { direction = Query.ORDER_DESCENDING ; } )
expr = BrackettedExpression()
)
|
( expr = Constraint()
- | v = Var() //{ expr = asExpr(v) ; }
+ | v = Var()
)
)
{ if ( v == null )
@@ -351,9 +247,6 @@ void OrderCondition() :
}
void LimitOffsetClauses() : { }
{
- // SPARQL does not care about the order here.
- // SQL (where implemented) does (it's LIMIT then OFFSET generally)
- // But that is counter intuitive as it's applied the other way round
(
LimitClause() (OffsetClause())?
|
@@ -379,12 +272,8 @@ void ValuesClause() : { Token t ; }
{ finishValuesClause(t.beginLine, t.beginColumn) ; }
)?
}
-// SPARQL Update + transitional extensions for SPARQL/Update (the W3C submission)
-// Update only entry point
-// Strict SPARQL 1.1 : mandatory separator, optional terminator.
void Update() : { }
{
- // SPARQL - recursion - does not scale for large number of updates in a single request
Prologue()
(Update1() ( <SEMICOLON> Update() )? )?
}
@@ -410,7 +299,6 @@ void Update1() : { Update up = null ; }
}
Update Load() : { String url ; Node dest = null ; boolean silent = false ; }
{
- // <LOAD> ( iri() )+
<LOAD> (<SILENT> { silent = true ; })? url = iri()
(<INTO> dest = GraphRef() )?
{ return new UpdateLoad(url, dest, silent) ; }
@@ -445,13 +333,6 @@ Update Copy() : { Target src ; Target dest ; boolean silent = false ; }
<COPY> (<SILENT> { silent=true ; } )? src = GraphOrDefault() <TO> dest = GraphOrDefault()
{ return new UpdateCopy(src, dest, silent) ; }
}
-// #ifdef ARQ
-// void Meta() : { QuadDataAccSink qd = new QuadDataAccSink() ; }
-// {
-// <META>
-// QuadData(qd)
-// }
-// #endif
void InsertData() : { QuadDataAccSink qd = createInsertDataSink() ; Token t ; }
{
t = <INSERT_DATA>
@@ -492,7 +373,6 @@ Update Modify() : { Element el ; String iri = null ;
| InsertClause(up)
)
(UsingClause(up))*
- // WHERE is mandatory here.
<WHERE>
{ startWherePattern() ; }
el = GroupGraphPattern() { up.setElement(el) ; }
@@ -555,7 +435,6 @@ void QuadPattern(QuadAcc acc) : { }
Quads(acc)
<RBRACE>
}
-//Ground data : As QuadPattern but don't allow variables.
void QuadData(QuadDataAccSink acc) : { }
{
<LBRACE>
@@ -581,12 +460,10 @@ void QuadsNotTriples(QuadAccSink acc) : {Node gn ; Node prev = acc.getGraph() ;
{ setAccGraph(acc, prev) ; }
}
void TriplesTemplate(TripleCollector acc) : { }
-{ // same as ConstructTriples
- // Version for the spec.
+{
TriplesSameSubject(acc)
(<DOT> (TriplesTemplate(acc))?)?
}
-// ---- General Graph Pattern
Element GroupGraphPattern() : { Element el = null ; Token t ; }
{
t = <LBRACE>
@@ -607,9 +484,6 @@ Element GroupGraphPatternSub() : { Element el = null ; }
{
{ ElementGroup elg = new ElementGroup() ; }
{ startGroup(elg) ; }
- // Ensure two BGP's can't be next to each other
- // Done by seeing if there is a non-BGP and recursing
- // if there is an intermediate
(
{ startTriplesBlock() ; }
el = TriplesBlock(null)
@@ -639,14 +513,9 @@ Element TriplesBlock(ElementPathBlock acc) : { }
( <DOT> (TriplesBlock(acc))? )?
{ return acc ; }
}
-// -----
Element GraphPatternNotTriples() : { Element el = null ; }
{
(
-// el = GroupGraphPattern()
-// |
-// el = UnionGraphPattern()
-// |
el = GroupOrUnionGraphPattern()
|
el = OptionalGraphPattern()
@@ -665,7 +534,6 @@ Element GraphPatternNotTriples() : { Element el = null ; }
)
{ return el ; }
}
-// ---- Definitions of each pattern element
Element OptionalGraphPattern() : { Element el ; }
{ <OPTIONAL> el = GroupGraphPattern()
{ return new ElementOptional(el) ; }
@@ -765,16 +633,6 @@ Element MinusGraphPattern() : { Element el ; }
el = GroupGraphPattern()
{ return new ElementMinus(el) ; }
}
-// Element UnionGraphPattern() : { Element el ; }
-// {
-// <UNION>
-// el = GroupGraphPattern()
-// { return new ElementUnion(el) ; }
-// }
-// SPARQL 1.0: {pattern} UNION {pattern} UNION {pattern} ... ::
-// SPARQL 1.1 may introduce: { pattern UNION pattern UNION ... }
-// G (union G)* can be a single group pattern
-// or a group pattern as part of an union.
Element GroupOrUnionGraphPattern() :
{ Element el = null ; ElementUnion el2 = null ; }
{
@@ -843,7 +701,6 @@ ExprList ExpressionList() : { Expr expr = null ; ExprList args = new ExprList()
)
{ return args ; }
}
-// -------- Construct patterns
Template ConstructTemplate() : { TripleCollectorBGP acc = new TripleCollectorBGP();
Template t = new Template(acc.getBGP()) ; }
{
@@ -855,19 +712,15 @@ Template ConstructTemplate() : { TripleCollectorBGP acc = new TripleCollectorBGP
return t ; }
}
void ConstructTriples(TripleCollector acc) : { }
-{ // Same as TriplesTemplate, but retain for 1.0 legacy
-// SPARQL - recursion - does not scale for SPARQL/Update
+{
TriplesSameSubject(acc)
(<DOT> (ConstructTriples(acc))? )?
}
-// -------- Triple lists with property and object lists
-// -------- Without paths: entry: TriplesSameSubject
void TriplesSameSubject(TripleCollector acc) : { Node s ; }
{
s = VarOrTerm()
PropertyListNotEmpty(s, acc)
|
- // Any of the triple generating syntax elements
{ ElementPathBlock tempAcc = new ElementPathBlock() ; }
s = TriplesNode(tempAcc)
PropertyList(s, tempAcc)
@@ -891,8 +744,6 @@ void PropertyListNotEmpty(Node s, TripleCollector acc) :
}
Node Verb() : { Node p ;}
{
-// Blank nodes as predicates
-// ( p = VarOrBlankNodeOriri() | <KW_A> { p = nRDFtype ; } )
( p = VarOrIri() | <KW_A> { p = nRDFtype ; } )
{ return p ; }
}
@@ -907,14 +758,11 @@ void Object(Node s, Node p, Path path, TripleCollector acc): { Node o ; }
o = GraphNode(tempAcc)
{ insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
}
-// -------- BGPs with paths.
-// -------- Entry point: TriplesSameSubjectPath
void TriplesSameSubjectPath(TripleCollector acc) : { Node s ; }
{
s = VarOrTerm()
PropertyListPathNotEmpty(s, acc)
|
- // Any of the triple generating syntax elements
{ ElementPathBlock tempAcc = new ElementPathBlock() ; }
s = TriplesNodePath(tempAcc)
PropertyListPath(s, tempAcc)
@@ -947,8 +795,6 @@ Path VerbPath() : {Node p ; Path path ; }
}
Node VerbSimple() : { Node p ; }
{
- // "a" now allowed in paths.
- //( p = Var() | <KW_A> { p = nRDFtype ; } )
p = Var()
{ return p ; }
}
@@ -963,9 +809,6 @@ void ObjectPath(Node s, Node p, Path path, TripleCollector acc): { Node o ; }
o = GraphNodePath(tempAcc)
{ insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
}
-// End paths stuff.
-// -------- Paths
-// Weakest outermost
Path Path() : { Path p ; }
{
p = PathAlternative() { return p ; }
@@ -987,14 +830,12 @@ Path PathSequence() : { Path p1 , p2 ; }
)*
{ return p1; }
}
-// Path unit element, no inverse
Path PathElt() : { String str ; Node n ; Path p ; }
{
p = PathPrimary()
( p = PathMod(p) )?
{ return p ; }
}
-// Path unit element, including inverse.
Path PathEltOrInverse() : { String str ; Node n ; Path p ; }
{
( p = PathElt()
@@ -1040,7 +881,6 @@ P_Path0 PathOneInPropertySet() : { String str ; Node n ; }
{
( str = iri() { n = createNode(str) ; return new P_Link(n) ; }
| <KW_A> { return new P_Link(nRDFtype) ; }
- // This is the !(^:property) form.
| <CARAT>
( str = iri() { n = createNode(str) ; return new P_ReverseLink(n) ; }
| <KW_A> { return new P_ReverseLink(nRDFtype) ; }
@@ -1052,9 +892,6 @@ long Integer() : {Token t ;}
t = <INTEGER>
{ return integerValue(t.image) ; }
}
-// -------- Triple expansions
-// Anything that can stand in a node slot and which is
-// a number of triples
Node TriplesNode(TripleCollectorMark acc) : { Node n ; }
{
n = Collection(acc) { return n ; }
@@ -1083,7 +920,6 @@ Node BlankNodePropertyListPath(TripleCollector acc) : { Token t ; }
<RBRACKET>
{ return n ; }
}
-// ------- RDF collections
Node Collection(TripleCollectorMark acc) :
{ Node listHead = nRDFnil ; Node lastCell = null ; int mark ; Node n ; Token t ; }
{
@@ -1103,7 +939,6 @@ Node Collection(TripleCollectorMark acc) :
lastCell = cell ;
}
) +
- // Not * here - "()" is handled separately.
<RPAREN>
{ if ( lastCell != null )
insert(acc, lastCell, nRDFrest, nRDFnil) ;
@@ -1128,13 +963,11 @@ Node CollectionPath(TripleCollectorMark acc) :
lastCell = cell ;
}
) +
- // Not * here - "()" is handled separately.
<RPAREN>
{ if ( lastCell != null )
insert(acc, lastCell, nRDFrest, nRDFnil) ;
return listHead ; }
}
-// -------- Nodes in a graph pattern or template
Node GraphNode(TripleCollectorMark acc) : { Node n ; }
{
n = VarOrTerm() { return n ; }
@@ -1152,7 +985,6 @@ Node VarOrTerm() : {Node n = null ; }
( n = Var() | n = GraphTerm() )
{ return n ; }
}
-// Property (if no bNodes) + DESCRIBE
Node VarOrIri() : {Node n = null ; String iri ; }
{
( n = Var() | iri = iri() { n = createNode(iri) ; } )
@@ -1170,10 +1002,8 @@ Node GraphTerm() : { Node n ; String iri ; }
| n = NumericLiteral() { return n ; }
| n = BooleanLiteral() { return n ; }
| n = BlankNode() { return n ; }
- // <LPAREN> <RPAREN> { return nRDFnil ; }
| <NIL> { return nRDFnil ; }
}
-// -------- Constraint syntax
Expr Expression() : { Expr expr ; }
{
expr = ConditionalOrExpression()
@@ -1271,8 +1101,6 @@ Expr MultiplicativeExpression() : { Expr expr1, expr2 ; }
{ expr1 = new E_Multiply(expr1, expr2) ; }
| <SLASH> expr2 = UnaryExpression()
{ expr1 = new E_Divide(expr1, expr2) ; }
-// | <REM> expr2 = UnaryExpression()
-// { expr1 = new E_Modulus(expr1, expr2) ; }
)*
{ return expr1 ; }
}
@@ -1289,8 +1117,6 @@ Expr PrimaryExpression() : { Expr expr ; Node gn ; }
( expr = BrackettedExpression() { return expr ; }
| expr = BuiltInCall() { return expr ; }
| expr = iriOrFunction() { return expr ; }
-// NOT | gn = VarOrTerm() { return asExpr(gn) ; }
-// Because of iriOrFunction
| gn = RDFLiteral() { return asExpr(gn) ; }
| gn = NumericLiteral() { return asExpr(gn) ; }
| gn = BooleanLiteral() { return asExpr(gn) ; }
@@ -1387,7 +1213,7 @@ Expr BuiltInCall() : { Expr expr ; Expr expr1 = null ; Expr expr2 = null ;
{ return new E_IsLiteral(expr) ; }
| <IS_NUMERIC> <LPAREN> expr = Expression() <RPAREN>
{ return new E_IsNumeric(expr) ; }
- | // Regular expression matcher
+ |
expr = RegexExpression() { return expr ; }
| expr = ExistsFunc() { return expr ; }
| expr = NotExistsFunc() { return expr ; }
@@ -1447,8 +1273,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
ExprList ordered = new ExprList() ;
Token t ; }
{
- // Count is special because of COUNT(*)
- // GROUP_CONCAT is special because of separator=
( t = <COUNT> <LPAREN>
( <DISTINCT> { distinct = true ; } )?
( <STAR> | expr = Expression() )
@@ -1470,7 +1294,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
<LPAREN>
(t = <DISTINCT> { distinct = true ; })?
expr = Expression() { a.add(expr) ; }
- // Single arg version
(<SEMICOLON> <SEPARATOR> <EQ> sep=String())?
<RPAREN>
{ agg = AggregatorFactory.createGroupConcat(distinct, expr, sep, ordered) ; }
@@ -1483,9 +1306,6 @@ Expr Aggregate() : { Aggregator agg = null ; String sep = null ;
{ Expr exprAgg = getQuery().allocAggregate(agg) ;
return exprAgg ; }
}
-// See also FunctionCall.
-// The case of "q:name()" or "q:agg()" or just "q:name"
-// by expanding out FunctionCall()
Expr iriOrFunction() : { String iri ; ExprList a = null ;
ExprList params = null ;
boolean distinct = false ; }
@@ -1500,7 +1320,6 @@ Expr iriOrFunction() : { String iri ; ExprList a = null ;
Node RDFLiteral() : { Token t ; String lex = null ; }
{
lex = String()
- // Optional lang tag and datatype.
{ String lang = null ; String uri = null ; }
(
( t = <LANGTAG> { lang = stripChars(t.image, 1) ; } )
@@ -1574,7 +1393,6 @@ Node BlankNode() : { Token t = null ; }
t = <BLANK_NODE_LABEL>
{ return createBNode(t.image, t.beginLine, t.beginColumn) ; }
|
-// <LBRACKET> <RBRACKET> { return createBNode(t.beginLine, t.beginColumn) ; }
t = <ANON> { return createBNode(t.beginLine, t.beginColumn) ; }
}
String IRIREF() : { Token t ; }
@@ -1582,24 +1400,18 @@ String IRIREF() : { Token t ; }
t = <IRIref>
{ return resolveQuotedIRI(t.image, t.beginLine, t.beginColumn) ; }
}
-// ------------------------------------------
-// Tokens
-// Comments and whitespace
SKIP : { " " | "\t" | "\n" | "\r" | "\f" }
SPECIAL_TOKEN :
{ <SINGLE_LINE_COMMENT: "#" (~["\n","\r"])* ("\n"|"\r"|"\r\n")? > }
TOKEN: {
<#WS: " " | "\t" | "\n" | "\r" | "\f">
|
- // Whitespace or comment.
<#WSC: <WS> | <SINGLE_LINE_COMMENT> >
|
<BOM: "\uFEFF">
}
-// Main tokens */
TOKEN:
{
- // Includes # for relative URIs
<IRIref: "<" (~[ ">","<", "\"", "{", "}", "^", "\\", "|", "`",
"\u0000"-"\u0020"])* ">" >
| <PNAME_NS: (<PN_PREFIX>)? ":" >
@@ -1611,17 +1423,11 @@ TOKEN:
| <#A2Z: ["a"-"z","A"-"Z"]>
| <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]>
}
-// -------------------------------------------------
-// Keyworks : includes operators that are words and should be
-// before general things like IDENTIFIER which swallow almost
-// anything
TOKEN : { <KW_A: "a" > }
TOKEN [IGNORE_CASE] :
{
-// Prologue
< BASE: "base" >
| < PREFIX: "prefix" >
-// Result forms
| < SELECT: "select" >
| < DISTINCT: "distinct" >
| < REDUCED: "reduced" >
@@ -1636,10 +1442,8 @@ TOKEN [IGNORE_CASE] :
| < UNDEF: "undef" >
| < ASC: "asc" >
| < DESC: "desc" >
-// Dataset
| < NAMED: "named" >
| < FROM: "from" >
-// Graph pattern operators
| < WHERE: "where" >
| < AND: "and" >
| < GRAPH: "graph" >
@@ -1650,7 +1454,6 @@ TOKEN [IGNORE_CASE] :
| < SERVICE: "service" >
| < EXISTS: "exists" >
| < NOT: "not" >
-//| < UNSAID: "unsaid" >
| < AS: "as" >
| < GROUP: "group" >
| < HAVING: "having" >
@@ -1665,7 +1468,6 @@ TOKEN [IGNORE_CASE] :
| < SAMPLE: "sample" >
| < GROUP_CONCAT: "group_concat" >
| < FILTER: "filter" >
-// Expression operators
| < BOUND: "bound" >
| < COALESCE: "coalesce" >
| < IN: "in" >
@@ -1723,7 +1525,6 @@ TOKEN [IGNORE_CASE] :
| < TRUE: "true" >
| < FALSE: "false" >
}
-// SPARQL/Update parts.
TOKEN [IGNORE_CASE] :
{
< DATA: "data" >
@@ -1744,22 +1545,16 @@ TOKEN [IGNORE_CASE] :
| < INTO: "into" >
| < TO: "to" >
| < DFT: "default" >
-//| < NAMED: "named" >
| < ALL: "all" >
| < WITH: "with" >
| < USING: "using" >
-//| < BEGIN: "begin" >
-//| < COMMIT: "commit" >
-//| < ABORT: "abort" >
}
-// -------------------------------------------------
TOKEN :
{
< #DIGITS: (["0"-"9"])+>
| < INTEGER: <DIGITS> >
-//| < DECIMAL: ( <DIGITS> "." (<DIGITS>)* | "." <DIGITS> ) >
| < DECIMAL: (<DIGITS>)? "." <DIGITS> >
-| < DOUBLE: // Required exponent.
+| < DOUBLE:
(
(["0"-"9"])+ "." (["0"-"9"])* <EXPONENT>
| "." (["0"-"9"])+ (<EXPONENT>)
@@ -1777,10 +1572,8 @@ TOKEN :
| < #QUOTE_3S: "'''">
| <ECHAR: "\\" ( "t"|"b"|"n"|"r"|"f"|"\\"|"\""|"'") >
| < STRING_LITERAL1:
- // Single quoted string
"'" ( (~["'","\\","\n","\r"]) | <ECHAR> )* "'" >
| < STRING_LITERAL2:
- // Double quoted string
"\"" ( (~["\"","\\","\n","\r"]) | <ECHAR> )* "\"" >
| < STRING_LITERAL_LONG1:
<QUOTE_3S>
@@ -1795,10 +1588,6 @@ TOKEN :
{
< LPAREN: "(" >
| < RPAREN: ")" >
-// All the stuff for NUL is needed just to make a
-// single list "() ." as a triple pattern illegal.
-// It leads to a lot of extra work.
-// Similarly [].
| <NIL: <LPAREN> (<WSC>)* <RPAREN> >
| < LBRACE: "{" >
| < RBRACE: "}" >
@@ -1812,8 +1601,8 @@ TOKEN :
| < NE: "!=" >
| < GT: ">" >
| < LT: "<" >
-| < LE: "<=" > // Maybe: | "=>" >
-| < GE: ">=" > // Maybe: | "=<" >
+| < LE: "<=" >
+| < GE: ">=" >
| < BANG: "!" >
| < TILDE: "~" >
| < COLON: ":" >
@@ -1823,21 +1612,16 @@ TOKEN :
| < MINUS: "-" >
| < STAR: "*" >
| < SLASH: "/" >
-//| < AMP: "&" >
-//| < REM: "%" >
| < DATATYPE: "^^">
| < AT: "@">
-// Path related
| < VBAR: "|" >
| < CARAT: "^" >
| < FPATH: "->" >
| < RPATH: "<-" >
| < QMARK: "?" >
}
-// See XML chars.txt for notes
TOKEN:
{
- // XML 1.1 NCNameStartChar without "_"
<#PN_CHARS_BASE:
["A"-"Z"] | ["a"-"z"] |
["\u00C0"-"\u00D6"] | ["\u00D8"-"\u00F6"] | ["\u00F8"-"\u02FF"] |
@@ -1845,18 +1629,14 @@ TOKEN:
["\u200C"-"\u200D"] | ["\u2070"-"\u218F"] | ["\u2C00"-"\u2FEF"] |
["\u3001"-"\uD7FF"] | ["\uF900"-"\uFFFD"]
>
- // [#x10000-#xEFFFF]
|
- // With underscore
<#PN_CHARS_U: <PN_CHARS_BASE> | "_" >
|
<#PN_CHARS: (<PN_CHARS_U> | "-" | ["0"-"9"] | "\u00B7" |
["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] ) >
|
- // No leading "_", no trailing ".", can have dot inside prefix name.
<#PN_PREFIX: <PN_CHARS_BASE> ((<PN_CHARS>|".")* <PN_CHARS>)? >
|
- // Local part.
<#PN_LOCAL: (<PN_CHARS_U> | ":" | ["0"-"9"] | <PLX> )
( (<PN_CHARS> | "." |":" | <PLX> )*
(<PN_CHARS> | ":" | <PLX>) )? >
@@ -1865,7 +1645,6 @@ TOKEN:
( <PN_CHARS_U> | ["0"-"9"] | "\u00B7" |
["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] )* >
|
- // Align with QueryParseBase unescapePName.
< #PN_LOCAL_ESC: "\\"
( "_" |
"~" | "." | "-" | "!" | "$" | "&" | "'" |
@@ -1878,17 +1657,7 @@ TOKEN:
|
< #PERCENT: "%" <HEX> <HEX> >
}
-// Catch-all tokens. Must be last.
-// Any non-whitespace. Causes a parser exception, rather than a
-// token manager error (which hides the line numbers).
TOKEN:
{
<#UNKNOWN: (~[" ","\t","\n","\r","\f" ])+ >
}
-/*
-# Local Variables:
-# tab-width: 4
-# indent-tabs-mode: nil
-# comment-default-style: "//"
-# End:
-*/