4 XPath 1.0 grammar. Should conform to the official spec at
5 http://www.w3.org/TR/1999/REC-xpath-19991116. The grammar
6 rules have been kept as close as possible to those in the
7 spec, but some adjustmewnts were unavoidable. These were
8 mainly removing left recursion (spec seems to be based on
9 LR), and to deal with the double nature of the '*' token
10 (node wildcard and multiplication operator). See also
11 section 3.7 in the spec. These rule changes should make
12 no difference to the strings accepted by the grammar.
14 Written by Jan-Willem van den Broek
17 Do with this code as you will.
20 Ported to Antlr4 by Tom Everett <tom@khubla.com>
28 : relativeLocationPath
29 | absoluteLocationPathNoroot
32 absoluteLocationPathNoroot
33 : '/' relativeLocationPath
34 | '//' relativeLocationPath
38 : step (('/'|'//') step)*
41 step : axisSpecifier nodeTest predicate*
52 | 'processing-instruction' '(' Literal ')'
76 : functionName '(' ( expr ( ',' expr )* )? ')'
80 : pathExprNoRoot ('|' unionExprNoRoot)?
81 | '/' '|' unionExprNoRoot
86 | filterExpr (('/'|'//') relativeLocationPath)?
90 : primaryExpr predicate*
93 orExpr : andExpr (OR andExpr)*
96 andExpr : equalityExpr (AND equalityExpr)*
100 : relationalExpr (('='|'!=') relationalExpr)*
104 : additiveExpr (('<'|'>'|'<='|'>=') additiveExpr)*
108 : multiplicativeExpr (('+'|'-') multiplicativeExpr)*
112 : unaryExprNoRoot (('*'|DIV|MOD) multiplicativeExpr)?
113 | '/' ((DIV|MOD) multiplicativeExpr)?
117 : '-'* unionExprNoRoot
120 qName : nCName (':' nCName)?
123 // Does not match NodeType, as per spec.
154 | 'processing-instruction'
158 Number : Digits ('.' Digits?)?
171 | 'descendant-or-self'
173 | 'following-sibling'
177 | 'preceding-sibling'
236 Literal : '"' ~'"'* '"'
241 : (' '|'\t'|'\n'|'\r')+ ->skip
244 NCName : NCNameStartChar NCNameChar*
263 // Unfortunately, java escapes can't handle this conveniently,
264 // as they're limited to 4 hex digits. TODO.
265 // | '\U010000'..'\U0EFFFF'
270 : NCNameStartChar | '-' | '.' | '0'..'9'
271 | '\u00B7' | '\u0300'..'\u036F'