xee-xpath-ast 0.1.1

XPath parser and AST implementation
Documentation
/* XML Path Language (XPath) 3.1
 * version https://www.w3.org/TR/2017/REC-xpath-31-20170321/
 * extracted from https://www.w3.org/TR/xpath-31/ on Wed Mar 29, 2023, 13:17 (UTC+02)
 * using the tool at https://www.bottlecaps.de/rr/ui
 * How to use this tool to update:
 * - Go to the "Get Grammar" tab
 * - Fill in the URL of the XPath specification, https://www.w3.org/TR/2017/REC-xpath-31-20170321/
 * - Go to the "Edit Grammar" tab, select save
 * Do the same for the grammars included by URL.
 */

XPath    ::= Expr
ParamList
         ::= Param ("," Param)*
Param    ::= "$" EQName TypeDeclaration?
FunctionBody
         ::= EnclosedExpr
EnclosedExpr
         ::= "{" Expr? "}"
Expr     ::= ExprSingle ("," ExprSingle)*
ExprSingle
         ::= ForExpr
           | LetExpr
           | QuantifiedExpr
           | IfExpr
           | OrExpr
ForExpr  ::= SimpleForClause "return" ExprSingle
SimpleForClause
         ::= "for" SimpleForBinding ("," SimpleForBinding)*
SimpleForBinding
         ::= "$" VarName "in" ExprSingle
LetExpr  ::= SimpleLetClause "return" ExprSingle
SimpleLetClause
         ::= "let" SimpleLetBinding ("," SimpleLetBinding)*
SimpleLetBinding
         ::= "$" VarName ":=" ExprSingle
QuantifiedExpr
         ::= ("some" | "every") "$" VarName "in" ExprSingle ("," "$" VarName "in" ExprSingle)* "satisfies" ExprSingle
IfExpr   ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
OrExpr   ::= AndExpr ( "or" AndExpr )*
AndExpr  ::= ComparisonExpr ( "and" ComparisonExpr )*
ComparisonExpr
         ::= StringConcatExpr ( (ValueComp
           | GeneralComp
           | NodeComp) StringConcatExpr )?
StringConcatExpr
         ::= RangeExpr ( "||" RangeExpr )*
RangeExpr
         ::= AdditiveExpr ( "to" AdditiveExpr )?
