| START | ::= | Pattern <EOF> |
| Pattern | ::= | PathPattern ( "|" Pattern )? |
| PathPattern | ::= | ( ( <Slash> ( RelativePathPattern )? ) | ( <SlashSlash> RelativePathPattern ) | ( IdKeyPattern ( ( <Slash> | <SlashSlash> ) RelativePathPattern )? ) | RelativePathPattern ) |
| RelativePathPattern | ::= | PatternStep ( ( <Slash> | <SlashSlash> ) RelativePathPattern )? |
| PatternStep | ::= | ( PatternAxis )? NodeTest PredicateList |
| PatternAxis | ::= | ( ( "child" "::" ) | ( "attribute" "::" ) | "@" ) |
| IdKeyPattern | ::= | ( ( "id" "(" IdValue ")" ) | ( "key" "(" <StringLiteral> "," KeyValue ")" ) ) |
| IdValue | ::= | ( <StringLiteral> | VarRef ) |
| KeyValue | ::= | ( Literal | VarRef ) |
| 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 | ::= | ( "=" | "!=" | <LeftAngleBracket> | "<=" | ">" | ">=" ) |
| 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 |
| NCName | ::= | QName |
| QName | ::= | ( FunctionQName | "attribute" | "comment" | "document-node" | "element" | "empty-sequence" | "if" | "item" | "node" | "processing-instruction" | "schema-attribute" | "schema-element" | "text" ) |
| FunctionQName | ::= | ( <QNameToken> | "ancestor" | "ancestor-or-self" | "and" | "as" | "cast" | "castable" | "child" | "descendant" | "descendant-or-self" | "div" | "else" | "eq" | "every" | "except" | "following" | "following-sibling" | "for" | "ge" | "gt" | "id" | "idiv" | "in" | "instance" | "intersect" | "is" | "key" | "le" | "lt" | "mod" | "namespace" | "ne" | "of" | "or" | "parent" | "preceding" | "preceding-sibling" | "return" | "satisfies" | "self" | "some" | "then" | "to" | "treat" | "union" ) |