# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | Expr <EOF>
ModuleDecl | ::= | "module" "namespace" NCName "=" URILiteral Separator
Separator | ::= | ";"
NamespaceDecl | ::= | "declare" "namespace" NCName "=" URILiteral
DefaultNamespaceDecl | ::= | "declare" "default" ( "element" | "function" ) "namespace" URILiteral
OptionDecl | ::= | "declare" "option" QName <StringLiteral>
OrderingModeDecl | ::= | "declare" "ordering" ( "ordered" | "unordered" )
EmptyOrderDecl | ::= | "declare" "default" "order" "empty" ( <Greatest> | <Least> )
CopyNamespacesDecl | ::= | "declare" "copy-namespaces" PreserveMode "," InheritMode
PreserveMode | ::= | ( "preserve" | "no-preserve" )
InheritMode | ::= | ( "inherit" | "no-inherit" )
DefaultCollationDecl | ::= | "declare" "default" "collation" URILiteral
BaseURIDecl | ::= | "declare" "base-uri" URILiteral
SchemaImport | ::= | "import" "schema" ( SchemaPrefix )? URILiteral ( "at" URILiteral ( "," URILiteral )* )?
SchemaPrefix | ::= | ( ( "namespace" NCName "=" ) | ( "default" "element" "namespace" ) )
ModuleImport | ::= | "import" "module" ( "namespace" NCName "=" )? URILiteral ( "at" URILiteral ( "," URILiteral )* )?
VarDecl | ::= | "declare" "variable" "$" QName ( TypeDeclaration )? ( ( ":=" ExprSingle ) | <External> )
ConstructionDecl | ::= | "declare" "construction" ( "strip" | "preserve" )
FunctionDecl | ::= | "declare" "function" QName "(" ( ParamList )? ")" ( "as" SequenceType )? ( EnclosedExpr | <External> )
ParamList | ::= | Param ( "," Param )*
Param | ::= | "$" QName ( TypeDeclaration )?
EnclosedExpr | ::= | ( <Lbrace> | <LbraceExprEnclosure> ) Expr <Rbrace>
Expr | ::= | ExprSingle ( "," ExprSingle )*
ExprSingle | ::= | ( FLWORExpr | QuantifiedExpr | TypeswitchExpr | IfExpr | OrExpr )
FLWORExpr | ::= | ( ForClause | LetClause ) "return" ExprSingle
ForClause | ::= | "for" "$" VarName ( TypeDeclaration )? ( PositionalVar )? "in" ExprSingle
PositionalVar | ::= | "at" "$" VarName
LetClause | ::= | ( "let" "$" VarName ( TypeDeclaration )? ) ":=" ExprSingle
OrderByClause | ::= | ( ( "order" "by" ) | ( "stable" "order" "by" ) ) OrderSpecList
OrderSpecList | ::= | OrderSpec ( "," OrderSpec )*
OrderSpec | ::= | ExprSingle OrderModifier
OrderModifier | ::= | ( ( <Ascending> | <Descending> ) )? ( "empty" ( <Greatest> | <Least> ) )? ( "collation" URILiteral )?
QuantifiedExpr | ::= | ( "some" | "every" ) "$" VarName ( TypeDeclaration )? "in" ExprSingle ( "," "$" VarName ( TypeDeclaration )? "in" ExprSingle )* "satisfies" ExprSingle
TypeswitchExpr | ::= | "typeswitch" "(" Expr ")" ( CaseClause )+ "default" "$" VarName "return" ExprSingle
CaseClause | ::= | "case" "$" VarName "as" SequenceType "return" ExprSingle
IfExpr | ::= | "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
OperatorExpr | ::= | OrExpr
OrExpr | ::= | AndExpr ( "or" AndExpr )*
AndExpr | ::= | CastableExpr ( "and" CastableExpr )*
CastableExpr | ::= | CastExpr ( "castable" "as" SingleType )?
CastExpr | ::= | ValueExpr ( "cast" "as" SingleType )?
ValueExpr | ::= | ( ValidateExpr | StepExpr | ExtensionExpr )
ValidateExpr | ::= | "validate" ( ValidationMode )? <LbraceExprEnclosure> Expr <Rbrace>
ValidationMode | ::= | ( "lax" | "strict" )
ExtensionExpr | ::= | ( Pragma )+ <LbraceExprEnclosure> ( Expr )? <Rbrace>
Pragma | ::= | <PragmaOpen> ( <S> )? <QNameForPragma> ( <SForPragma> PragmaContents )? <PragmaClose>
PragmaContents | ::= | ( <ExtensionContentChar> )*
StepExpr | ::= | ( PrimaryExpr | AxisStep )
AxisStep | ::= | ( ReverseStep | ForwardStep )
ForwardStep | ::= | ( ForwardAxis NodeTest )
ForwardAxis | ::= | ( ( "child" "::" ) | ( "descendant" "::" ) | ( "attribute" "::" ) | ( "self" "::" ) | ( "descendant-or-self" "::" ) | ( "namespace" "::" ) )
ReverseStep | ::= | ( ReverseAxis NodeTest )
ReverseAxis | ::= | ( ( "parent" "::" ) | ( "ancestor" "::" ) | ( "ancestor-or-self" "::" ) )
NodeTest | ::= | ( KindTest | NameTest )
NameTest | ::= | ( QName | Wildcard )
Wildcard | ::= | ( "*" | <NCNameColonStar> | <StarColonNCName> )
PrimaryExpr | ::= | ( Literal | VarRef | ParenthesizedExpr | FunctionCall | OrderedExpr | UnorderedExpr | Constructor )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
VarRef | ::= | "$" VarName
VarName | ::= | QName
ParenthesizedExpr | ::= | "(" ( Expr )? ")"
OrderedExpr | ::= | "ordered" <LbraceExprEnclosure> Expr <Rbrace>
UnorderedExpr | ::= | "unordered" <LbraceExprEnclosure> Expr <Rbrace>
FunctionCall | ::= | FunctionQName "(" ( ExprSingle ( "," ExprSingle )* )? ")"
Constructor | ::= | ComputedConstructor
ComputedConstructor | ::= | ( CompDocConstructor | CompElemConstructor | CompAttrConstructor | CompTextConstructor | CompCommentConstructor | CompPIConstructor )
CompDocConstructor | ::= | "document" <LbraceExprEnclosure> Expr <Rbrace>
CompElemConstructor | ::= | "element" ( QName | ( <LbraceExprEnclosure> Expr <Rbrace> ) ) <LbraceExprEnclosure> ContentExpr <Rbrace> <LbraceExprEnclosure> ( NamespaceBinding )* <Rbrace>
NamespaceBinding | ::= | "namespace" NCName <Lbrace> URILiteral <Rbrace>
ContentExpr | ::= | Expr
CompAttrConstructor | ::= | "attribute" ( QName | ( <LbraceExprEnclosure> Expr <Rbrace> ) ) <LbraceExprEnclosure> Expr <Rbrace>
CompTextConstructor | ::= | "text" <LbraceExprEnclosure> Expr <Rbrace>
CompCommentConstructor | ::= | "comment" <LbraceExprEnclosure> Expr <Rbrace>
CompPIConstructor | ::= | "processing-instruction" ( NCName | ( <LbraceExprEnclosure> Expr <Rbrace> ) ) <LbraceExprEnclosure> ( Expr )? <Rbrace>
SingleType | ::= | AtomicType ( "?" )?
TypeDeclaration | ::= | "as" SequenceType
SequenceType | ::= | ( ( "empty-sequence" "(" ")" ) | ( ItemType ( OccurrenceIndicator )? ) )
OccurrenceIndicator | ::= | ( "?" | "*" | <Plus> )
ItemType | ::= | ( KindTest | ( "item" "(" ")" ) | AtomicType )
AtomicType | ::= | QName
KindTest | ::= | ( DocumentTest | ElementTest | AttributeTest | SchemaElementTest | SchemaAttributeTest | PITest | CommentTest | TextTest | AnyKindTest )
AnyKindTest | ::= | "node" "(" ")"
DocumentTest | ::= | "document-node" "(" ( ( ElementTest | SchemaElementTest ) )? ")"
TextTest | ::= | "text" "(" ")"
CommentTest | ::= | "comment" "(" ")"
PITest | ::= | "processing-instruction" "(" ( ( NCName | <StringLiteral> ) )? ")"
AttributeTest | ::= | "attribute" "(" ( ( AttribNameOrWildcard ( "," TypeName )? ) )? ")"
AttribNameOrWildcard | ::= | ( AttributeName | "*" )
SchemaAttributeTest | ::= | "schema-attribute" "(" AttributeDeclaration ")"
AttributeDeclaration | ::= | AttributeName
ElementTest | ::= | "element" "(" ( ( ElementNameOrWildcard ( "," TypeName ( "?" )? )? ) )? ")"
ElementNameOrWildcard | ::= | ( ElementName | "*" )
SchemaElementTest | ::= | "schema-element" "(" ElementDeclaration ")"
ElementDeclaration | ::= | ElementName
AttributeName | ::= | QName
ElementName | ::= | QName
TypeName | ::= | QName
URILiteral | ::= | <StringLiteral>
NCName | ::= | QName
QName | ::= | ( FunctionQName | "attribute" | "comment" | "document-node" | "element" | "if" | "item" | "node" | "processing-instruction" | "schema-attribute" | "schema-element" | "text" | "typeswitch" | "empty-sequence" )
FunctionQName | ::= | ( <QNameToken> | <External> | "xquery" | "version" | "encoding" | "module" | "namespace" | "declare" | "default" | "function" | "option" | "ordering" | "ordered" | "unordered" | "order" | "empty" | <Greatest> | <Least> | "copy-namespaces" | "no-preserve" | "inherit" | "no-inherit" | "collation" | "base-uri" | "import" | "schema" | "at" | "variable" | "construction" | "as" | "lax" | "strict" | "return" | "for" | "in" | "let" | "by" | "stable" | <Ascending> | <Descending> | "some" | "every" | "satisfies" | "case" | "then" | "else" | "or" | "and" | "div" | "castable" | "cast" | "validate" | "child" | "descendant" | "self" | "descendant-or-self" | "parent" | "ancestor" | "ancestor-or-self" | "document" | "type" )