# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | QueryList <EOF>
QueryList | ::= | Module ( <QuerySeparator> ( Module )? )*
Module | ::= | ( VersionDecl )? ( MainModule | LibraryModule )
MainModule | ::= | Prolog QueryBody
LibraryModule | ::= | ModuleDecl Prolog
ModuleDecl | ::= | <ModuleNamespace> <NCNameForPrefix> <AssignEquals> <URLLiteral> Separator
Prolog | ::= | ( ( NamespaceDecl | XMLSpaceDecl | DefaultNamespaceDecl | DefaultCollationDecl | BaseURIDecl | SchemaImport | ModuleImport | VarDecl | ValidationDecl | FunctionDecl ) Separator )*
Separator | ::= | <SemiColon>
VersionDecl | ::= | <VersionStringLiteral> Separator
ModuleImport | ::= | <ImportModuleToken> ( <Namespace> <NCNameForPrefix> <AssignEquals> )? <URLLiteral> ( <AtStringLiteral> )?
VarDecl | ::= | <DefineVariable> <VarName> ( TypeDeclaration )? ( ( <LbraceExprEnclosure> Expr <Rbrace> ) | <External> )
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> Expr
OrderByClause | ::= | ( <OrderBy> | <OrderByStable> ) OrderSpecList
OrderSpecList | ::= | OrderSpec ( <Comma> OrderSpec )*
OrderSpec | ::= | ExprSingle OrderModifier
OrderModifier | ::= | ( ( <Ascending> | <Descending> ) )? ( ( <EmptyGreatest> | <EmptyLeast> ) )? ( <Collation> <StringLiteral> )?
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 | ::= | InstanceofExpr ( <And> InstanceofExpr )*
InstanceofExpr | ::= | TreatExpr ( <Instanceof> SequenceType )?
TreatExpr | ::= | CastableExpr ( <TreatAs> SequenceType )?
CastableExpr | ::= | CastExpr ( <Castable> SingleType )?
CastExpr | ::= | ComparisonExpr ( <CastAs> SingleType )?
ComparisonExpr | ::= | RangeExpr ( ( ValueComp | GeneralComp | NodeComp ) RangeExpr )?
RangeExpr | ::= | AdditiveExpr ( <To> AdditiveExpr )?
AdditiveExpr | ::= | MultiplicativeExpr ( ( <Plus> | <Minus> ) MultiplicativeExpr )*
MultiplicativeExpr | ::= | UnaryExpr ( ( <Multiply> | <Div> | <Idiv> | <Mod> ) UnaryExpr )*
UnaryExpr | ::= | ( <UnaryMinus> | <UnaryPlus> )* UnionExpr
UnionExpr | ::= | IntersectExceptExpr ( ( <Union> | <Vbar> ) IntersectExceptExpr )*
IntersectExceptExpr | ::= | ValueExpr ( ( <Intersect> | <Except> ) ValueExpr )*
ValueExpr | ::= | ( ValidateExpr | PathExpr )
PathExpr | ::= | ( ( <Root> ( RelativePathExpr )? ) | ( <RootDescendants> RelativePathExpr ) | RelativePathExpr )
RelativePathExpr | ::= | StepExpr ( ( <Slash> | <SlashSlash> ) StepExpr )*
StepExpr | ::= | ( AxisStep | FilterStep )
AxisStep | ::= | ( ForwardStep | ReverseStep ) Predicates
FilterStep | ::= | PrimaryExpr Predicates
ContextItemExpr | ::= | <Dot>
PrimaryExpr | ::= | ( Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall | Constructor )
VarRef | ::= | <VariableIndicator> <VarName>
Predicates | ::= | ( ( ( <Lbrack> Expr <Rbrack> ) ) )*
ValidateExpr | ::= | ( <ValidateLbrace> | ( <ValidateGlobal> <LbraceExprEnclosure> ) | ( <ValidateContext> SchemaContextLoc <LbraceExprEnclosure> ) | ( <ValidateSchemaMode> ( SchemaContext )? <LbraceExprEnclosure> ) ) Expr <Rbrace>
SchemaContext | ::= | ( ( <InContextForKindTest> SchemaContextLoc ) | <Global> )
Constructor | ::= | ( DirElemConstructor | ComputedConstructor | XmlComment | XmlPI | CdataSection )
ComputedConstructor | ::= | ( CompElemConstructor | CompAttrConstructor | CompDocConstructor | CompTextConstructor | CompXmlPI | CompXmlComment | CompNSConstructor )
GeneralComp | ::= | ( <Equals> | <NotEquals> | <Lt> | <LtEquals> | <Gt> | <GtEquals> )
ValueComp | ::= | ( <FortranEq> | <FortranNe> | <FortranLt> | <FortranLe> | <FortranGt> | <FortranGe> )
NodeComp | ::= | ( <Is> | <LtLt> | <GtGt> )
ForwardStep | ::= | ( ( ForwardAxis NodeTest ) | AbbrevForwardStep )
ReverseStep | ::= | ( ( ReverseAxis ( NodeTest ) ) | AbbrevReverseStep )
AbbrevForwardStep | ::= | ( <At> )? NodeTest
AbbrevReverseStep | ::= | <DotDot>
ForwardAxis | ::= | ( <AxisChild> | <AxisDescendant> | <AxisAttribute> | <AxisSelf> | <AxisDescendantOrSelf> | <AxisFollowingSibling> | <AxisFollowing> )
ReverseAxis | ::= | ( <AxisParent> | <AxisAncestor> | <AxisPrecedingSibling> | <AxisPreceding> | <AxisAncestorOrSelf> )
NodeTest | ::= | ( KindTest | NameTest )
NameTest | ::= | ( <QName> | Wildcard )
Wildcard | ::= | ( <Star> | <NCNameColonStar> | <StarColonNCName> )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
ParenthesizedExpr | ::= | <Lpar> ( Expr )? <Rpar>
FunctionCall | ::= | ( <QNameLpar> ) ( ExprSingle ( <Comma> ExprSingle )* )? <Rpar>
DirElemConstructor | ::= | ( <StartTagOpenRoot> | <StartTagOpen> ) <TagQName> AttributeList ( <EmptyTagClose> | ( <StartTagClose> ( ElementContent )* <EndTagOpen> <TagQName> ( <S> )? <EndTagClose> ) )
CompDocConstructor | ::= | ( <DocumentLbrace> Expr <Rbrace> )
CompElemConstructor | ::= | ( <ElementQNameLbrace> | ( <ElementLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( Expr )? <Rbrace>
CompNSConstructor | ::= | <NamespaceNCNameLbrace> Expr <Rbrace>
CompAttrConstructor | ::= | ( <AttributeQNameLbrace> | ( <AttributeLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( Expr )? <Rbrace>
CompXmlPI | ::= | ( <PINCNameLbrace> | ( <PILbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( Expr )? <Rbrace>
CompXmlComment | ::= | <CommentLbrace> Expr <Rbrace>
CompTextConstructor | ::= | <TextLbrace> ( Expr )? <Rbrace>
CdataSection | ::= | <CdataSectionStart> ( <CDataSectionChar> )* <CdataSectionEnd>
XmlPI | ::= | <ProcessingInstructionStart> <PITarget> ( <PIContentChar> )* <ProcessingInstructionEnd>
XmlComment | ::= | <XmlCommentStart> ( <CommentContentChar> )* <XmlCommentEnd>
ElementContent | ::= | ( <ElementContentChar> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | DirElemConstructor | EnclosedExpr | CdataSection | <CharRef> | <PredefinedEntityRef> | XmlComment | XmlPI )
AttributeList | ::= | ( <S> ( <TagQName> ( <S> )? <ValueIndicator> ( <S> )? AttributeValue )? )*
AttributeValue | ::= | ( ( <OpenQuot> ( ( <EscapeQuot> | QuotAttrValueContent ) )* <CloseQuot> ) | ( <OpenApos> ( ( <EscapeApos> | AposAttrValueContent ) )* <CloseApos> ) )
QuotAttrValueContent | ::= | ( <QuotAttContentChar> | <CharRef> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | EnclosedExpr | <PredefinedEntityRef> )
AposAttrValueContent | ::= | ( <AposAttContentChar> | <CharRef> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | EnclosedExpr | <PredefinedEntityRef> )
EnclosedExpr | ::= | ( <Lbrace> | <LbraceExprEnclosure> ) Expr <Rbrace>
XMLSpaceDecl | ::= | <DeclareXMLSpace> ( <XMLSpacePreserve> | <XMLSpaceStrip> )
DefaultCollationDecl | ::= | <DeclareCollation> <URLLiteral>
BaseURIDecl | ::= | <DeclareBaseURI> <URLLiteral>
NamespaceDecl | ::= | <DeclareNamespace> <NCNameForPrefix> <AssignEquals> <URLLiteral>
DefaultNamespaceDecl | ::= | ( <DeclareDefaultElement> | <DeclareDefaultFunction> ) <Namespace> <URLLiteral>
FunctionDecl | ::= | <DefineFunction> <QNameLpar> ( ParamList )? ( <Rpar> | ( <RparAs> SequenceType ) ) ( EnclosedExpr | <External> )
ParamList | ::= | Param ( <Comma> Param )*
Param | ::= | <VariableIndicator> <VarName> ( TypeDeclaration )?
TypeDeclaration | ::= | <As> SequenceType
SingleType | ::= | AtomicType ( <OccurrenceZeroOrOne> )?
SequenceType | ::= | ( ( ItemType ( OccurrenceIndicator )? ) | <Empty> )
AtomicType | ::= | <QNameForSequenceType>
ItemType | ::= | ( AtomicType | KindTest | <Item> )
KindTest | ::= | ( DocumentTest | ElementTest | AttributeTest | PITest | CommentTest | TextTest | AnyKindTest )
ElementTest | ::= | ( <ElementType> | <ElementTypeForKindTest> | <ElementTypeForDocumentTest> ) ( ( ( SchemaContextPath ElementName ) | ( ElementNameOrWildcard ( <CommaForKindTest> TypeNameOrWildcard ( <Nillable> )? )? ) ) )? <RparForKindTest>
AttributeTest | ::= | ( <AttributeType> | <AttributeTypeForKindTest> ) ( ( ( SchemaContextPath AttributeName ) | ( AttribNameOrWildcard ( <CommaForKindTest> TypeNameOrWildcard )? ) ) )? <RparForKindTest>
ElementName | ::= | <QNameForItemType>
AttributeName | ::= | <QNameForItemType>
TypeName | ::= | <QNameForItemType>
ElementNameOrWildcard | ::= | ( ElementName | <AnyName> )
AttribNameOrWildcard | ::= | ( AttributeName | <AnyName> )
TypeNameOrWildcard | ::= | ( TypeName | <AnyName> )
PITest | ::= | ( <ProcessingInstructionLpar> | <ProcessingInstructionLparForKindTest> ) ( ( <NCNameForPI> | <StringLiteralForKindTest> ) )? <RparForKindTest>
DocumentTest | ::= | ( <DocumentLpar> | <DocumentLparForKindTest> ) ( ElementTest )? <RparForKindTest>
CommentTest | ::= | ( <CommentLpar> | <CommentLparForKindTest> ) <RparForKindTest>
TextTest | ::= | ( <TextLpar> | <TextLparForKindTest> ) <RparForKindTest>
AnyKindTest | ::= | ( <NodeLpar> | <NodeLparForKindTest> ) <RparForKindTest>
SchemaContextPath | ::= | <SchemaGlobalContextSlash> ( <SchemaContextStepSlash> )*
SchemaContextLoc | ::= | ( ( ( SchemaContextPath )? <QNameForItemType> ) | <SchemaGlobalTypeName> )
OccurrenceIndicator | ::= | ( <OccurrenceZeroOrOne> | <OccurrenceZeroOrMore> | <OccurrenceOneOrMore> )
ValidationDecl | ::= | <DeclareValidation> <SchemaModeForDeclareValidate>
SchemaImport | ::= | <ImportSchemaToken> ( SchemaPrefix )? <URLLiteral> ( <AtStringLiteral> )?
SchemaPrefix | ::= | ( ( <Namespace> <NCNameForPrefix> <AssignEquals> ) | ( <DefaultElement> <Namespace> ) )