Full XSPARQL grammar

The grammar into XQuery and SPARQL parts. Added objects are set in bold: insert; Deleted objects are set strikethrough: deleted. Changed production rules are also set in bold. Some of the links in the XQuery section are currently broken.

See also the XQuery grammar and the SPARQL grammar.

Contents

XQuery Non terminals

[1]   Module   ::=   VersionDecl? (LibraryModule | MainModule)
[2]   VersionDecl   ::=   "xquery" "version" StringLiteral ("encoding" StringLiteral)? Separator
[3]   MainModule   ::=   Prolog QueryBody
[4]   LibraryModule   ::=   ModuleDecl Prolog
[5]   ModuleDecl   ::=   "module" "namespace" NCName "=" URILiteral Separator
[6]   Prolog   ::=   BaseDecl?(((DefaultNamespaceDecl | Setter | NamespaceDecl | ImportX) Separator) | PrefixDecl)* ((VarDecl | FunctionDecl | OptionDecl) Separator)*
[7]   Setter   ::=   BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | CopyNamespacesDecl
[8]   ImportX   ::=   SchemaImport | ModuleImport
[9]   Separator   ::=   ";"
[10]   NamespaceDecl   ::=   "declare" "namespace" NCName "=" URILiteral
[11]   BoundarySpaceDecl   ::=   "declare" "boundary-space" ("preserve" | "strip")
[12]   DefaultNamespaceDecl   ::=   "declare" "default" ("element" | "function") "namespace" URILiteral
[13]   OptionDecl   ::=   "declare" "option" QName StringLiteral
[14]   OrderingModeDecl   ::=   "declare" "ordering" ("ordered" | "unordered")
[15]   EmptyOrderDecl   ::=   "declare" "default" "order" "empty" ("greatest" | "least")
[16]   CopyNamespacesDecl   ::=   "declare" "copy-namespaces" PreserveMode "," InheritMode
[17]   PreserveMode   ::=   "preserve" | "no-preserve"
[18]   InheritMode   ::=   "inherit" | "no-inherit"
[19]   DefaultCollationDecl   ::=   "declare" "default" "collation" URILiteral
[20]   BaseURIDecl   ::=   "declare" "base-uri" URILiteral
[21]   SchemaImport   ::=   "import" "schema" SchemaPrefix? URILiteral ("at" URILiteral ("," URILiteral)*)?
[22]   SchemaPrefix   ::=   ("namespace" NCName "=") | ("default" "element" "namespace")
[23]   ModuleImport   ::=   "import" "module" ("namespace" NCName "=")? URILiteral ("at" URILiteral ("," URILiteral)*)?
[24]   VarDecl   ::=   "declare" "variable" "$" QName TypeDeclaration? ((":=" ExprSingle) | "external")
[25]   ConstructionDecl   ::=   "declare" "construction" ("strip" | "preserve")
[26]   FunctionDecl   ::=   "declare" "function" QName "(" ParamList? ")" ("as" SequenceType)? (EnclosedExpr | "external")
[27]   ParamList   ::=   Param ("," Param)*
[28]   Param   ::=   "$" QName TypeDeclaration?
[29]   EnclosedExpr   ::=   "{" Expr "}"
[30]   QueryBody   ::=   Expr
[31]   Expr   ::=   ExprSingle ("," ExprSingle)*
[32]   ExprSingle   ::=   FLWORExpr
| QuantifiedExpr
| TypeswitchExpr
| IfExpr
| OrExpr
[33]   FLWORExpr   ::=   (ForClause | LetClause | SparqlForClause)+ WhereClause? OrderByClause? "return" ExprSingle ReturnClause
[33a]   ReturnClause   ::=   "return" ExprSingle | "construct" ConstructTemplate
[33b]   SparqlForClause   ::=   "for" "distinct"? ("$" VarName ("$" Varname)* | "*") DatasetClause "where" GroupGraphPattern SolutionModifier
[34]   ForClause   ::=   "for" "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle ("," "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle)*
[35]   PositionalVar   ::=   "at" "$" VarName
[36]   LetClause   ::=   "let" "$" VarName TypeDeclaration? ":=" ExprSingle ("," "$" VarName TypeDeclaration? ":=" ExprSingle)*
[37]   WhereClause   ::=   "where" ExprSingle
[38]   OrderByClause   ::=   (("order" "by") | ("stable" "order" "by")) OrderSpecList
[39]   OrderSpecList   ::=   OrderSpec ("," OrderSpec)*
[40]   OrderSpec   ::=   ExprSingle OrderModifier
[41]   OrderModifier   ::=   ("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation" URILiteral)?
[42]   QuantifiedExpr   ::=   ("some" | "every") "$" VarName TypeDeclaration? "in" ExprSingle ("," "$" VarName TypeDeclaration? "in" ExprSingle)* "satisfies" ExprSingle
[43]   TypeswitchExpr   ::=   "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle
[44]   CaseClause   ::=   "case" ("$" VarName "as")? SequenceType "return" ExprSingle
[45]   IfExpr   ::=   "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
[46]   OrExpr   ::=   AndExpr ( "or" AndExpr )*
[47]   AndExpr   ::=   ComparisonExpr ( "and" ComparisonExpr )*
[48]   ComparisonExpr   ::=   RangeExpr ( (ValueComp
| GeneralComp
| NodeComp) RangeExpr )?
[49]   RangeExpr   ::=   AdditiveExpr ( "to" AdditiveExpr )?
[50]   AdditiveExpr   ::=   MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )*
[51]   MultiplicativeExpr   ::=   UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )*
[52]   UnionExpr   ::=   IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )*
[53]   IntersectExceptExpr   ::=   InstanceofExpr ( ("intersect" | "except") InstanceofExpr )*
[54]   InstanceofExpr   ::=   TreatExpr ( "instance" "of" SequenceType )?
[55]   TreatExpr   ::=   CastableExpr ( "treat" "as" SequenceType )?
[56]   CastableExpr   ::=   CastExpr ( "castable" "as" SingleType )?
[57]   CastExpr   ::=   UnaryExpr ( "cast" "as" SingleType )?
[58]   UnaryExpr   ::=   ("-" | "+")* ValueExpr
[59]   ValueExpr   ::=   ValidateExpr | PathExpr | ExtensionExpr
[60]   GeneralComp   ::=   "=" | "!=" | "<" | "<=" | ">" | ">="
[61]   ValueComp   ::=   "eq" | "ne" | "lt" | "le" | "gt" | "ge"
[62]   NodeComp   ::=   "is" | "<<" | ">>"
[63]   ValidateExpr   ::=   "validate" ValidationMode? "{" Expr "}"
[64]   ValidationMode   ::=   "lax" | "strict"
[65]   ExtensionExpr   ::=   Pragma+ "{" Expr? "}"
[66]   Pragma   ::=   "(#" S? QName (S PragmaContents)? "#)" /* ws: explicit */
[67]   PragmaContents   ::=   (Char* - (Char* '#)' Char*))
[68]   PathExpr   ::=   ("/" RelativePathExpr?)
| ("//" RelativePathExpr)
| RelativePathExpr
/* xgs: leading-lone-slash */
[69]   RelativePathExpr   ::=   StepExpr (("/" | "//") StepExpr)*
[70]   StepExpr   ::=   FilterExpr | AxisStep
[71]   AxisStep   ::=   (ReverseStep | ForwardStep) PredicateList
[72]   ForwardStep   ::=   (ForwardAxis NodeTest) | AbbrevForwardStep
[73]   ForwardAxis   ::=   ("child" "::")
| ("descendant" "::")
| ("attribute" "::")
| ("self" "::")
| ("descendant-or-self" "::")
| ("following-sibling" "::")
| ("following" "::")
[74]   AbbrevForwardStep   ::=   "@"? NodeTest
[75]   ReverseStep   ::=   (ReverseAxis NodeTest) | AbbrevReverseStep
[76]   ReverseAxis   ::=   ("parent" "::")
| ("ancestor" "::")
| ("preceding-sibling" "::")
| ("preceding" "::")
| ("ancestor-or-self" "::")
[77]   AbbrevReverseStep   ::=   ".."
[78]   NodeTest   ::=   KindTest | NameTest
[79]   NameTest   ::=   QName | Wildcard
[80]   Wildcard   ::=   "*"
| (NCName ":" "*")
| ("*" ":" NCName)
/* ws: explicit */
[81]   FilterExpr   ::=   PrimaryExpr PredicateList
[82]   PredicateList   ::=   Predicate*
[83]   Predicate   ::=   "[" Expr "]"
[84]   PrimaryExpr   ::=   Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall | OrderedExpr | UnorderedExpr | Constructor
[85]   Literal   ::=   NumericLiteral | StringLiteral
[86]   NumericLiteral   ::=   IntegerLiteral | DecimalLiteral | DoubleLiteral
[87]   VarRef   ::=   "$" VarName
[88]   VarName   ::=   QName
[89]   ParenthesizedExpr   ::=   "(" Expr? ")"
[90]   ContextItemExpr   ::=   "."
[91]   OrderedExpr   ::=   "ordered" "{" Expr "}"
[92]   UnorderedExpr   ::=   "unordered" "{" Expr "}"
[93]   FunctionCall   ::=   QName "(" (ExprSingle ("," ExprSingle)*)? ")" /* xgs: reserved-function-names */
/* gn: parens */
[94]   Constructor   ::=   DirectConstructor
| ComputedConstructor
[95]   DirectConstructor   ::=   DirElemConstructor
| DirCommentConstructor
| DirPIConstructor
[96]   DirElemConstructor   ::=   "<" QName DirAttributeList ("/>" | (">" DirElemContent* "</" QName S? ">")) /* ws: explicit */
[97]   DirAttributeList   ::=   (S (QName S? "=" S? DirAttributeValue)?)* /* ws: explicit */
[98]   DirAttributeValue   ::=   ('"' (EscapeQuot | QuotAttrValueContent)* '"')
| ("'" (EscapeApos | AposAttrValueContent)* "'")
/* ws: explicit */
[99]   QuotAttrValueContent   ::=   QuotAttrContentChar
| CommonContent
[100]   AposAttrValueContent   ::=   AposAttrContentChar
| CommonContent
[101]   DirElemContent   ::=   DirectConstructor
| CDataSection
| CommonContent
| ElementContentChar
[102]   CommonContent   ::=   PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr
[103]   DirCommentConstructor   ::=   "<!--" DirCommentContents "-->" /* ws: explicit */
[104]   DirCommentContents   ::=   ((Char - '-') | ('-' (Char - '-')))* /* ws: explicit */
[105]   DirPIConstructor   ::=   "<?" PITarget (S DirPIContents)? "?>" /* ws: explicit */
[106]   DirPIContents   ::=   (Char* - (Char* '?>' Char*)) /* ws: explicit */
[107]   CDataSection   ::=   "<![CDATA[" CDataSectionContents "]]>" /* ws: explicit */
[108]   CDataSectionContents   ::=   (Char* - (Char* ']]>' Char*)) /* ws: explicit */
[109]   ComputedConstructor   ::=   CompDocConstructor
| CompElemConstructor
| CompAttrConstructor
| CompTextConstructor
| CompCommentConstructor
| CompPIConstructor
[110]   CompDocConstructor   ::=   "document" "{" Expr "}"
[111]   CompElemConstructor   ::=   "element" (QName | ("{" Expr "}")) "{" ContentExpr? "}"
[112]   ContentExpr   ::=   Expr
[113]   CompAttrConstructor   ::=   "attribute" (QName | ("{" Expr "}")) "{" Expr? "}"
[114]   CompTextConstructor   ::=   "text" "{" Expr "}"
[115]   CompCommentConstructor   ::=   "comment" "{" Expr "}"
[116]   CompPIConstructor   ::=   "processing-instruction" (NCName | ("{" Expr "}")) "{" Expr? "}"
[117]   SingleType   ::=   AtomicType "?"?
[118]   TypeDeclaration   ::=   "as" SequenceType
[119]   SequenceType   ::=   ("empty-sequence" "(" ")")
| (ItemType OccurrenceIndicator?)
[120]   OccurrenceIndicator   ::=   "?" | "*" | "+" /* xgs: occurrence-indicators */
[121]   ItemType   ::=   KindTest | ("item" "(" ")") | AtomicType
[122]   AtomicType   ::=   QName
[123]   KindTest   ::=   DocumentTest
| ElementTest
| AttributeTest
| SchemaElementTest
| SchemaAttributeTest
| PITest
| CommentTest
| TextTest
| AnyKindTest
[124]   AnyKindTest   ::=   "node" "(" ")"
[125]   DocumentTest   ::=   "document-node" "(" (ElementTest | SchemaElementTest)? ")"
[126]   TextTest   ::=   "text" "(" ")"
[127]   CommentTest   ::=   "comment" "(" ")"
[128]   PITest   ::=   "processing-instruction" "(" (NCName | StringLiteral)? ")"
[129]   AttributeTest   ::=   "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")"
[130]   AttribNameOrWildcard   ::=   AttributeName | "*"
[131]   SchemaAttributeTest   ::=   "schema-attribute" "(" AttributeDeclaration ")"
[132]   AttributeDeclaration   ::=   AttributeName
[133]   ElementTest   ::=   "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")"
[134]   ElementNameOrWildcard   ::=   ElementName | "*"
[135]   SchemaElementTest   ::=   "schema-element" "(" ElementDeclaration ")"
[136]   ElementDeclaration   ::=   ElementName
[137]   AttributeName   ::=   QName
[138]   ElementName   ::=   QName
[139]   TypeName   ::=   QName
[140]   URILiteral   ::=   StringLiteral

