# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | QueryList <EOF>
QueryList | ::= | Module ( <QuerySeparator> ( Module )? )*
Module | ::= | ( VersionDecl )? ( MainModule | LibraryModule )
VersionDecl | ::= | <XQueryVersion> <StringLiteralForVersion> ( <XQueryEncoding> <StringLiteralForVersion> )? Separator
MainModule | ::= | Prolog QueryBody
LibraryModule | ::= | ModuleDecl Prolog
ModuleDecl | ::= | <ModuleNamespace> <NCNameForPrefix> <AssignEquals> <URILiteral> Separator
Prolog | ::= | ( ( Setter | Import | NamespaceDecl | DefaultNamespaceDecl ) Separator )* ( ( VarDecl | FunctionDecl | OptionDecl ) Separator )*
Setter | ::= | ( BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | CopyNamespacesDecl )
Import | ::= | ( SchemaImport | ModuleImport )
Separator | ::= | <SemiColon>
NamespaceDecl | ::= | <DeclareNamespace> <NCNameForPrefix> <AssignEquals> <URILiteral>
BoundarySpaceDecl | ::= | <DeclareXMLSpace> ( <XMLSpacePreserve> | <XMLSpaceStrip> )
DefaultNamespaceDecl | ::= | ( <DeclareDefaultElement> | <DeclareDefaultFunction> ) <Namespace> <URILiteral>
OptionDecl | ::= | <DeclareOption> <QNameForOption> <StringLiteral>
OrderingModeDecl | ::= | <DeclareOrdering> ( <Ordered> | <Unordered> )
EmptyOrderDecl | ::= | <DeclareDefaultOrder> ( <EmptyGreatest> | <EmptyLeast> )
CopyNamespacesDecl | ::= | <DeclareCopyNamespace> PreserveMode <CommaForCopyNamespace> InheritMode
PreserveMode | ::= | ( <Preserve> | <NoPreserve> )
InheritMode | ::= | ( <Inherit> | <NoInherit> )
DefaultCollationDecl | ::= | <DeclareCollation> <URILiteral>
BaseURIDecl | ::= | <DeclareBaseURI> <URILiteral>
SchemaImport | ::= | <ImportSchemaToken> ( SchemaPrefix )? <URILiteral> ( <AtURILiteral> ( <CommaForURITransition> <URILiteral> )* )?
SchemaPrefix | ::= | ( ( <Namespace> <NCNameForPrefix> <AssignEquals> ) | ( <DefaultElement> <Namespace> ) )
ModuleImport | ::= | <ImportModuleToken> ( <Namespace> <NCNameForPrefix> <AssignEquals> )? <URILiteral> ( <AtURILiteral> ( <CommaForURITransition> <URILiteral> )* )?
VarDecl | ::= | <DefineVariable> <VarName> ( TypeDeclaration )? ( ( <ColonEquals> ExprSingle ) | <External> )
ConstructionDecl | ::= | <DeclareConstruction> <SchemaModeForDeclareConstruction>
FunctionDecl | ::= | <DefineFunction> <QNameLpar> ( ParamList )? ( <Rpar> | ( <RparAs> SequenceType ) ) ( EnclosedExpr | <External> )
ParamList | ::= | Param ( <Comma> Param )*
Param | ::= | <VariableIndicator> <VarName> ( TypeDeclaration )?
EnclosedExpr | ::= | ( <Lbrace> | <LbraceExprEnclosure> ) Expr <Rbrace>
QueryBody | ::= | ( Expr )
Expr | ::= | ExprSingle ( <Comma> ExprSingle )*
ExprSingle | ::= | ( FLWORExpr | QuantifiedExpr | TypeswitchExpr | IfExpr | OrExpr )
FLWORExpr | ::= | ( ( ForClause | LetClause ) )+ ( WhereClause )? ( OrderByClause )? <Return> ExprSingle
ForClause | ::= | <ForVariable> <VarName> ( TypeDeclaration )? ( PositionalVar )? <In> ExprSingle ( <Comma> <VariableIndicator> <VarName> ( TypeDeclaration )? ( PositionalVar )? <In> ExprSingle )*
PositionalVar | ::= | <AtWord> <VariableIndicator> <VarName>
LetClause | ::= | <LetVariable> <VarName> ( TypeDeclaration )? <ColonEquals> ExprSingle ( <Comma> <VariableIndicator> <VarName> ( TypeDeclaration )? <ColonEquals> ExprSingle )*
WhereClause | ::= | <Where> ExprSingle
OrderByClause | ::= | ( <OrderBy> | <OrderByStable> ) OrderSpecList
OrderSpecList | ::= | OrderSpec ( <Comma> OrderSpec )*
OrderSpec | ::= | ExprSingle OrderModifier
OrderModifier | ::= | ( ( <Ascending> | <Descending> ) )? ( ( <EmptyGreatest> | <EmptyLeast> ) )? ( <Collation> <URILiteralToOperator> )?
QuantifiedExpr | ::= | ( <Some> | <Every> ) <VarName> ( TypeDeclaration )? <In> ExprSingle ( <Comma> <VariableIndicator> <VarName> ( TypeDeclaration )? <In> ExprSingle )* <Satisfies> ExprSingle
TypeswitchExpr | ::= | <TypeswitchLpar> Expr <Rpar> ( CaseClause )+ <Default> ( <VariableIndicator> <VarName> )? <Return> ExprSingle
CaseClause | ::= | <Case> ( <VariableIndicator> <VarName> <As> )? SequenceType <Return> ExprSingle
IfExpr | ::= | <IfLpar> Expr <Rpar> <Then> ExprSingle <Else> ExprSingle
OperatorExpr | ::= | OrExpr
OrExpr | ::= | AndExpr ( <Or> AndExpr )*
AndExpr | ::= | ComparisonExpr ( <And> ComparisonExpr )*
ComparisonExpr | ::= | RangeExpr ( ( ValueComp | GeneralComp | NodeComp ) RangeExpr )?
RangeExpr | ::= | AdditiveExpr ( <To> AdditiveExpr )?
AdditiveExpr | ::= | MultiplicativeExpr ( ( <Plus> | <Minus> ) MultiplicativeExpr )*
MultiplicativeExpr | ::= | UnionExpr ( ( <Multiply> | <Div> | <Idiv> | <Mod> ) UnionExpr )*
UnionExpr | ::= | IntersectExceptExpr ( ( <Union> | <Vbar> ) IntersectExceptExpr )*
IntersectExceptExpr | ::= | InstanceofExpr ( ( <Intersect> | <Except> ) InstanceofExpr )*
InstanceofExpr | ::= | TreatExpr ( <Instanceof> SequenceType )?
TreatExpr | ::= | CastableExpr ( <TreatAs> SequenceType )?
CastableExpr | ::= | CastExpr ( <Castable> SingleType )?
CastExpr | ::= | UnaryExpr ( <CastAs> SingleType )?
UnaryExpr | ::= | ( <UnaryMinus> | <UnaryPlus> )* ValueExpr
ValueExpr | ::= | ( ValidateExpr | PathExpr | ExtensionExpr )
GeneralComp | ::= | ( <Equals> | <NotEquals> | <Lt> | <LtEquals> | <Gt> | <GtEquals> )
ValueComp | ::= | ( <FortranEq> | <FortranNe> | <FortranLt> | <FortranLe> | <FortranGt> | <FortranGe> )
NodeComp | ::= | ( <Is> | <LtLt> | <GtGt> )
ValidateExpr | ::= | ( <ValidateLbrace> | ( <ValidateSchemaMode> <LbraceExprEnclosure> ) ) Expr <Rbrace>
ExtensionExpr | ::= | ( Pragma )+ <LbraceExprEnclosure> ( Expr )? <Rbrace>
Pragma | ::= | <PragmaOpen> ( <S> )? <QNameForPragma> PragmaContents <PragmaClose>
PragmaContents | ::= | ( <ExtensionContentChar> )*
PathExpr | ::= | ( ( <Root> ( RelativePathExpr )? ) | ( <RootDescendants> RelativePathExpr ) | RelativePathExpr )
RelativePathExpr | ::= | StepExpr ( ( <Slash> | <SlashSlash> ) StepExpr )*
StepExpr | ::= | ( AxisStep | FilterExpr )
AxisStep | ::= | ( ForwardStep | ReverseStep ) PredicateList
ForwardStep | ::= | ( ( ForwardAxis NodeTest ) | AbbrevForwardStep )
ForwardAxis | ::= | ( <AxisChild> | <AxisDescendant> | <AxisAttribute> | <AxisSelf> | <AxisDescendantOrSelf> | <AxisFollowingSibling> | <AxisFollowing> )
AbbrevForwardStep | ::= | ( <At> )? NodeTest
ReverseStep | ::= | ( ( ReverseAxis NodeTest ) | AbbrevReverseStep )
ReverseAxis | ::= | ( <AxisParent> | <AxisAncestor> | <AxisPrecedingSibling> | <AxisPreceding> | <AxisAncestorOrSelf> )
AbbrevReverseStep | ::= | <DotDot>
NodeTest | ::= | ( KindTest | NameTest )
NameTest | ::= | ( <QName> | Wildcard )
Wildcard | ::= | ( <Star> | <NCNameColonStar> | <StarColonNCName> )
FilterExpr | ::= | PrimaryExpr PredicateList
PredicateList | ::= | ( Predicate )*
Predicate | ::= | <Lbrack> Expr <Rbrack>
PrimaryExpr | ::= | ( Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall | Constructor | OrderedExpr | UnorderedExpr )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
VarRef | ::= | <VariableIndicator> <VarName>
ParenthesizedExpr | ::= | <Lpar> ( Expr )? <Rpar>
ContextItemExpr | ::= | <Dot>
OrderedExpr | ::= | <OrderedOpen> Expr <Rbrace>
UnorderedExpr | ::= | <UnorderedOpen> Expr <Rbrace>
FunctionCall | ::= | ( <QNameLpar> ) ( ExprSingle ( <Comma> ExprSingle )* )? <Rpar>
Constructor | ::= | ( DirectConstructor | ComputedConstructor )
DirectConstructor | ::= | ( DirElemConstructor | DirCommentConstructor | DirPIConstructor )
DirElemConstructor | ::= | ( <StartTagOpenRoot> | <StartTagOpen> ) <TagQName> DirAttributeList ( <EmptyTagClose> | ( <StartTagClose> ( DirElemContent )* <EndTagOpen> <TagQName> ( <S> )? <EndTagClose> ) )
DirAttributeList | ::= | ( <S> ( <TagQName> ( <S> )? <ValueIndicator> ( <S> )? DirAttributeValue )? )*
DirAttributeValue | ::= | ( ( <OpenQuot> ( ( <EscapeQuot> | QuotAttrValueContent ) )* <CloseQuot> ) | ( <OpenApos> ( ( <EscapeApos> | AposAttrValueContent ) )* <CloseApos> ) )
QuotAttrValueContent | ::= | ( <QuotAttrContentChar> | CommonContent )
AposAttrValueContent | ::= | ( <AposAttrContentChar> | CommonContent )
DirElemContent | ::= | ( DirectConstructor | <ElementContentChar> | CDataSection | CommonContent )
CommonContent | ::= | ( <PredefinedEntityRef> | <CharRef> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | EnclosedExpr )
DirCommentConstructor | ::= | ( <XmlCommentStartForElementContent> | <XmlCommentStart> ) DirCommentContents <XmlCommentEnd>
DirCommentContents | ::= | ( ( <CommentContentChar> | <CommentContentCharDash> ) )*
DirPIConstructor | ::= | ( <ProcessingInstructionStartForElementContent> | <ProcessingInstructionStart> ) <PITarget> ( <SForPI> DirPIContents )? <ProcessingInstructionEnd>
DirPIContents | ::= | ( <PIContentChar> )*
CDataSection | ::= | ( <CdataSectionStartForElementContent> | <CdataSectionStart> ) CDataSectionContents <CdataSectionEnd>
CDataSectionContents | ::= | ( <CDataSectionChar> )*
ComputedConstructor | ::= | ( CompDocConstructor | CompElemConstructor | CompAttrConstructor | CompTextConstructor | CompCommentConstructor | CompPIConstructor )
CompDocConstructor | ::= | <DocumentLbrace> Expr <Rbrace>
CompElemConstructor | ::= | ( <ElementQNameLbrace> | ( <ElementLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( ContentExpr )? <Rbrace>
ContentExpr | ::= | Expr
CompAttrConstructor | ::= | ( <AttributeQNameLbrace> | ( <AttributeLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( Expr )? <Rbrace>
CompTextConstructor | ::= | <TextLbrace> Expr <Rbrace>
CompCommentConstructor | ::= | <CommentLbrace> Expr <Rbrace>
CompPIConstructor | ::= | ( <PINCNameLbrace> | ( <PILbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( Expr )? <Rbrace>
SingleType | ::= | AtomicType ( <OccurrenceZeroOrOne> )?
TypeDeclaration | ::= | <As> SequenceType
SequenceType | ::= | ( ( ItemType ( OccurrenceIndicator )? ) | <EmptyTok> )
OccurrenceIndicator | ::= | ( <OccurrenceZeroOrOne> | <OccurrenceZeroOrMore> | <OccurrenceOneOrMore> )
ItemType | ::= | ( AtomicType | KindTest | <Item> )
AtomicType | ::= | ( <QNameForAtomicType> | <QNameForSequenceType> )
KindTest | ::= | ( DocumentTest | ElementTest | AttributeTest | SchemaElementTest | SchemaAttributeTest | PITest | CommentTest | TextTest | AnyKindTest )
AnyKindTest | ::= | ( <NodeLpar> | <NodeLparForKindTest> ) <RparForKindTest>
DocumentTest | ::= | ( <DocumentLpar> | <DocumentLparForKindTest> ) ( ( ElementTest | SchemaElementTest ) )? <RparForKindTest>
TextTest | ::= | ( <TextLpar> | <TextLparForKindTest> ) <RparForKindTest>
CommentTest | ::= | ( <CommentLpar> | <CommentLparForKindTest> ) <RparForKindTest>
PITest | ::= | ( <ProcessingInstructionLpar> | <ProcessingInstructionLparForKindTest> ) ( ( <NCNameForPI> | <StringLiteralForKindTest> ) )? <RparForKindTest>
AttributeTest | ::= | ( <AttributeType> | <AttributeTypeForKindTest> ) ( ( AttribNameOrWildcard ( <CommaForKindTest> TypeName )? ) )? <RparForKindTest>
AttribNameOrWildcard | ::= | ( AttributeName | <AnyName> )
SchemaAttributeTest | ::= | ( <SchemaAttributeType> | <SchemaAttributeTypeForKindTest> ) AttributeDeclaration <RparForKindTest>
AttributeDeclaration | ::= | AttributeName
ElementTest | ::= | ( <ElementType> | <ElementTypeForKindTest> | <ElementTypeForDocumentTest> ) ( ( ElementNameOrWildcard ( <CommaForKindTest> TypeName ( <Nillable> )? )? ) )? <RparForKindTest>
ElementNameOrWildcard | ::= | ( ElementName | <AnyName> )
SchemaElementTest | ::= | ( <SchemaElementType> | <SchemaElementTypeForKindTest> | <SchemaElementTypeForDocumentTest> ) ElementDeclaration <RparForKindTest>
ElementDeclaration | ::= | ElementName
AttributeName | ::= | <QNameForItemType>
ElementName | ::= | <QNameForItemType>
TypeName | ::= | <QNameForItemType>