# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | QueryList <EOF>
QueryList | ::= | Query ( <SemiColon> Query )*
Query | ::= | QueryProlog QueryBody
QueryProlog | ::= | ( ( NamespaceDecl | XMLSpaceDecl | DefaultNamespaceDecl | DefaultCollationDecl | SchemaImport ) )* ( FunctionDefn )*
QueryBody | ::= | ( ExprSequence )?
ExprSequence | ::= | Expr ( <Comma> Expr )*
Expr | ::= | OrExpr
OrExpr | ::= | AndExpr ( <Or> AndExpr )*
AndExpr | ::= | FLWRExpr ( <And> FLWRExpr )*
FLWRExpr | ::= | ( ( ( ForClause | LetClause ) )+ ( WhereClause )? ( OrderByClause )? <Return> )* QuantifiedExpr
QuantifiedExpr | ::= | ( ( <Some> | <Every> ) <VarName> ( TypeDeclaration )? <In> Expr ( <Comma> ( <VariableIndicator> <VarName> ( TypeDeclaration )? ) <In> Expr )* <Satisfies> )* TypeswitchExpr
TypeswitchExpr | ::= | ( <TypeswitchLpar> Expr <Rpar> ( CaseClause )+ <Default> ( <VariableIndicator> <VarName> )? <Return> )* IfExpr
IfExpr | ::= | ( <IfLpar> Expr <Rpar> <Then> Expr <Else> )* InstanceofExpr
InstanceofExpr | ::= | CastableExpr ( <Instanceof> SequenceType )?
CastableExpr | ::= | ComparisonExpr ( <Castable> SingleType )?
ComparisonExpr | ::= | RangeExpr ( ( ValueComp | GeneralComp | NodeComp | OrderComp ) RangeExpr )?
RangeExpr | ::= | AdditiveExpr ( <To> AdditiveExpr )?
AdditiveExpr | ::= | MultiplicativeExpr ( ( <Plus> | <Minus> ) MultiplicativeExpr )*
MultiplicativeExpr | ::= | UnaryExpr ( ( <Multiply> | <Div> | <Idiv> | <Mod> ) UnaryExpr )*
UnaryExpr | ::= | ( <Minus> | <Plus> )* UnionExpr
UnionExpr | ::= | IntersectExceptExpr ( ( <Union> | <Vbar> ) IntersectExceptExpr )*
IntersectExceptExpr | ::= | ValueExpr ( ( <Intersect> | <Except> ) ValueExpr )*
ValueExpr | ::= | ( ValidateExpr | CastExpr | TreatExpr | Constructor | PathExpr )
PathExpr | ::= | ( ( <Root> ( RelativePathExpr )? ) | ( <RootDescendants> RelativePathExpr ) | RelativePathExpr )
RelativePathExpr | ::= | StepExpr ( ( <Slash> | <SlashSlash> ) StepExpr )*
StepExpr | ::= | ( ForwardStep | ReverseStep | PrimaryExpr ) Predicates
ForClause | ::= | <ForVariable> <VarName> ( TypeDeclaration )? ( PositionalVar )? <In> Expr ( <Comma> ( <VariableIndicator> <VarName> ( TypeDeclaration )? ( PositionalVar )? ) <In> Expr )*
LetClause | ::= | <LetVariable> <VarName> ( TypeDeclaration )? <ColonEquals> Expr ( <Comma> ( <VariableIndicator> <VarName> ( TypeDeclaration )? ) <ColonEquals> Expr )*
WhereClause | ::= | <Where> Expr
PositionalVar | ::= | <AtWord> <VariableIndicator> <VarName>
ValidateExpr | ::= | ( <ValidateLbrace> | ( <ValidateContext> SchemaGlobalContext ( <Slash> SchemaContextStep )* <LbraceExprEnclosure> ) ) Expr <Rbrace>
CastExpr | ::= | ( <CastAs> SingleType ) ParenthesizedExpr
TreatExpr | ::= | ( <TreatAs> SequenceType ) ParenthesizedExpr
Constructor | ::= | ( ElementConstructor | XmlComment | XmlProcessingInstruction | CdataSection | ComputedDocumentConstructor | ComputedElementConstructor | ComputedAttributeConstructor | ComputedTextConstructor )
GeneralComp | ::= | ( <Equals> | <NotEquals> | <Lt> | <LtEquals> | <Gt> | <GtEquals> )
ValueComp | ::= | ( <FortranEq> | <FortranNe> | <FortranLt> | <FortranLe> | <FortranGt> | <FortranGe> )
NodeComp | ::= | ( <Is> | <IsNot> )
OrderComp | ::= | ( <LtLt> | <GtGt> )
OrderByClause | ::= | ( <OrderBy> | <OrderByStable> ) OrderSpecList
OrderSpecList | ::= | OrderSpec ( <Comma> OrderSpec )*
OrderSpec | ::= | Expr OrderModifier
OrderModifier | ::= | ( ( <Ascending> | <Descending> ) )? ( ( <EmptyGreatest> | <EmptyLeast> ) )? ( <Collation> <StringLiteral> )?
CaseClause | ::= | <Case> ( <VariableIndicator> <VarName> <As> )? SequenceType <Return> Expr
PrimaryExpr | ::= | ( Literal | FunctionCall | ( <VariableIndicator> <VarName> ) | ParenthesizedExpr )
ForwardAxis | ::= | ( <AxisChild> | <AxisDescendant> | <AxisAttribute> | <AxisSelf> | <AxisDescendantOrSelf> )
ReverseAxis | ::= | ( <AxisParent> )
NodeTest | ::= | ( KindTest | NameTest )
NameTest | ::= | ( <QName> | Wildcard )
Wildcard | ::= | ( <Star> | <NCNameColonStar> | <StarColonNCName> )
KindTest | ::= | ( ProcessingInstructionTest | CommentTest | TextTest | AnyKindTest )
ProcessingInstructionTest | ::= | <ProcessingInstructionLpar> ( <StringLiteral> )? <Rpar>
CommentTest | ::= | <CommentLpar> <Rpar>
TextTest | ::= | <TextLpar> <Rpar>
AnyKindTest | ::= | <NodeLpar> <Rpar>
ForwardStep | ::= | ( ( ForwardAxis ( NodeTest ) ) | AbbreviatedForwardStep )
ReverseStep | ::= | ( ( ReverseAxis ( NodeTest ) ) | AbbreviatedReverseStep )
AbbreviatedForwardStep | ::= | ( <Dot> | ( <At> NameTest ) | NodeTest )
AbbreviatedReverseStep | ::= | <DotDot>
Predicates | ::= | ( ( ( <Lbrack> Expr <Rbrack> ) ) )*
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
ParenthesizedExpr | ::= | <Lpar> ( ExprSequence )? <Rpar>
FunctionCall | ::= | <QNameLpar> ( Expr ( <Comma> Expr )* )? <Rpar>
Param | ::= | <VariableIndicator> <VarName> ( TypeDeclaration )?
SchemaContext | ::= | <InContext> SchemaGlobalContext ( <Slash> SchemaContextStep )*
SchemaGlobalContext | ::= | ( <QName> | <TypeQName> )
SchemaContextStep | ::= | <QName>
TypeDeclaration | ::= | <As> SequenceType
SingleType | ::= | AtomicType ( <QMark> )?
SequenceType | ::= | ( ( ItemType OccurrenceIndicator ) | <Empty> )
ItemType | ::= | ( ( ( <ElementType> | <AttributeType> ) ( ElemOrAttrType )? ) | <Node> | <ProcessingInstruction> | <Comment> | <Text> | ( <Document> ) | <Item> | AtomicType | <Untyped> | <AtomicValue> )
ElemOrAttrType | ::= | ( ( <QName> ( SchemaType | ( SchemaContext )? ) ) | SchemaType )
SchemaType | ::= | <OfType> <QName>
AtomicType | ::= | <QName>
OccurrenceIndicator | ::= | ( ( <Star> | <Multiply> | <Plus> | <QMark> ) )?
ElementConstructor | ::= | ( <StartTagOpenRoot> | <StartTagOpen> ) <TagQName> AttributeList ( <EmptyTagClose> | ( <StartTagClose> ( ElementContent )* <EndTagOpen> <TagQName> ( <S> )? <EndTagClose> ) )
ComputedDocumentConstructor | ::= | ( <DocumentLbrace> ExprSequence <Rbrace> )
ComputedElementConstructor | ::= | ( <ElementQNameLbrace> | ( <ElementLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( ExprSequence )? <Rbrace>
ComputedAttributeConstructor | ::= | ( <AttributeQNameLbrace> | ( <AttributeLbrace> Expr <Rbrace> <LbraceExprEnclosure> ) ) ( ExprSequence )? <Rbrace>
ComputedTextConstructor | ::= | <TextLbrace> ( ExprSequence )? <Rbrace>
CdataSection | ::= | <CdataSectionStart> ( <Char> )* <CdataSectionEnd>
XmlProcessingInstruction | ::= | <ProcessingInstructionStart> <PITarget> ( <Char> )* <ProcessingInstructionEnd>
XmlComment | ::= | <XmlCommentStart> ( <Char> )* <XmlCommentEnd>
ElementContent | ::= | ( <Char> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | ElementConstructor | EnclosedExpr | CdataSection | <CharRef> | <PredefinedEntityRef> | XmlComment | XmlProcessingInstruction )
AttributeList | ::= | ( <S> ( <TagQName> ( <S> )? <ValueIndicator> ( <S> )? AttributeValue )? )*
AttributeValue | ::= | ( ( <OpenQuot> ( ( <EscapeQuot> | AttributeValueContent ) )* <CloseQuot> ) | ( <OpenApos> ( ( <EscapeApos> | AttributeValueContent ) )* <CloseApos> ) )
AttributeValueContent | ::= | ( <Char> | <CharRef> | <LCurlyBraceEscape> | <RCurlyBraceEscape> | EnclosedExpr | <PredefinedEntityRef> )
EnclosedExpr | ::= | ( <Lbrace> | <LbraceExprEnclosure> ) ExprSequence <Rbrace>
XMLSpaceDecl | ::= | <DeclareXMLSpace> <XMLSpaceEquals> ( <XMLSpacePreserve> | <XMLSpaceStrip> )
DefaultCollationDecl | ::= | <DefaultCollationEquals> <URLLiteral>
NamespaceDecl | ::= | <DeclareNamespace> <NCNameForPrefix> <AssignEquals> <URLLiteral>
SubNamespaceDecl | ::= | <Namespace> <NCNameForPrefix> <AssignEquals> <URLLiteral>
DefaultNamespaceDecl | ::= | ( <DefaultElement> | <DefaultFunction> ) <Namespace> <AssignEquals> <URLLiteral>
FunctionDefn | ::= | <DefineFunction> <QNameLpar> ( ParamList )? ( <Rpar> | ( <RparAs> SequenceType ) ) EnclosedExpr
ParamList | ::= | Param ( <Comma> Param )*
SchemaImport | ::= | <ImportSchemaToken> ( <StringLiteral> | SubNamespaceDecl | DefaultNamespaceDecl ) ( <AtStringLiteral> )?