AdditiveExpr
         ::= MultiplicativeExpr ( ("+" | "-") 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 ::= ArrowExpr ( "cast" "as" SingleType )?
ArrowExpr
         ::= UnaryExpr ( "=>" ArrowFunctionSpecifier ArgumentList )*
UnaryExpr
         ::= ("-" | "+")* ValueExpr
ValueExpr
         ::= SimpleMapExpr
GeneralComp
         ::= "=" | "!=" | "<" | "<=" | ">" | ">="
ValueComp
         ::= "eq" | "ne" | "lt" | "le" | "gt" | "ge"
NodeComp ::= "is" | "<<" | ">>"
SimpleMapExpr
         ::= PathExpr ("!" PathExpr)*
PathExpr ::= ("/" RelativePathExpr?)
           | ("//" RelativePathExpr)
           | RelativePathExpr
          /* xgc: leading-lone-slash */
RelativePathExpr
         ::= StepExpr (("/" | "//") StepExpr)*
StepExpr ::= PostfixExpr | 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 ::= EQName | Wildcard
Wildcard ::= "*"
           | (NCName ":*")
           | ("*:" NCName)
           | (BracedURILiteral "*")
          /* ws: explicit */
PostfixExpr
         ::= PrimaryExpr (Predicate | ArgumentList | Lookup)*
ArgumentList
         ::= "(" (Argument ("," Argument)*)? ")"
PredicateList
         ::= Predicate*
Predicate
         ::= "[" Expr "]"
Lookup   ::= "?" KeySpecifier
KeySpecifier
         ::= NCName | IntegerLiteral | ParenthesizedExpr | "*"
ArrowFunctionSpecifier
         ::= EQName | VarRef | ParenthesizedExpr
PrimaryExpr
         ::= Literal
           | VarRef
           | ParenthesizedExpr
           | ContextItemExpr
           | FunctionCall
           | FunctionItemExpr
           | MapConstructor
           | ArrayConstructor
           | UnaryLookup
Literal  ::= NumericLiteral | StringLiteral
NumericLiteral
         ::= IntegerLiteral | DecimalLiteral | DoubleLiteral
VarRef   ::= "$" VarName
VarName  ::= EQName
ParenthesizedExpr
         ::= "(" Expr? ")"
ContextItemExpr
         ::= "."
FunctionCall  
         ::= EQName ArgumentList
          /* xgc: reserved-function-names */
          /* gn: parens */
Argument ::= ExprSingle | ArgumentPlaceholder
ArgumentPlaceholder
         ::= "?"
FunctionItemExpr
         ::= NamedFunctionRef | InlineFunctionExpr
NamedFunctionRef
         ::= EQName "#" IntegerLiteral
          /* xgc: reserved-function-names */
InlineFunctionExpr
         ::= "function" "(" ParamList? ")" ("as" SequenceType)? FunctionBody
MapConstructor
         ::= "map" "{" (MapConstructorEntry ("," MapConstructorEntry)*)? "}"
MapConstructorEntry
         ::= MapKeyExpr ":" MapValueExpr
MapKeyExpr
         ::= ExprSingle
MapValueExpr
         ::= ExprSingle
ArrayConstructor
         ::= SquareArrayConstructor | CurlyArrayConstructor
SquareArrayConstructor
         ::= "[" (ExprSingle ("," ExprSingle)*)? "]"
CurlyArrayConstructor
         ::= "array" EnclosedExpr
UnaryLookup
         ::= "?" KeySpecifier
SingleType
         ::= SimpleTypeName "?"?
TypeDeclaration
         ::= "as" SequenceType
SequenceType
         ::= ("empty-sequence" "(" ")")
           | (ItemType OccurrenceIndicator?)
OccurrenceIndicator
         ::= "?" | "*" | "+"
          /* xgc: occurrence-indicators */
ItemType ::= KindTest | ("item" "(" ")") | FunctionTest | MapTest | ArrayTest | AtomicOrUnionType | ParenthesizedItemType
AtomicOrUnionType
         ::= EQName
KindTest ::= DocumentTest
           | ElementTest
           | AttributeTest
           | SchemaElementTest
           | SchemaAttributeTest
           | PITest
           | CommentTest
           | TextTest
           | NamespaceNodeTest
           | AnyKindTest
AnyKindTest
         ::= "node" "(" ")"
DocumentTest
         ::= "document-node" "(" (ElementTest | SchemaElementTest)? ")"
TextTest ::= "text" "(" ")"
CommentTest
         ::= "comment" "(" ")"
NamespaceNodeTest
         ::= "namespace-node" "(" ")"
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
         ::= EQName
ElementName
         ::= EQName
SimpleTypeName
         ::= TypeName
TypeName ::= EQName
FunctionTest
         ::= AnyFunctionTest
           | TypedFunctionTest
AnyFunctionTest
         ::= "function" "(" "*" ")"
TypedFunctionTest
         ::= "function" "(" (SequenceType ("," SequenceType)*)? ")" "as" SequenceType
MapTest  ::= AnyMapTest | TypedMapTest
AnyMapTest
         ::= "map" "(" "*" ")"
TypedMapTest
         ::= "map" "(" AtomicOrUnionType "," SequenceType ")"
ArrayTest
         ::= AnyArrayTest | TypedArrayTest
AnyArrayTest
         ::= "array" "(" "*" ")"
TypedArrayTest
         ::= "array" "(" SequenceType ")"
ParenthesizedItemType
         ::= "(" ItemType ")"
EQName   ::= QName | URIQualifiedName

<?TOKENS?>

IntegerLiteral
         ::= Digits
DecimalLiteral
         ::= ("." Digits) | (Digits "." [0-9]*)
          /* ws: explicit */
DoubleLiteral
         ::= (("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits
          /* ws: explicit */
StringLiteral
         ::= ('"' (EscapeQuot | [^"])* '"') | ("'" (EscapeApos | [^'])* "'")
          /* ws: explicit */
URIQualifiedName
         ::= BracedURILiteral NCName
          /* ws: explicit */
BracedURILiteral
         ::= "Q" "{" [^{}]* "}"
          /* ws: explicit */
EscapeQuot
         ::= '""'
EscapeApos
         ::= "''"
Comment  ::= "(:" (CommentContents | Comment)* ":)"
Char     ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
          /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */

Digits   ::= #'[0-9]+'
CommentContents
         ::= (Char+ - (Char* ('(:' | ':)') Char*))

/* Namespaces in XML 1.0 (Third Edition)
 * version http://www.w3.org/TR/2009/REC-xml-names-20091208/
 * extracted from https://www.w3.org/TR/REC-xml-names/#NT-QName on Wed Mar 29, 2023, 14:06 (UTC+02)
 */

NSAttName
         ::= PrefixedAttName
           | DefaultAttName
PrefixedAttName
         ::= 'xmlns:' NCName
          /* NSC: Reserved Prefixes and Namespace Names */
DefaultAttName
         ::= 'xmlns'
NCName   ::= Name - (Char* ':' Char*)
          /* An XML Name, minus the ":" */
QName    ::= PrefixedName
           | UnprefixedName
PrefixedName
         ::= Prefix ':' LocalPart
UnprefixedName
         ::= LocalPart
Prefix   ::= NCName
LocalPart
         ::= NCName
STag     ::= '<' QName (S Attribute)* S? '>'
          /* NSC: Prefix Declared */
ETag     ::= '</' QName S? '>'
          /* NSC: Prefix Declared */
EmptyElemTag
         ::= '<' QName (S Attribute)* S? '/>'
          /* NSC: Prefix Declared */
Attribute
         ::= NSAttName Eq AttValue
           | QName Eq AttValue
          /* NSC: Prefix Declared */
          /* NSC: No Prefix Undeclaring */
          /* NSC: Attributes Unique */
doctypedecl
         ::= '<!DOCTYPE' S QName (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
elementdecl
         ::= '<!ELEMENT' S QName S contentspec S? '>'
cp       ::= (QName | choice | seq) ('?' | '*' | '+')?
Mixed    ::= '(' S? '#PCDATA' (S? '|' S? QName)* S? ')*'
           | '(' S? '#PCDATA' S? ')'
AttlistDecl
         ::= '<!ATTLIST' S QName AttDef* S? '>'
AttDef   ::= S (QName | NSAttName) S AttType S DefaultDecl
NCNameChar
         ::= NameChar - ':' /* An XML NameChar, minus the ":" */
NCNameStartChar
         ::= NCName - ( Char Char Char* ) /* The first letter of an NCName */