# BNF for xpath-grammar.jj

## NON-TERMINALS

XPath2 | ::= | XPath <EOF>
XPath | ::= | Expr
Expr | ::= | ExprSingle ( "," ExprSingle )*
ExprSingle | ::= | ( ForExpr | QuantifiedExpr | IfExpr | OrExpr )
ForExpr | ::= | SimpleForClause "return" ExprSingle
SimpleForClause | ::= | "for" "$" VarName "in" ExprSingle ( "," "$" VarName "in" ExprSingle )*
QuantifiedExpr | ::= | ( "some" | "every" ) "$" VarName "in" ExprSingle ( "," "$" VarName "in" ExprSingle )* "satisfies" ExprSingle
IfExpr | ::= | "if" "(" Expr ")" "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 ( ( "*" | "div" | "idiv" | "mod" ) UnionExpr )*
UnionExpr | ::= | IntersectExceptExpr ( ( "union" | "|" ) IntersectExceptExpr )*
IntersectExceptExpr | ::= | InstanceofExpr ( ( "intersect" | "except" ) InstanceofExpr )*
InstanceofExpr | ::= | TreatExpr ( "instance" "of" SequenceType )?
TreatExpr | ::= | CastableExpr ( "treat" "as" SequenceType )?
CastableExpr | ::= | CastExpr ( "castable" "as" SingleType )?
CastExpr | ::= | UnaryExpr ( "cast" "as" SingleType )?
UnaryExpr | ::= | ( <Minus> | <Plus> )* ValueExpr
ValueExpr | ::= | PathExpr
GeneralComp | ::= | ( "=" | "!=" | <LessThanOpOrTagO> | "<=" | ">" | ">=" )
ValueComp | ::= | ( "eq" | "ne" | "lt" | "le" | "gt" | "ge" )
NodeComp | ::= | ( "is" | "<<" | ">>" )
PathExpr | ::= | ( ( <Slash> ( RelativePathExpr )? ) | ( <SlashSlash> RelativePathExpr ) | RelativePathExpr )
RelativePathExpr | ::= | StepExpr ( ( <Slash> | <SlashSlash> ) StepExpr )*
StepExpr | ::= | ( FilterExpr | AxisStep )
AxisStep | ::= | ( ReverseStep | ForwardStep ) PredicateList
ForwardStep | ::= | ( ( ForwardAxis NodeTest ) | AbbrevForwardStep )
ForwardAxis | ::= | ( ( "child" "::" ) | ( "descendant" "::" ) | ( "attribute" "::" ) | ( "self" "::" ) | ( "descendant-or-self" "::" ) | ( "following-sibling" "::" ) | ( "following" "::" ) | ( "namespace" "::" ) )
AbbrevForwardStep | ::= | ( "@" )? NodeTest
ReverseStep | ::= | ( ( ReverseAxis NodeTest ) | AbbrevReverseStep )
ReverseAxis | ::= | ( ( "parent" "::" ) | ( "ancestor" "::" ) | ( "preceding-sibling" "::" ) | ( "preceding" "::" ) | ( "ancestor-or-self" "::" ) )
AbbrevReverseStep | ::= | ".."
NodeTest | ::= | ( KindTest | NameTest )
NameTest | ::= | ( QName | Wildcard )
Wildcard | ::= | ( "*" | <NCNameColonStar> | <StarColonNCName> )
FilterExpr | ::= | PrimaryExpr PredicateList
PredicateList | ::= | ( Predicate )*
Predicate | ::= | "[" Expr "]"
PrimaryExpr | ::= | ( Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall )
Literal | ::= | ( NumericLiteral | <StringLiteral> )
NumericLiteral | ::= | ( <IntegerLiteral> | <DecimalLiteral> | <DoubleLiteral> )
VarRef | ::= | "$" VarName
VarName | ::= | QName
ParenthesizedExpr | ::= | "(" ( Expr )? ")"
ContextItemExpr | ::= | "."
FunctionCall | ::= | FunctionQName "(" ( ExprSingle ( "," ExprSingle )* )? ")"
SingleType | ::= | AtomicType ( "?" )?
SequenceType | ::= | ( ( "empty-sequence" "(" ")" ) | ( ItemType ( OccurrenceIndicator )? ) )
OccurrenceIndicator | ::= | ( "?" | "*" | <Plus> )
ItemType | ::= | ( KindTest | ( "item" "(" ")" ) | AtomicType )
AtomicType | ::= | QName
KindTest | ::= | ( DocumentTest | ElementTest | AttributeTest | SchemaElementTest | SchemaAttributeTest | PITest | CommentTest | TextTest | AnyKindTest )
AnyKindTest | ::= | "node" "(" ")"
DocumentTest | ::= | "document-node" "(" ( ( ElementTest | SchemaElementTest ) )? ")"
TextTest | ::= | "text" "(" ")"
CommentTest | ::= | "comment" "(" ")"
PITest | ::= | "processing-instruction" "(" ( ( NCName | <StringLiteral> ) )? ")"
AttributeTest | ::= | "attribute" "(" ( ( AttribNameOrWildcard ( "," TypeName )? ) )? ")"
AttribNameOrWildcard | ::= | ( AttributeName | "*" )
SchemaAttributeTest | ::= | "schema-attribute" "(" AttributeDeclaration ")"
AttributeDeclaration | ::= | AttributeName
ElementTest | ::= | "element" "(" ( ( ElementNameOrWildcard ( "," TypeName ( "?" )? )? ) )? ")"
ElementNameOrWildcard | ::= | ( ElementName | "*" )
SchemaElementTest | ::= | "schema-element" "(" ElementDeclaration ")"
ElementDeclaration | ::= | ElementName
AttributeName | ::= | QName
ElementName | ::= | QName
TypeName | ::= | QName
Pattern | ::= | PathPattern ( ( "union" | "|" ) Pattern )?
PathPattern | ::= | ( ( <Slash> ( RelativePathPattern )? ) | ( <SlashSlash> RelativePathPattern ) | RelativePathPattern )
RelativePathPattern | ::= | PatternStep ( ( <Slash> | <SlashSlash> ) RelativePathPattern )?
PatternStep | ::= | ( PatternAxis )? NodeTest PredicateList
PatternAxis | ::= | ( ( "child" "::" ) | ( "attribute" "::" ) | "@" )
NCName | ::= | QName
QName | ::= | ( FunctionQName | "attribute" | "comment" | "document-node" | "element" | "if" | "item" | "node" | "processing-instruction" | "schema-attribute" | "schema-element" | "text" | "empty-sequence" )
FunctionQName | ::= | ( <QNameToken> | <External> | "return" | "for" | "in" | "some" | "every" | "satisfies" | "then" | "else" | "or" | "and" | "to" | "div" | "idiv" | "mod" | "union" | "intersect" | "except" | "instance" | "of" | "treat" | "castable" | "cast" | "eq" | "ne" | "lt" | "le" | "gt" | "ge" | "is" | "child" | "descendant" | "self" | "descendant-or-self" | "following-sibling" | "following" | "parent" | "ancestor" | "preceding-sibling" | "preceding" | "ancestor-or-self" | "type" )