XQuery Terminals

[141]   IntegerLiteral   ::=   Digits
[142]   DecimalLiteral   ::=   ("." Digits) | (Digits "." [0-9]*) /* ws: explicit */
[143]   DoubleLiteral   ::=   (("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits /* ws: explicit */
[144]   StringLiteral   ::=   ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") /* ws: explicit */
[145]   PredefinedEntityRef   ::=   "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";" /* ws: explicit */
[146]   EscapeQuot   ::=   '""'
[147]   EscapeApos   ::=   "''"
[148]   ElementContentChar   ::=   Char - [{}<&]
[149]   QuotAttrContentChar   ::=   Char - ["{}<&]
[150]   AposAttrContentChar   ::=   Char - ['{}<&]
[151]   Comment   ::=   "(:" (CommentContents | Comment)* ":)" /* ws: explicit */
/* gn: comments */
[152]   PITarget   ::=   [http://www.w3.org/TR/REC-xml#NT-PITarget] XML /* xgs: xml-version */
[153]   CharRef   ::=   [http://www.w3.org/TR/REC-xml#NT-CharRef] XML /* xgs: xml-version */
[154]   QName   ::=   [http://www.w3.org/TR/REC-xml-names/#NT-QName] Names /* xgs: xml-version */
[155]   NCName   ::=   [http://www.w3.org/TR/REC-xml-names/#NT-NCName] Names /* xgs: xml-version */
[156]   S   ::=   [http://www.w3.org/TR/REC-xml#NT-S] XML /* xgs: xml-version */
[157]   Char   ::=   [http://www.w3.org/TR/REC-xml#NT-Char] XML /* xgs: xml-version */

The following symbols are used only in the definition of terminal symbols; they are not terminal symbols in the grammar of A.1 EBNF.

[158]   Digits   ::=   [0-9]+
[159]   CommentContents   ::=   (Char+ - (Char* ('(:' | ':)') Char*))

SPARQL Non terminals

Keep in mind that for XSPARQL only lowercase keywords are allowed. To retain the original grammar as much as possible, keywords are mostly set in uppercase.

[1]   Query   ::=   Prologue
( SelectQuery | ConstructQuery | DescribeQuery | AskQuery )
[2]   Prologue   ::=   BaseDecl? PrefixDecl*
[3]   BaseDecl   ::=   'BASE' IRI_REF
[4]   PrefixDecl   ::=   'PREFIX' PNAME_NS IRI_REF
[5]   SelectQuery   ::=   'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( Var+ | '*' ) DatasetClause* WhereClause SolutionModifier
[6]   ConstructQuery   ::=   'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier
[7]   DescribeQuery   ::=   'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier
[8]   AskQuery   ::=   'ASK' DatasetClause* WhereClause
[9]   DatasetClause   ::=   'FROM' ( DefaultGraphClause | NamedGraphClause)
[10]   DefaultGraphClause   ::=   SourceSelector
[11]   NamedGraphClause   ::=   'NAMED' SourceSelector
[12]   SourceSelector   ::=   IRIref | Var
[13]   WhereClause   ::=   'WHERE'? GroupGraphPattern
[14]   SolutionModifier   ::=   OrderClause? LimitOffsetClauses?
[15]   LimitOffsetClauses   ::=   ( LimitClause OffsetClause? | OffsetClause LimitClause? )
[16]   OrderClause   ::=   'ORDER' 'BY' OrderCondition+
[17]   OrderCondition   ::=   ( ( 'ASC' | 'DESC' ) BrackettedExpression )
| ( Constraint | Var )
[18]   LimitClause   ::=   'LIMIT' INTEGER
[19]   OffsetClause   ::=   'OFFSET' INTEGER
[20]   GroupGraphPattern   ::=   '{' TriplesBlock? ( ( GraphPatternNotTriples | Filter ) '.'? TriplesBlock? )* '}'
[21]   TriplesBlock   ::=   TriplesSameSubject ( '.' TriplesBlock? )?
[22]   GraphPatternNotTriples   ::=   OptionalGraphPattern | GroupOrUnionGraphPattern | GraphGraphPattern
[23]   OptionalGraphPattern   ::=   'OPTIONAL' GroupGraphPattern
[24]   GraphGraphPattern   ::=   'GRAPH' VarOrIRIref GroupGraphPattern
[25]   GroupOrUnionGraphPattern   ::=   GroupGraphPattern ( 'UNION' GroupGraphPattern )*
[26]   Filter   ::=   'FILTER' Constraint
[27]   Constraint   ::=   BrackettedExpression | BuiltInCall | FunctionCall
[28]   FunctionCall   ::=   IRIref ArgList
[29]   ArgList   ::=   ( NIL | '(' Expression ( ',' Expression )* ')' )
[30]   ConstructTemplate   ::=   '{' ConstructTriples? '}'
[31]   ConstructTriples   ::=   TriplesSameSubject' ( '.' ConstructTriples? )?
[32]   TriplesSameSubject   ::=   VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
[32']  TriplesSameSubject'   ::=   VarOrTerm' PropertyListNotEmpty' | TriplesNode' PropertyList'
[33]   PropertyListNotEmpty   ::=   Verb ObjectList ( ';' ( Verb ObjectList )? )*
[33']  PropertyListNotEmpty'   ::=   Verb' ObjectList' ( ';' ( Verb' ObjectList' )? )*
[34]  PropertyList   ::=   PropertyListNotEmpty?
[34']  PropertyList'   ::=   PropertyListNotEmpty'?
[35]   ObjectList   ::=   Object ( ',' Object )*
[35']  ObjectList'   ::=   Object' ( ',' Object' )*
[36]   Object   ::=   GraphNode
[36']  Object'   ::=   GraphNode'
[37]   Verb   ::=   VarOrIRIref | 'a'
[37']  Verb'   ::=   VarOrIRIref' | 'a'
[38]   TriplesNode   ::=   Collection | BlankNodePropertyList
[38']  TriplesNode'   ::=   Collection' | BlankNodePropertyList'
[39]   BlankNodePropertyList   ::=   '[' PropertyListNotEmpty ']'
[39']  BlankNodePropertyList'   ::=   '[' PropertyListNotEmpty' ']'
[40]   Collection   ::=   '(' GraphNode+ ')'
[40']  Collection'   ::=   '(' GraphNode'+ ')'
[41]   GraphNode   ::=   VarOrTerm | TriplesNode
[41']  GraphNode'   ::=   VarOrTerm' | TriplesNode'
[42]   VarOrTerm   ::=   Var | GraphTerm
[42']  VarOrTerm'   ::=   Var | GraphTerm'
[43]   VarOrIRIref   ::=   Var | IRIref
[43']  VarOrIRIref'   ::=   Var | IRIref'
[44]   Var   ::=   VAR1 | VAR2
[45]   GraphTerm   ::=   IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL
[45']  GraphTerm'   ::=   IRIref' | RDFLiteral' | NumericLiteral | BooleanLiteral | BlankNode' | NIL
[46]   Expression   ::=   ConditionalOrExpression
[47]   ConditionalOrExpression   ::=   ConditionalAndExpression ( '||' ConditionalAndExpression )*
[48]   ConditionalAndExpression   ::=   ValueLogical ( '&&' ValueLogical )*
[49]   ValueLogical   ::=   RelationalExpression
[50]   RelationalExpression   ::=   NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression )?
[51]   NumericExpression   ::=   AdditiveExpression
[52]   AdditiveExpression   ::=   MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | NumericLiteralPositive | NumericLiteralNegative )*
[53]   MultiplicativeExpression   ::=   UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )*
[54]   UnaryExpression   ::=     '!' PrimaryExpression
| '+' PrimaryExpression
| '-' PrimaryExpression
| PrimaryExpression
[55]   PrimaryExpression   ::=   BrackettedExpression | BuiltInCall | IRIrefOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var
[56]   BrackettedExpression   ::=   '(' Expression ')'
[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
[58]   RegexExpression   ::=   'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
[59]   IRIrefOrFunction   ::=   IRIref ArgList?
[60]   RDFLiteral   ::=   String ( LANGTAG | ( '^^' IRIref ) )?
[60']   RDFLiteral'   ::=   String' ( LANGTAG | '@{' FLWORExpr '}' | ( '^^' IRIref') )?
[61]   NumericLiteral   ::=   NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative
[62]   NumericLiteralUnsigned   ::=   INTEGER | DECIMAL | DOUBLE
[63]   NumericLiteralPositive   ::=   INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE
[64]   NumericLiteralNegative   ::=   INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE
[65]   BooleanLiteral   ::=   'true' | 'false'
[66]   String   ::=   STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
[66']   String'   ::=   STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 | '{' FLWORExpr '}'
[67]   IRIref   ::=   IRI_REF | PrefixedName
[67']   IRIref'   ::=   IRI_REF | '<{' FLWORExpr '}>' | PrefixedName'
[68]   PrefixedName   ::=   PNAME_LN | PNAME_NS
[68']   PrefixedName'   ::=   PNAME_LN( (PN_PREFIX | '{' FLWORExpr '}')? ':' (PN_LOCAL | '{' FLWORExpr '}') ) | PNAME_NS
[69]   BlankNode   ::=   BLANK_NODE_LABEL | ANON
[69']   BlankNode'   ::=   BLANK_NODE_LABEL | ANON | '_:{' FLWORExpr '}'

SPARQL Terminals

[70]   IRI_REF   ::=   '<' ([^<>"{}|^`\]-[#x00-#x20])* '>'
[71]   PNAME_NS   ::=   PN_PREFIX? ':'
[72]   PNAME_LN   ::=   PNAME_NS PN_LOCAL
[73]   BLANK_NODE_LABEL   ::=   '_:' PN_LOCAL
[74]   VAR1   ::=   '?' VARNAME
[75]   VAR2   ::=   '$' VARNAME
[76]   LANGTAG   ::=   '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)*
[77]   INTEGER   ::=   [0-9]+
[78]   DECIMAL   ::=   [0-9]+ '.' [0-9]* | '.' [0-9]+
[79]   DOUBLE   ::=   [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT
[80]   INTEGER_POSITIVE   ::=   '+' INTEGER
[81]   DECIMAL_POSITIVE   ::=   '+' DECIMAL
[82]   DOUBLE_POSITIVE   ::=   '+' DOUBLE
[83]   INTEGER_NEGATIVE   ::=   '-' INTEGER
[84]   DECIMAL_NEGATIVE   ::=   '-' DECIMAL
[85]   DOUBLE_NEGATIVE   ::=   '-' DOUBLE
[86]   EXPONENT   ::=   [eE] [+-]? [0-9]+
[87]   STRING_LITERAL1   ::=   "'" ( ([^#x27#x5C#xA#xD]) | ECHAR )* "'"
[88]   STRING_LITERAL2   ::=   '"' ( ([^#x22#x5C#xA#xD]) | ECHAR )* '"'
[89]   STRING_LITERAL_LONG1   ::=   "'''" ( ( "'" | "''" )? ( [^'\] | ECHAR ) )* "'''"
[90]   STRING_LITERAL_LONG2   ::=   '"""' ( ( '"' | '""' )? ( [^"\] | ECHAR ) )* '"""'
[91]   ECHAR   ::=   '\' [tbnrf\"']
[92]   NIL   ::=   '(' WS* ')'
[93]   WS   ::=   #x20 | #x9 | #xD | #xA
[94]   ANON   ::=   '[' WS* ']'
[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]
[96]   PN_CHARS_U   ::=   PN_CHARS_BASE | '_'
[97]   VARNAME   ::=   ( PN_CHARS_U - '_' | [0-9] ) ( PN_CHARS_U | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040] )*
[98]   PN_CHARS   ::=   PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
[99]   PN_PREFIX   ::=   PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
[100]   PN_LOCAL   ::=   ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
Note that SPARQL local names allow leading digits while XML local names do not.