- From: Eric Prud'hommeaux <eric@w3.org>
- Date: Sat, 1 Jan 2011 23:39:49 -0500
- To: public-rdf-dawg@w3.org
(replied to old thread for ease of grammar trackability)
I updated the
http://www.w3.org/2005/01/yacker/uploads/SPARQL_11?lang=perl
yacker grammar to reflect
http://www.w3.org/2009/sparql/docs/sparql-grammar-11
with the following changes:
Added a "top" to put all of SPARQL under one start production:
+ [0] Top ::= QueryUnit | UpdateUnit
[1] QueryUnit ::= Query
[2] Query ::= Prologue
( SelectQuery | ConstructQuery | DescribeQuery | AskQuery )
[3] Prologue ::= BaseDecl? PrefixDecl*
[4] BaseDecl ::= 'BASE' IRI_REF
[5] PrefixDecl ::= 'PREFIX' PNAME_NS IRI_REF
[6] SelectQuery ::= SelectClause DatasetClause* WhereClause SolutionModifier BindingsClause
Added BindingsClause to SubSelect, ConstructQuery, DescribeQuery and AskQuery:
- [7] SubSelect ::= SelectClause WhereClause SolutionModifier
+ [7] SubSelect ::= SelectClause WhereClause SolutionModifier BindingsClause
[8] SelectClause ::= 'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( ( Var | ( '(' Expression 'AS' Var ')' ) )+ | '*' )
- [9] ConstructQuery ::= 'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier
+ [9] ConstructQuery ::= 'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier BindingsClause
- [10] DescribeQuery ::= 'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier
+ [10] DescribeQuery ::= 'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier BindingsClause
- [11] AskQuery ::= 'ASK' DatasetClause* WhereClause
+ [11] AskQuery ::= 'ASK' DatasetClause* WhereClause BindingsClause
[12] DatasetClause ::= 'FROM' ( DefaultGraphClause | NamedGraphClause )
[13] DefaultGraphClause ::= SourceSelector
[14] NamedGraphClause ::= 'NAMED' SourceSelector
[15] SourceSelector ::= IRIref
[16] WhereClause ::= 'WHERE'? GroupGraphPattern
[17] SolutionModifier ::= GroupClause? HavingClause? OrderClause? LimitOffsetClauses?
[18] GroupClause ::= 'GROUP' 'BY' GroupCondition+
Removed extra parens on 19, 24, 46, 67, 68, 106, 115
- [19] GroupCondition ::= ( BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var )
+ [19] GroupCondition ::= BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var
[20] HavingClause ::= 'HAVING' HavingCondition+
[21] HavingCondition ::= Constraint
[22] OrderClause ::= 'ORDER' 'BY' OrderCondition+
[23] OrderCondition ::= ( ( 'ASC' | 'DESC' ) BrackettedExpression )
| ( Constraint | Var )
- [24] LimitOffsetClauses ::= ( LimitClause OffsetClause? | OffsetClause LimitClause? )
+ [24] LimitOffsetClauses ::= LimitClause OffsetClause? | OffsetClause LimitClause?
[25] LimitClause ::= 'LIMIT' INTEGER
[26] OffsetClause ::= 'OFFSET' INTEGER
[27] BindingsClause ::= ( 'BINDINGS' Var* '{' ( '(' BindingValue+ ')' | NIL )* '}' )?
[28] BindingValue ::= IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | 'UNDEF'
[29] UpdateUnit ::= Update
[30] Update ::= Prologue Update1 ( ';' Update? )?
[31] Update1 ::= Load | Clear | Drop | Add | Move | Copy | Create | InsertData | DeleteData | DeleteWhere | Modify
[32] Load ::= 'LOAD' IRIref ( 'INTO' GraphRef )?
[33] Clear ::= 'CLEAR' 'SILENT'? GraphRefAll
[34] Drop ::= 'DROP' 'SILENT'? GraphRefAll
[35] Create ::= 'CREATE' 'SILENT'? GraphRef
[36] Add ::= 'ADD' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
[37] Move ::= 'MOVE' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
[38] Copy ::= 'COPY' 'SILENT'? GraphOrDefault 'TO' GraphOrDefault
Made separators for 'INSERT DATA', 'DELETE DATA', 'DELETE WHERE' more whitespace-friendly:
- [39] InsertData ::= 'INSERT DATA' QuadData
+ [39] InsertData ::= 'INSERT[ \t\r\n]+DATA' QuadData
- [40] DeleteData ::= 'DELETE DATA' QuadData
+ [40] DeleteData ::= 'DELETE[ \t\r\n]+DATA' QuadData
- [41] DeleteWhere ::= 'DELETE WHERE' QuadPattern
+ [41] DeleteWhere ::= 'DELETE[ \t\r\n]+WHERE' QuadPattern
[42] Modify ::= ( 'WITH' IRIref )? ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
[43] DeleteClause ::= 'DELETE' QuadPattern
[44] InsertClause ::= 'INSERT' QuadPattern
[45] UsingClause ::= 'USING' ( IRIref | 'NAMED' IRIref )
- [46] GraphOrDefault ::= ( 'DEFAULT' | 'GRAPH'? IRIref )
+ [46] GraphOrDefault ::= 'DEFAULT' | 'GRAPH'? IRIref
[47] GraphRef ::= 'GRAPH' IRIref
[48] GraphRefAll ::= GraphRef | 'DEFAULT' | 'NAMED' | 'ALL'
QuadPattern and QuadData are redundant for now. I guess the
intention is that e.g. "DELETE WHERE { ?s <p> <o> }" be allowed
but "INSERT DATA { ?s <p> <o> }" not be allowed. I left this alone.
[49] QuadPattern ::= '{' Quads '}'
[50] QuadData ::= '{' Quads '}'
[51] Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )*
[52] QuadsNotTriples ::= 'GRAPH' VarOrIRIref '{' TriplesTemplate? '}'
[53] TriplesTemplate ::= TriplesSameSubject ( '.' TriplesTemplate? )?
[54] GroupGraphPattern ::= '{' ( SubSelect | GroupGraphPatternSub ) '}'
[55] GroupGraphPatternSub ::= TriplesBlock? ( GraphPatternNotTriples '.'? TriplesBlock? )*
[56] TriplesBlock ::= TriplesSameSubjectPath ( '.' TriplesBlock? )?
[57] GraphPatternNotTriples ::= GroupOrUnionGraphPattern | OptionalGraphPattern | MinusGraphPattern | GraphGraphPattern | ServiceGraphPattern | Filter | Bind
[58] OptionalGraphPattern ::= 'OPTIONAL' GroupGraphPattern
[59] GraphGraphPattern ::= 'GRAPH' VarOrIRIref GroupGraphPattern
[60] ServiceGraphPattern ::= 'SERVICE' VarOrIRIref GroupGraphPattern
[61] Bind ::= 'BIND' '(' Expression 'AS' Var ')'
[62] MinusGraphPattern ::= 'MINUS' GroupGraphPattern
[63] GroupOrUnionGraphPattern ::= GroupGraphPattern ( 'UNION' GroupGraphPattern )*
[64] Filter ::= 'FILTER' Constraint
[65] Constraint ::= BrackettedExpression | BuiltInCall | FunctionCall
[66] FunctionCall ::= IRIref ArgList
- [67] ArgList ::= ( NIL | '(' 'DISTINCT'? Expression ( ',' Expression )* ')' )
+ [67] ArgList ::= NIL | '(' 'DISTINCT'? Expression ( ',' Expression )* ')'
- [68] ExpressionList ::= ( NIL | '(' Expression ( ',' Expression )* ')' )
+ [68] ExpressionList ::= NIL | '(' Expression ( ',' Expression )* ')'
[69] ConstructTemplate ::= '{' ConstructTriples? '}'
[70] ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )?
[71] TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
[72] PropertyListNotEmpty ::= Verb ObjectList ( ';' ( Verb ObjectList )? )*
[73] PropertyList ::= PropertyListNotEmpty?
[74] ObjectList ::= Object ( ',' Object )*
[75] Object ::= GraphNode
[76] Verb ::= VarOrIRIref | 'a'
[77] TriplesSameSubjectPath ::= VarOrTerm PropertyListNotEmptyPath | TriplesNode PropertyListPath
[78] PropertyListNotEmptyPath ::= ( VerbPath | VerbSimple ) ObjectList ( ';' ( ( VerbPath | VerbSimple ) ObjectList )? )*
[79] PropertyListPath ::= PropertyListNotEmpty?
[80] VerbPath ::= Path
[81] VerbSimple ::= Var
[82] Path ::= PathAlternative
[83] PathAlternative ::= PathSequence ( '|' PathSequence )*
[84] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )*
[85] PathElt ::= PathPrimary PathMod?
[86] PathEltOrInverse ::= PathElt | '^' PathElt
[87] PathMod ::= ( '*' | '?' | '+' | '{' ( Integer ( ',' ( '}' | Integer '}' ) | '}' ) | ',' Integer '}' ) )
[88] PathPrimary ::= ( IRIref | 'a' | '!' PathNegatedPropertySet | '(' Path ')' )
[89] PathNegatedPropertySet ::= ( PathOneInPropertySet | '(' ( PathOneInPropertySet ( '|' PathOneInPropertySet )* )? ')' )
[90] PathOneInPropertySet ::= ( IRIref | 'a' | '^' ( IRIref | 'a' ) )
[91] Integer ::= INTEGER
[92] TriplesNode ::= Collection | BlankNodePropertyList
[93] BlankNodePropertyList ::= '[' PropertyListNotEmpty ']'
[94] Collection ::= '(' GraphNode+ ')'
[95] GraphNode ::= VarOrTerm | TriplesNode
[96] VarOrTerm ::= Var | GraphTerm
[97] VarOrIRIref ::= Var | IRIref
[98] Var ::= VAR1 | VAR2
[99] GraphTerm ::= IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL
[100] Expression ::= ConditionalOrExpression
[101] ConditionalOrExpression ::= ConditionalAndExpression ( '||' ConditionalAndExpression )*
[102] ConditionalAndExpression ::= ValueLogical ( '&&' ValueLogical )*
[103] ValueLogical ::= RelationalExpression
Factored out a RelativeExpression to simplify RelationalExpression rule
and ease life for parser generators; broke up multi-word terminal 'NOT IN':
- [104] RelationalExpression ::= NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression | 'IN' ExpressionList | 'NOT IN' ExpressionList )?
+ [104] RelationalExpression ::= NumericExpression RelativeExpression?
+ [104b] RelativeExpression ::= '=' NumericExpression
+ | '!=' NumericExpression
+ | '<' NumericExpression
+ | '>' NumericExpression
+ | '<=' NumericExpression
+ | '>=' NumericExpression
+ | 'IN' ExpressionList
+ | 'NOT' 'IN' ExpressionList
[105] NumericExpression ::= AdditiveExpression
- [106] AdditiveExpression ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( ( '*' UnaryExpression ) | ( '/' UnaryExpression ) )? )*
+ [106] AdditiveExpression ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | ( NumericLiteralPositive | NumericLiteralNegative ) ( '*' UnaryExpression | '/' UnaryExpression )? )*
[107] MultiplicativeExpression ::= UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )*
[108] UnaryExpression ::= '!' PrimaryExpression
| '+' PrimaryExpression
| '-' PrimaryExpression
| PrimaryExpression
[109] PrimaryExpression ::= BrackettedExpression | BuiltInCall | IRIrefOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var | Aggregate
[110] BrackettedExpression ::= '(' Expression ')'
[111] BuiltInCall ::= '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 ')'
| 'UCASE' '(' Expression ')'
| 'LCASE' '(' Expression ')'
| 'ENCODE_FOR_URI' '(' Expression ')'
| 'CONTAINS' '(' Expression ',' Expression ')'
| 'STRSTARTS' '(' Expression ',' Expression ')'
| 'STRENDS' '(' Expression ',' Expression ')'
| 'YEAR' '(' Expression ')'
| 'MONTH' '(' Expression ')'
| 'DAY' '(' Expression ')'
| 'HOURS' '(' Expression ')'
| 'MINUTES' '(' Expression ')'
| 'SECONDS' '(' Expression ')'
| 'TIMEZONE' '(' Expression ')'
| 'NOW' NIL
| 'MD5' '(' Expression ')'
| 'SHA1' '(' Expression ')'
| 'SHA224' '(' 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
[112] RegexExpression ::= 'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
[113] SubstringExpression ::= 'SUBSTR' '(' Expression ',' Expression ( ',' Expression )? ')'
[114] ExistsFunc ::= 'EXISTS' GroupGraphPattern
Broke up terminal:
- [115] NotExistsFunc ::= 'NOT EXISTS' GroupGraphPattern
+ [115] NotExistsFunc ::= 'NOT' 'EXISTS' GroupGraphPattern
Removed outer ()s and factored aggregates with common parameters [[ '(' 'DISTINCT'? Expression ')' ]]:
- [116] 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 )? ')' )
+ [116] Aggregate ::= 'COUNT' '(' 'DISTINCT'? ( '*' | Expression ) ')' | ( 'SUM' | 'MIN' | 'MAX' | 'AVG' | 'SAMPLE' ) '(' 'DISTINCT'? Expression ')' | 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
[117] IRIrefOrFunction ::= IRIref ArgList?
[118] RDFLiteral ::= String ( LANGTAG | ( '^^' IRIref ) )?
[119] NumericLiteral ::= NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative
[120] NumericLiteralUnsigned ::= INTEGER | DECIMAL | DOUBLE
[121] NumericLiteralPositive ::= INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE
[122] NumericLiteralNegative ::= INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE
[123] BooleanLiteral ::= 'true' | 'false'
[124] String ::= STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
[125] IRIref ::= IRI_REF | PrefixedName
[126] PrefixedName ::= PNAME_LN | PNAME_NS
[127] BlankNode ::= BLANK_NODE_LABEL | ANON
[128] IRI_REF ::= '<' ([^<>"{}|^`\]-[#x00-#x20])* '>'
[129] PNAME_NS ::= PN_PREFIX? ':'
[130] PNAME_LN ::= PNAME_NS PN_LOCAL
[131] BLANK_NODE_LABEL ::= '_:' PN_LOCAL
[132] VAR1 ::= '?' VARNAME
[133] VAR2 ::= '$' VARNAME
[134] LANGTAG ::= '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)*
[135] INTEGER ::= [0-9]+
[136] DECIMAL ::= [0-9]+ '.' [0-9]* | '.' [0-9]+
[137] DOUBLE ::= [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT
[138] INTEGER_POSITIVE ::= '+' INTEGER
[139] DECIMAL_POSITIVE ::= '+' DECIMAL
[140] DOUBLE_POSITIVE ::= '+' DOUBLE
[141] INTEGER_NEGATIVE ::= '-' INTEGER
[142] DECIMAL_NEGATIVE ::= '-' DECIMAL
[143] DOUBLE_NEGATIVE ::= '-' DOUBLE
[144] EXPONENT ::= [eE] [+-]? [0-9]+
[145] STRING_LITERAL1 ::= "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'"
[146] STRING_LITERAL2 ::= '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"'
[147] STRING_LITERAL_LONG1 ::= "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''"
[148] STRING_LITERAL_LONG2 ::= '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""'
[149] ECHAR ::= '\' [tbnrf\"']
[150] NIL ::= '(' WS* ')'
[151] WS ::= #x20 | #x9 | #xD | #xA
[152] ANON ::= '[' WS* ']'
[153] 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]
[154] PN_CHARS_U ::= PN_CHARS_BASE | '_'
[155] VARNAME ::= ( PN_CHARS_U | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
[156] PN_CHARS ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
[157] PN_PREFIX ::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
[158] PN_LOCAL ::= ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
* Eric Prud'hommeaux <eric@w3.org> [2010-10-19 02:03-0400]
> * Eric Prud'hommeaux <eric@w3.org> [2010-10-18 23:21-0400]
> > I updated the
> > http://www.w3.org/2005/01/yacker/uploads/SPARQL_11?lang=perl
> > yacker grammar to reflect
> > http://www.w3.org/2009/sparql/docs/sparql-grammar-11
> > with three small changes:
> >
> > Added a "top" to put all of SPARQL under one start production:
> > + [0] Top ::= QueryUnit | UpdateUnit
>
> Removed ()s around RHSs on:
> ~ [19] GroupCondition ::= BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var
> ~ [24] LimitOffsetClauses ::= LimitClause OffsetClause? | OffsetClause LimitClause?
> ~ [62] ArgList ::= NIL | '(' 'DISTINCT'? Expression ( ',' Expression )* ')'
> ~ [63] ExpressionList ::= NIL | '(' Expression ( ',' Expression )* ')'
>
>
> > Moved the WS*s out of 36-38 and split 39 to avoid the reduce-reuse-recyle error:
> > ~ [36] InsertData ::= 'INSERT' 'DATA' QuadData
> > ~ [37] DeleteData ::= 'DELETE' 'DATA' QuadData
> > ~ [38] DeleteWhere ::= 'DELETE' 'WHERE' QuadPattern # ???
> > ~ [39] Modify ::= ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
> > ~ | ( 'WITH' IRIref ) ( DeleteClause InsertClause? | InsertClause ) UsingClause* 'WHERE' GroupGraphPattern
> >
> > Why do we need QuadData and QuadPattern?
> > ~ [46] QuadData ::= '{' Quads '}' # ???
> >
> > Removing DeleteWhere and s/QuadPattern/QuadData/g gives no S/R errors.
>
> Separated 'NOT' 'IN' and 'NOT' 'EXISTS' and shortened RelationalExpression
> ~ [99] RelationalExpression ::= NumericExpression RelativeExpression?
> ~ [00] RelativeExpression ::= '=' NumericExpression
> | '!=' NumericExpression
> | '<' NumericExpression
> | '>' NumericExpression
> | '<=' NumericExpression
> | '>=' NumericExpression
> | 'IN' ExpressionList
> | 'NOT' 'IN' ExpressionList
> ~[109] NotExistsFunc ::= 'NOT' 'EXISTS' GroupGraphPattern
>
> Grouped like aggregate expressions:
> ~ [110] Aggregate ::= 'COUNT' '(' 'DISTINCT'? ( '*' | Expression ) ')' | ( 'SUM' | 'MIN' | 'MAX' | 'AVG' | 'SAMPLE' ) '(' 'DISTINCT'? Expression ')' | 'GROUP_CONCAT' '(' 'DISTINCT'? Expression ( ';' 'SEPARATOR' '=' String )? ')'
>
>
> > --
> > -ericP
>
> --
> -ericP
--
-ericP
Received on Sunday, 2 January 2011 04:40:31 UTC