# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | XPath <EOF>
MatchPattern | ::= | Pattern <EOF>
XPath | ::= | ( Expr )?
Expr | ::= | ExprSingle ( <Comma> ExprSingle )*
Pattern | ::= | PathPattern ( ( <Union> | <Vbar> ) Pattern )?
PathPattern | ::= | ( ( <Root> ( RelativePathPattern )? ) | ( <RootDescendants> RelativePathPattern ) | ( IdKeyPattern ( ( <Slash> | <SlashSlash> ) RelativePathPattern )? ) | RelativePathPattern )
RelativePathPattern | ::= | PatternStep ( ( <Slash> | <SlashSlash> ) RelativePathPattern )?
PatternStep | ::= | ( PatternAxis )? NodeTest Predicates
PatternAxis | ::= | ( <AxisChild> | <AxisAttribute> | <At> )
IdKeyPattern | ::= | ( ( <IDLpar> IdKeyValue <Rpar> ) | ( <KeyLpar> <StringLiteral> <Comma> IdKeyValue <Rpar> ) )
IdKeyValue | ::= | ( <StringLiteral> | ( <VariableIndicator> <VarName> ) )
ExprSingle | ::= | ( ForExpr | QuantifiedExpr | IfExpr | OrExpr )
ForExpr | ::= | ( SimpleForClause <Return> ExprSingle )
SimpleForClause | ::= | <ForVariable> <VarName> <In> ExprSingle ( <Comma> ( <VariableIndicator> <VarName> ) <In> ExprSingle )*
QuantifiedExpr | ::= | ( ( <Some> | <Every> ) <VarName> <In> ExprSingle ( <Comma> ( <VariableIndicator> <VarName> ) <In> ExprSingle )* <Satisfies> 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 | ::= | ( 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 )
VarRef | ::= | <VariableIndicator> <VarName>
Predicates | ::= | ( ( ( <Lbrack> Expr <Rbrack> ) ) )*
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> | <AxisNamespace> )
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> | <IDLpar> | <KeyLpar> ) ( ExprSingle ( <Comma> ExprSingle )* )? <Rpar>
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> )*
OccurrenceIndicator | ::= | ( <OccurrenceZeroOrOne> | <OccurrenceZeroOrMore> | <OccurrenceOneOrMore> )