# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | XPath <EOF>
MatchPattern | ::= | Pattern <EOF>
XPath | ::= | Expr
Expr | ::= | ExprSingle ( <Comma> ExprSingle )*
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 | ::= | 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 | ::= | ( PathExpr )
GeneralComp | ::= | ( <Equals> | <NotEquals> | <Lt> | <LtEquals> | <Gt> | <GtEquals> )
ValueComp | ::= | ( <FortranEq> | <FortranNe> | <FortranLt> | <FortranLe> | <FortranGt> | <FortranGe> )
NodeComp | ::= | ( <Is> | <LtLt> | <GtGt> )
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> | <AxisNamespace> )
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 )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
VarRef | ::= | <VariableIndicator> <VarName>
ParenthesizedExpr | ::= | <Lpar> ( Expr )? <Rpar>
ContextItemExpr | ::= | <Dot>
FunctionCall | ::= | ( <QNameLpar> ) ( ExprSingle ( <Comma> ExprSingle )* )? <Rpar>
SingleType | ::= | AtomicType ( <OccurrenceZeroOrOne> )?
SequenceType | ::= | ( ( ItemType ( OccurrenceIndicator )? ) | <VoidTok> )
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>
Pattern | ::= | PathPattern ( ( <Union> | <Vbar> ) Pattern )?
PathPattern | ::= | ( ( <Root> ( RelativePathPattern )? ) | ( <RootDescendants> RelativePathPattern ) | ( ( ( <Slash> | <SlashSlash> ) RelativePathPattern )? ) | RelativePathPattern )
RelativePathPattern | ::= | PatternStep ( ( <Slash> | <SlashSlash> ) RelativePathPattern )?
PatternStep | ::= | ( PatternAxis )? NodeTest PredicateList
PatternAxis | ::= | ( <AxisChild> | <AxisAttribute> | <At> )