4 package org.opendaylight.yangtools.yang.xpath.impl;
8 XPath 1.0 grammar. Should conform to the official spec at
9 http://www.w3.org/TR/1999/REC-xpath-19991116. The grammar
10 rules have been kept as close as possible to those in the
11 spec, but some adjustmewnts were unavoidable. These were
12 mainly removing left recursion (spec seems to be based on
13 LR), and to deal with the double nature of the '*' token
14 (node wildcard and multiplication operator). See also
15 section 3.7 in the spec. These rule changes should make
16 no difference to the strings accepted by the grammar.
18 Written by Jan-Willem van den Broek
21 Do with this code as you will.
24 Ported to Antlr4 by Tom Everett <tom@khubla.com>
32 : relativeLocationPath
33 | absoluteLocationPathNoroot
36 absoluteLocationPathNoroot
37 : '/' relativeLocationPath
38 | '//' relativeLocationPath
42 : step (('/'|'//') step)*
45 step : axisSpecifier nodeTest predicate*
56 | 'processing-instruction' '(' Literal ')'
80 : functionName '(' ( expr ( ',' expr )* )? ')'
84 : pathExprNoRoot ('|' unionExprNoRoot)?
85 | '/' '|' unionExprNoRoot
90 | filterExpr (('/'|'//') relativeLocationPath)?
94 : primaryExpr predicate*
97 orExpr : andExpr ('or' andExpr)*
100 andExpr : equalityExpr ('and' equalityExpr)*
104 : relationalExpr (('='|'!=') relationalExpr)*
108 : additiveExpr (('<'|'>'|'<='|'>=') additiveExpr)*
112 : multiplicativeExpr (('+'|'-') multiplicativeExpr)*
116 : unaryExprNoRoot (('*'|'div'|'mod') multiplicativeExpr)?
117 | '/' (('div'|'mod') multiplicativeExpr)?
121 : '-'* unionExprNoRoot
124 qName : nCName (':' nCName)?
127 // Does not match NodeType, as per spec.
150 | 'processing-instruction'
154 Number : Digits ('.' Digits?)?
167 | 'descendant-or-self'
169 | 'following-sibling'
173 | 'preceding-sibling'
223 Literal : '"' ~'"'* '"'
228 : (' '|'\t'|'\n'|'\r')+ ->skip
231 NCName : NCNameStartChar NCNameChar*
250 // Unfortunately, java escapes can't handle this conveniently,
251 // as they're limited to 4 hex digits. TODO.
252 // | '\U010000'..'\U0EFFFF'
257 : NCNameStartChar | '-' | '.' | '0'..'9'
258 | '\u00B7' | '\u0300'..'\u036F'