some more example xpath 2.0 expressions
[xpath20.git] / cc / xpath.sablecc
blobd305062bf3b0b111ab4601f4a807392f69123f85
1 Package com.interrupt.cc.xpath; \r
2 \r
3  /* \r
4  author: Timothy Washington\r
5  email twashing [at] gmail.com\r
6  \r
7  license: \r
8         Copyright (c) 2008, Tim Washington\r
9         All rights reserved.\r
10         \r
11         Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r
12         \r
13             * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r
14             * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r
15             * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\r
16         \r
17         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
19  \r
20  -----------\r
21  declare namespace xq='http://xmlbeans.apache.org/samples/xquery/employees'; \r
22  $this/xq:employees/xq:employee/xq:phone[contains(., '(206)')]\r
24  ./child::node()[1]/attribute::name\r
25          *) Find value of the name attribute of the first element in the XMl document \r
26          1) The first section is only a dot (.). A dot at the start of a query means you want to start your search from the beginning of the XMl document.\r
27          2) The second section (child::node()[1]) says: Find the first child element node. The combined effect of the first and second portions (./child::node()[1]) is like saying: Find the first element of this XMl document.\r
28          3) The third section (attribute::name) says: Find the value of an attribute name. The combined effect of the query is like saying: .\r
30  ./child::node()[1]/child::service/child::port/child::soap:address/attribute::location\r
31          *) Find the first child node of the XMl document, then find a service child element within the first child, then find a port element inside the service element, then look inside the port element for an address element that belongs to the sOAP namespace and return the value of its location attribute. \r
33 -----------\r
36 --> Expression tests\r
37 //system/bookkeeping\r
38 /system/bookkeeping\r
39 system/bookkeeping\r
40 ./child::node()\r
43 --> forward axis \r
44 descendant::node() \r
45 attribute::attribute() \r
46 ./self::element() \r
47 /descendant-or-self::element() \r
48 //following-sibling::node() \r
49 following::element() \r
50 namespace::node() \r
53 --> reverse axis \r
54 parent::node() \r
55 ancestor::node() \r
56 preceding-sibling::node() \r
57 preceding::node() \r
58 ancestor-or-self::node() \r
61 --> predicates \r
62 ./child::node()[ @asdf='' ]\r
63 ./child::node()/child::service/child::port/child::soap:address/attribute::location\r
64 ./child::node()[]/child::service/child::port/child::soap:address/attribute::location\r
65 [x] ./child::node()[ @name='tim' ]              Error: [1,24] Unknown token: 't\r
66 [x] ./child::node()[ 1 ]                                Error: [1,18] expecting: 'for', 'if', 'some', 'every', ',', '$', '(', ']', '+', '-', '*', '/', '//', '@', '..', '.', 'child', 'descendant', 'attribute', 'self', 'descendant-or-self', 'following-sibling', 'following', 'namespace', 'parent', 'ancestor', 'preceding-sibling', 'preceding', 'ancestor-or-self', 'comment', 'document-node', 'element', 'node', 'processing-instruction', 'schema-attribute', 'schema-element', 'text', letter, '_', integerliteral, decimalliteral, doubleliteral, stringliteral\r
67 [x] ./child::node()[ 1 ]/child::service/child::port/child::soap:address/attribute::location\r
68 /GPS/memory[text()=""]\r
69 [x] /GPS/memory[text()="64MB"]\r
72 --> for \r
73 [x] for $i in (10, 20), $j in (1, 2) \r
74                 return ( $i + $j )              Error: [1,6] expecting: letter, '_'\r
75 [x] for $x in $z, $y in f($x) \r
76                 return g($x, $y)                Error: [1,6] expecting: letter, '_' \r
77 [x] for $a in fn:distinct-values(book/author)\r
78                 return (book/author[. = $a][1], book[author = $a]/title)\r
81 --> if / then / else \r
82 [x] if ($widget1/unit-cost < $widget2/unit-cost) \r
83                 then $widget1 \r
84                 else $widget2                   Error: [1,18] expecting: ',', ')'\r
87 --> or / and \r
88 [x] 1 eq 1 and 2 eq 2 \r
89 [x] 1 eq 2 and 3 idiv 0 = 1\r
90 [x] 1 eq 1 or 3 idiv 0 = 1              Error: [1,1] expecting: EOF\r
93 --> cast / castable \r
94 [x] if ($x castable as hatsize)         \r
95                 then $x cast as hatsize Error: [1,6] expecting: letter, '_'\r
98 --> some / every \r
99 every $part in /parts/part satisfies $part/@discounted\r
100 [x] every $xart in (1, 2, 3), $yart in (2, 3, 4) \r
101         satisfies $xart + $yart = 4\r
102 [x] some $xart in (1, 2, "cat") satisfies $x * 2 = 4            Error: [1,7] expecting: letter, '_'\r
105 --> intersect / except \r
106 $seq1 intersect $seq2\r
107 $seq1 except $seq2\r
110 --> instanceof \r
111 [x] $p instance of xs:decimal                   Error: [1,2] expecting: letter, '_'\r
112 [x] 5  instance of xs:integer                   Error: [1,1] expecting: EOF\r
113 [x] (5, 6) instance of xs:integer+              Error: [1,2] expecting: 'for', 'if', 'some', 'every', ',', '$', '(', ')', '+', '-', '*', '/', '//', '@', '..', '.', 'child', 'descendant', 'attribute', 'self', 'descendant-or-self', 'following-sibling', 'following', 'namespace', 'parent', 'ancestor', 'preceding-sibling', 'preceding', 'ancestor-or-self', 'comment', 'document-node', 'element', 'node', 'processing-instruction', 'schema-attribute', 'schema-element', 'text', letter, '_', integerliteral, decimalliteral, doubleliteral, stringliteral\r
116 --> treat \r
117 $myaddress treat as element(*, USAddress)\r
120 */ \r
121  \r
122  /** \r
123   * KNOWN ISSUES \r
124   * \r
125   * - with defining differences (ex: ncname) \r
126   * \r
127   */ \r
129 Helpers\r
131         basechar        =       [0x0041..0x005A] | [0x0061..0x007A] | [0x00C0..0x00D6] | \r
132                                         [0x00D8..0x00F6] | [0x00F8..0x00FF] | [0x0100..0x0131] | \r
133                                         [0x0134..0x013E] | [0x0141..0x0148] | [0x014A..0x017E] | \r
134                                         [0x0180..0x01C3] | [0x01CD..0x01F0] | [0x01F4..0x01F5] | \r
135                                         [0x01FA..0x0217] | [0x0250..0x02A8] | [0x02BB..0x02C1] | \r
136                                         0x0386 | [0x0388..0x038A] | 0x038C | [0x038E..0x03A1] | \r
137                                         [0x03A3..0x03CE] | [0x03D0..0x03D6] | 0x03DA | 0x03DC | \r
138                                         0x03DE | 0x03E0 | [0x03E2..0x03F3] | [0x0401..0x040C] | \r
139                                         [0x040E..0x044F] | [0x0451..0x045C] | [0x045E..0x0481] | \r
140                                         [0x0490..0x04C4] | [0x04C7..0x04C8] | [0x04CB..0x04CC] | \r
141                                         [0x04D0..0x04EB] | [0x04EE..0x04F5] | [0x04F8..0x04F9] | \r
142                                         [0x0531..0x0556] | 0x0559 | [0x0561..0x0586] | [0x05D0..0x05EA] | \r
143                                         [0x05F0..0x05F2] | [0x0621..0x063A] | [0x0641..0x064A] | \r
144                                         [0x0671..0x06B7] | [0x06BA..0x06BE] | [0x06C0..0x06CE] | \r
145                                         [0x06D0..0x06D3] | 0x06D5 | [0x06E5..0x06E6] | [0x0905..0x0939] | \r
146                                         0x093D | [0x0958..0x0961] | [0x0985..0x098C] | [0x098F..0x0990] | \r
147                                         [0x0993..0x09A8] | [0x09AA..0x09B0] | 0x09B2 | [0x09B6..0x09B9] | \r
148                                         [0x09DC..0x09DD] | [0x09DF..0x09E1] | [0x09F0..0x09F1] | \r
149                                         [0x0A05..0x0A0A] | [0x0A0F..0x0A10] | [0x0A13..0x0A28] | \r
150                                         [0x0A2A..0x0A30] | [0x0A32..0x0A33] | [0x0A35..0x0A36] | \r
151                                         [0x0A38..0x0A39] | [0x0A59..0x0A5C] | 0x0A5E | [0x0A72..0x0A74] | \r
152                                         [0x0A85..0x0A8B] | 0x0A8D | [0x0A8F..0x0A91] | [0x0A93..0x0AA8] | \r
153                                         [0x0AAA..0x0AB0] | [0x0AB2..0x0AB3] | [0x0AB5..0x0AB9] | \r
154                                         0x0ABD | 0x0AE0 | [0x0B05..0x0B0C] | [0x0B0F..0x0B10] | \r
155                                         [0x0B13..0x0B28] | [0x0B2A..0x0B30] | [0x0B32..0x0B33] | \r
156                                         [0x0B36..0x0B39] | 0x0B3D | [0x0B5C..0x0B5D] | [0x0B5F..0x0B61] | \r
157                                         [0x0B85..0x0B8A] | [0x0B8E..0x0B90] | [0x0B92..0x0B95] | \r
158                                         [0x0B99..0x0B9A] | 0x0B9C | [0x0B9E..0x0B9F] | [0x0BA3..0x0BA4] | \r
159                                         [0x0BA8..0x0BAA] | [0x0BAE..0x0BB5] | [0x0BB7..0x0BB9] | \r
160                                         [0x0C05..0x0C0C] | [0x0C0E..0x0C10] | [0x0C12..0x0C28] | \r
161                                         [0x0C2A..0x0C33] | [0x0C35..0x0C39] | [0x0C60..0x0C61] | \r
162                                         [0x0C85..0x0C8C] | [0x0C8E..0x0C90] | [0x0C92..0x0CA8] | \r
163                                         [0x0CAA..0x0CB3] | [0x0CB5..0x0CB9] | 0x0CDE | [0x0CE0..0x0CE1] | \r
164                                         [0x0D05..0x0D0C] | [0x0D0E..0x0D10] | [0x0D12..0x0D28] | \r
165                                         [0x0D2A..0x0D39] | [0x0D60..0x0D61] | [0x0E01..0x0E2E] | 0x0E30 | \r
166                                         [0x0E32..0x0E33] | [0x0E40..0x0E45] | [0x0E81..0x0E82] | 0x0E84 | \r
167                                         [0x0E87..0x0E88] | 0x0E8A | 0x0E8D | [0x0E94..0x0E97] | \r
168                                         [0x0E99..0x0E9F] | [0x0EA1..0x0EA3] | 0x0EA5 | 0x0EA7 | \r
169                                         [0x0EAA..0x0EAB] | [0x0EAD..0x0EAE] | 0x0EB0 | [0x0EB2..0x0EB3] | \r
170                                         0x0EBD | [0x0EC0..0x0EC4] | [0x0F40..0x0F47] | [0x0F49..0x0F69] | \r
171                                         [0x10A0..0x10C5] | [0x10D0..0x10F6] | 0x1100 | [0x1102..0x1103] | \r
172                                         [0x1105..0x1107] | 0x1109 | [0x110B..0x110C] | [0x110E..0x1112] | \r
173                                         0x113C | 0x113E | 0x1140 | 0x114C | 0x114E | 0x1150 | \r
174                                         [0x1154..0x1155] | 0x1159 | [0x115F..0x1161] | 0x1163 | \r
175                                         0x1165 | 0x1167 | 0x1169 | [0x116D..0x116E] | [0x1172..0x1173] | \r
176                                         0x1175 | 0x119E | 0x11A8 | 0x11AB | [0x11AE..0x11AF] | \r
177                                         [0x11B7..0x11B8] | 0x11BA | [0x11BC..0x11C2] | 0x11EB | \r
178                                         0x11F0 | 0x11F9 | [0x1E00..0x1E9B] | [0x1EA0..0x1EF9] | \r
179                                         [0x1F00..0x1F15] | [0x1F18..0x1F1D] | [0x1F20..0x1F45] | \r
180                                         [0x1F48..0x1F4D] | [0x1F50..0x1F57] | 0x1F59 | 0x1F5B | \r
181                                         0x1F5D | [0x1F5F..0x1F7D] | [0x1F80..0x1FB4] | [0x1FB6..0x1FBC] | \r
182                                         0x1FBE | [0x1FC2..0x1FC4] | [0x1FC6..0x1FCC] | [0x1FD0..0x1FD3] | \r
183                                         [0x1FD6..0x1FDB] | [0x1FE0..0x1FEC] | [0x1FF2..0x1FF4] | \r
184                                         [0x1FF6..0x1FFC] | 0x2126 | [0x212A..0x212B] | 0x212E | \r
185                                         [0x2180..0x2182] | [0x3041..0x3094] | [0x30A1..0x30FA] | \r
186                                         [0x3105..0x312C] | [0xAC00..0xD7A3]; \r
187         \r
188         ideographic             =       [0x4E00..0x9FA5] | 0x3007 | [0x3021..0x3029]; \r
189         \r
190         \r
191         combiningchar   =       [0x0300..0x0345] | [0x0360..0x0361] | [0x0483..0x0486] | \r
192                                                 [0x0591..0x05A1] | [0x05A3..0x05B9] | [0x05BB..0x05BD] | \r
193                                                 0x05BF | [0x05C1..0x05C2] | 0x05C4 | [0x064B..0x0652] | \r
194                                                 0x0670 | [0x06D6..0x06DC] | [0x06DD..0x06DF] | [0x06E0..0x06E4] | \r
195                                                 [0x06E7..0x06E8] | [0x06EA..0x06ED] | [0x0901..0x0903] | \r
196                                                 0x093C | [0x093E..0x094C] | 0x094D | [0x0951..0x0954] | \r
197                                                 [0x0962..0x0963] | [0x0981..0x0983] | 0x09BC | 0x09BE | \r
198                                                 0x09BF | [0x09C0..0x09C4] | [0x09C7..0x09C8] | [0x09CB..0x09CD] | \r
199                                                 0x09D7 | [0x09E2..0x09E3] | 0x0A02 | 0x0A3C | 0x0A3E | \r
200                                                 0x0A3F | [0x0A40..0x0A42] | [0x0A47..0x0A48] | [0x0A4B..0x0A4D] | \r
201                                                 [0x0A70..0x0A71] | [0x0A81..0x0A83] | 0x0ABC | [0x0ABE..0x0AC5] | \r
202                                                 [0x0AC7..0x0AC9] | [0x0ACB..0x0ACD] | [0x0B01..0x0B03] | \r
203                                                 0x0B3C | [0x0B3E..0x0B43] | [0x0B47..0x0B48] | [0x0B4B..0x0B4D] | \r
204                                                 [0x0B56..0x0B57] | [0x0B82..0x0B83] | [0x0BBE..0x0BC2] | \r
205                                                 [0x0BC6..0x0BC8] | [0x0BCA..0x0BCD] | 0x0BD7 | [0x0C01..0x0C03] | \r
206                                                 [0x0C3E..0x0C44] | [0x0C46..0x0C48] | [0x0C4A..0x0C4D] | \r
207                                                 [0x0C55..0x0C56] | [0x0C82..0x0C83] | [0x0CBE..0x0CC4] | \r
208                                                 [0x0CC6..0x0CC8] | [0x0CCA..0x0CCD] | [0x0CD5..0x0CD6] | \r
209                                                 [0x0D02..0x0D03] | [0x0D3E..0x0D43] | [0x0D46..0x0D48] | \r
210                                                 [0x0D4A..0x0D4D] | 0x0D57 | 0x0E31 | [0x0E34..0x0E3A] | \r
211                                                 [0x0E47..0x0E4E] | 0x0EB1 | [0x0EB4..0x0EB9] | [0x0EBB..0x0EBC] | \r
212                                                 [0x0EC8..0x0ECD] | [0x0F18..0x0F19] | 0x0F35 | 0x0F37 | \r
213                                                 0x0F39 | 0x0F3E | 0x0F3F | [0x0F71..0x0F84] | [0x0F86..0x0F8B] | \r
214                                                 [0x0F90..0x0F95] | 0x0F97 | [0x0F99..0x0FAD] | [0x0FB1..0x0FB7] | \r
215                                                 0x0FB9 | [0x20D0..0x20DC] | 0x20E1 | [0x302A..0x302F] | \r
216                                                 0x3099 | 0x309A; \r
217         \r
218         digit   =       [0x0030..0x0039] | [0x0660..0x0669] | [0x06F0..0x06F9] | \r
219                                 [0x0966..0x096F] | [0x09E6..0x09EF] | [0x0A66..0x0A6F] | \r
220                                 [0x0AE6..0x0AEF] | [0x0B66..0x0B6F] | [0x0BE7..0x0BEF] | \r
221                                 [0x0C66..0x0C6F] | [0x0CE6..0x0CEF] | [0x0D66..0x0D6F] | \r
222                                 [0x0E50..0x0E59] | [0x0ED0..0x0ED9] | [0x0F20..0x0F29]; \r
223         \r
224         extender        =       0x00B7 | 0x02D0 | 0x02D1 | 0x0387 | 0x0640 | 0x0E46 | \r
225                                         0x0EC6 | 0x3005 | [0x3031..0x3035] | [0x309D..0x309E] | \r
226                                         [0x30FC..0x30FE]; \r
227         \r
228         \r
229         /** \r
230          * XML names and characters taken (for reference) from these sources \r
231          * \r
232          * http://www.w3.org/TR/REC-xml-names/#NT-QName\r
233          * http://www.w3.org/TR/REC-xml-names/#NT-NCName \r
234          * http://www.w3.org/TR/REC-xml/#NT-NameChar \r
235          * http://www.w3.org/TR/REC-xml/#NT-Letter \r
236          */ \r
237         \r
238         /*letter_helper    =    basechar | \r
239                                                         ideographic; \r
240         */\r
241         letter_helper      =    basechar; \r
242         \r
243         namechar        =       letter_helper | digit | '.' | '-' | '_' | ':' | combiningchar | extender; \r
244         name            =   (letter_helper | '_' | ':') (namechar)*; \r
245         names           =   name (0x20 name)*; \r
246         nmtoken         =   (namechar)+; \r
247         nmtokens        =   nmtoken (0x20 nmtoken)*; \r
248         char = 0x9 | 0xA | 0xD | [0x20-0xD7FF] | [0xE000-0xFFFD] | [0x10000-0x10FFFF]; \r
249         digits     =            [0-9]+; \r
250         \r
251         escapequot         =            '""'; \r
252         \r
253         doubleliteral_helper    =   (('.' digits) | \r
254                                                                 (digits ('.' [0-9]*)?)) ('e' | 'E') ('+' | '-')? digits; \r
255         stringliteral_helper    =   ( 0x22 (escapequot)* 0x22 ) | \r
256                                                                 (''' ('''''')* '''); \r
257         \r
258         //doubleliteral_helper  =   (('.' digits) | \r
259         //                                                      (digits ('.' [0-9]*)?)) ('e' | 'E') ('+' | '-')? digits; \r
260         //stringliteral_helper  =   ( 0x22 (escapequot | [char - 0x22])* 0x22 ) | \r
261         //                                                      (''' ('''''' | [char - '''])* '''); \r
262         \r
263         //escapeapos       =            ''''; \r
264         //comment          =            '(:' (commentcontents | comment)* ':)'; \r
265         //commentcontents          =            [char+ - (char* ('(:' | ':)') char*)]; \r
266         \r
267         tab = 9;\r
268         cr = 13;\r
269         lf = 10;\r
270         eol = cr lf | cr | lf;  // This takes care of different platforms               \r
271         \r
272         \r
273 Tokens\r
274         \r
275         keyword_return =        'return';\r
276         keyword_for =           'for';\r
277         keyword_in =            'in';\r
278         keyword_if =            'if';\r
279         keyword_is =            'is'; \r
280         keyword_satisfies = 'satisfies';\r
281         keyword_then =          'then';\r
282         keyword_else =          'else';\r
283         keyword_or =            'or';\r
284         keyword_and =           'and';\r
285         keyword_to =            'to';   \r
286         keyword_div =           'div';\r
287         keyword_idiv =          'idiv';\r
288         keyword_mod =           'mod';\r
289         keyword_union =         'union';\r
290         keyword_intersect = 'intersect';\r
291         keyword_except =        'except';\r
292         keyword_instance =      'instance';\r
293         keyword_of =            'of';\r
294         keyword_treat =         'treat';\r
295         keyword_as =            'as';\r
296         keyword_castable =      'castable';\r
297         keyword_cast =          'cast';\r
298         keyword_some =          'some';\r
299         keyword_every =         'every'; \r
300         \r
301         comma =         ',';\r
302         dollar =        '$';\r
303         question =      '?';\r
304         \r
305         lparenth =      '(';\r
306         rparenth =      ')';\r
307         lbracket =      '[';\r
308         rbracket =      ']';\r
309         plus =          '+';\r
310         plus2 =         '+';\r
311         minus =         '-';\r
312         minus2 =        '-';\r
313         star =          '*';\r
314         star2 =         '*';\r
315         union =         '|';\r
316         equals =        '=';\r
317         \r
318         ne_abbrev =     '!=';\r
319         lt_abbrev =     '<';\r
320         le_abbrev =     '<=';\r
321         gt_abbrev =     '>';\r
322         ge_abbrev =     '>=';\r
323         eq =                    'eq';\r
324         ne =                    'ne';\r
325         lt =                            'lt';\r
326         le =                            'le';\r
327         gt =                            'gt';\r
328         ge =                            'ge';\r
329         is =                            'is';\r
330         ncomp_precedes =        '<<';\r
331         ncomp_follows =         '>>';\r
332         axis_delim =            '::';\r
333         colon =                 ':';\r
334         \r
335         abbrev_root =           '/';\r
336         abbrev_root_desc =      '//';\r
337         abbrev_attrib =                 '@';\r
338         abbrev_reversestep =    '..';\r
339         abbrev_context =                '.';\r
340         \r
341         \r
342         /**\r
343          * Axes \r
344          */\r
345         \r
346         //forward axis\r
347         axis_child = 'child';\r
348         axis_descendant = 'descendant'; \r
349         axis_attribute = 'attribute'; \r
350         axis_self = 'self'; \r
351         axis_descendant_or_self = 'descendant-or-self'; \r
352         axis_following_sibling = 'following-sibling'; \r
353         axis_following = 'following'; \r
354         axis_namespace = 'namespace'; \r
355         \r
356         // reverse axis \r
357         axis_parent = 'parent'; \r
358         axis_ancestor = 'ancestor'; \r
359         axis_preceding_sibling = 'preceding-sibling'; \r
360         axis_preceding = 'preceding'; \r
361         axis_ancestor_or_self = 'ancestor-or-self'; \r
362         \r
363         \r
364         /**\r
365          *  Node Set Functions\r
366          * \r
367          *      function: number last()\r
368          *      function: number position()\r
369          *      function: number count(node-set)\r
370          *      function: node-set id(object) \r
371          *      function: string local-name(node-set?)\r
372          *      function: string namespace-uri(node-set?)\r
373          *      function: string name(node-set?) \r
374          */\r
375         \r
376         /** \r
377          *  String Functions\r
378          *\r
379          *      function: string string(object?)\r
380          *      function: string concat(string, string, string*)\r
381          *      function: boolean starts-with(string, string)\r
382          *      function: boolean contains(string, string)\r
383          *      function: string substring-before(string, string)\r
384          *      function: string substring-after(string, string)\r
385          *      function: string substring(string, number, number?) \r
386          *      function: number string-length(string?)\r
387          *      function: string normalize-space(string?)\r
388          *      function: string translate(string, string, string) \r
389          */\r
390         \r
391         /**\r
392          *  Boolean Functions\r
393          *\r
394          *      function: boolean boolean(object)\r
395          *      function: boolean not(boolean)\r
396          *      function: boolean true()\r
397          *      function: boolean false()\r
398          *      function: boolean lang(string) \r
399          */\r
400         \r
401         /** \r
402          *  Number Functions\r
403          *\r
404          *      function: number number(object?)\r
405          *      function: number sum(node-set)\r
406          *      function: number floor(number) \r
407          *      function: number ceiling(number)\r
408          *      function: number round(number) \r
409          */\r
410         \r
411         /**\r
412          * Reserved Function Names \r
413          */ \r
414         //fn_attribute = 'attribute'; \r
415         fn_comment = 'comment'; \r
416         fn_document_node = 'document-node'; \r
417         fn_element = 'element'; \r
418         fn_empty_sequence = 'empty-sequence'; \r
419         fn_item = 'item'; \r
420         fn_node = 'node'; \r
421         fn_processing_instruction = 'processing-instruction'; \r
422         fn_schema_attribute = 'schema-attribute'; \r
423         fn_schema_element = 'schema-element'; \r
424         fn_text = 'text'; \r
425         fn_typeswitch = 'typeswitch'; \r
426         \r
427         \r
428         xmlns = 'xmlns'; \r
429         ncnamechar      =   namechar; \r
430         //ncnamechar    =   [namechar - ':']; \r
431         \r
432         letter     =    basechar+; \r
433         \r
434         underscore = '_'; \r
435         \r
436         integerliteral          =       digits; \r
437         \r
438         decimalliteral          =       ('.' digits) | (digits '.' [0-9]*); \r
439         \r
440         doubleliteral           =   doubleliteral_helper; \r
441         \r
442         stringliteral           =   stringliteral_helper; \r
443         \r
444         whitespace      =       (' ' | tab | eol);\r
445         comment            =            '(:' (char)* ':)'; \r
446         \r
447         \r
448 Ignored Tokens \r
449         \r
450         whitespace, \r
451         comment; \r
452         \r
453         \r
454 Productions \r
455         \r
456         xpath = expr; \r
457         \r
458         expr = exprsingle? expr_part*; \r
459                 expr_part = T.comma exprsingle; \r
460         \r
461         exprsingle =    {for} forexpr | \r
462                                         {quantif} quantifiedexpr | \r
463                                         {if} ifexpr | \r
464                                         {or} orexpr;\r
465         \r
466         forexpr                 = simpleforclause T.keyword_return exprsingle;\r
467         \r
468         simpleforclause = T.keyword_for T.dollar varname T.keyword_in exprsingle simpleforclause_part*;\r
469                 simpleforclause_part = T.comma T.dollar varname T.keyword_in exprsingle;\r
470         \r
471         quantifiedexpr  = some_every_part T.dollar varname T.keyword_in [exprsingle1]:exprsingle quantifiedexpr_part* T.keyword_satisfies [exprsingle2]:exprsingle;\r
472                 some_every_part =       {some}  T.keyword_some | \r
473                                                         {every} T.keyword_every; \r
474                 quantifiedexpr_part = T.comma T.dollar varname T.keyword_in exprsingle; \r
475         \r
476         ifexpr = T.keyword_if T.lparenth expr T.rparenth T.keyword_then [exprsingle1]:exprsingle T.keyword_else [exprsingle2]:exprsingle;\r
477         \r
478         orexpr     =            andexpr orexpr_part*;\r
479                 orexpr_part = T.keyword_or andexpr; \r
480         \r
481         andexpr            =            comparisonexpr andexpr_part*;\r
482                 andexpr_part = T.keyword_and comparisonexpr; \r
483         \r
484         comparisonexpr     =    rangeexpr comparisonexpr_part?; \r
485                 comparisonexpr_part = comparisonexpr_part_part rangeexpr; \r
486                 comparisonexpr_part_part =      {value} valuecomp | \r
487                                                                         {general} generalcomp | \r
488                                                                         {node} nodecomp; \r
489         \r
490         rangeexpr          =            additiveexpr rangeexpr_part?;\r
491                 rangeexpr_part = T.keyword_to additiveexpr; \r
492         \r
493         additiveexpr       =            multiplicativeexpr additiveexpr_part*;\r
494                 additiveexpr_part = additiveexpr_part_part multiplicativeexpr; \r
495                 additiveexpr_part_part =        {plus} T.plus2 | \r
496                                                                         {minus} T.minus2; \r
497         \r
498         \r
499         multiplicativeexpr         =            unionexpr multiplicativeexpr_part*; \r
500                 multiplicativeexpr_part = multiplicativeexpr_part_part unionexpr; \r
501                 multiplicativeexpr_part_part =  {star} T.star2 | \r
502                                                                                 {div} T.keyword_div | \r
503                                                                                 {idiv} T.keyword_idiv | \r
504                                                                                 {mod} T.keyword_mod; \r
505         \r
506         unionexpr          =            intersectexceptexpr unionexpr_part*;\r
507                 unionexpr_part = unionexpr_part_part intersectexceptexpr; \r
508                 unionexpr_part_part =   {unionkey} T.keyword_union | \r
509                                                                 {union} T.union; \r
510                 \r
511         intersectexceptexpr        =            instanceofexpr intersectexceptexpr_part*;\r
512                 intersectexceptexpr_part = intersectexceptexpr_part_part instanceofexpr; \r
513                 intersectexceptexpr_part_part =         {intersect} T.keyword_intersect | \r
514                                                                                         {except} T.keyword_except; \r
515         \r
516         instanceofexpr     =            treatexpr instanceofexpr_part?;\r
517                 instanceofexpr_part = T.keyword_instance T.keyword_of sequencetype; \r
518                 \r
519         treatexpr          =            castableexpr treatexpr_part?; \r
520                 treatexpr_part = T.keyword_treat T.keyword_as sequencetype; \r
521         \r
522         castableexpr       =            castexpr castableexpr_part?;\r
523                 castableexpr_part = T.keyword_castable T.keyword_as singletype; \r
524         \r
525         castexpr           =            unaryexpr castexpr_part?;\r
526                 castexpr_part = T.keyword_cast T.keyword_as singletype; \r
527         \r
528         unaryexpr          =            unaryexpr_part* valueexpr;\r
529                 unaryexpr_part =        {minus} T.minus | \r
530                                                         {plus} T.plus; \r
531         \r
532         valueexpr          =            pathexpr;\r
533         \r
534         generalcomp        =    {eq} T.equals | \r
535                                                         {ne} T.ne_abbrev | \r
536                                                         {lt} T.lt_abbrev | \r
537                                                         {le} T.le_abbrev | \r
538                                                         {gt} T.gt_abbrev | \r
539                                                         {ge} T.ge_abbrev;\r
540         \r
541         valuecomp          =    {eq} T.eq | \r
542                                                 {ne} T.ne | \r
543                                                 {lt} T.lt | \r
544                                                 {le} T.le | \r
545                                                 {gt} T.gt | \r
546                                                 {ge} T.ge;\r
547         \r
548         nodecomp           =    {is} T.keyword_is | \r
549                                                 {ncomppre} T.ncomp_precedes | \r
550                                                 {ncompfol} T.ncomp_follows;\r
551         \r
552         pathexpr           =    {path1} pathexpr_part_one | \r
553                                                 {path2} pathexpr_part_two | \r
554                                                 {relpath} relativepathexpr; \r
555                 pathexpr_part_one = T.abbrev_root relativepathexpr?; \r
556                 pathexpr_part_two = T.abbrev_root_desc relativepathexpr; \r
557         \r
558         relativepathexpr           =            stepexpr relativepathexpr_part*;\r
559                 relativepathexpr_part = relativepathexpr_part_part stepexpr; \r
560                 relativepathexpr_part_part =    {root} T.abbrev_root | \r
561                                                                                 {rootdesc} T.abbrev_root_desc; \r
562         \r
563         stepexpr           =    {filter} filterexpr | \r
564                                                 {axis} axisstep;\r
565         \r
566         \r
567         /**\r
568          * Axes \r
569          */ \r
570         axisstep           =    axisstep_part predicatelist;\r
571                 axisstep_part =         {reverse} reversestep | \r
572                                                         {forward} forwardstep; \r
573         \r
574         forwardstep        =    {forward} forwardstep_part | \r
575                                                         {abbrevforward} abbrevforwardstep;\r
576                 forwardstep_part = forwardaxis nodetest; \r
577                 \r
578         forwardaxis        =    {forward1} forwardaxis_part_one | \r
579                                                         {forward2} forwardaxis_part_two | \r
580                                                         {forward3} forwardaxis_part_three | \r
581                                                         {forward4} forwardaxis_part_four | \r
582                                                         {forward5} forwardaxis_part_five | \r
583                                                         {forward6} forwardaxis_part_six | \r
584                                                         {forward7} forwardaxis_part_seven | \r
585                                                         {forward8} forwardaxis_part_eight;\r
586                 forwardaxis_part_one = T.axis_child T.axis_delim; \r
587                 forwardaxis_part_two = T.axis_descendant T.axis_delim; \r
588                 forwardaxis_part_three = T.axis_attribute T.axis_delim; \r
589                 forwardaxis_part_four = T.axis_self T.axis_delim; \r
590                 forwardaxis_part_five = T.axis_descendant_or_self T.axis_delim; \r
591                 forwardaxis_part_six = T.axis_following_sibling T.axis_delim; \r
592                 forwardaxis_part_seven = T.axis_following T.axis_delim; \r
593                 forwardaxis_part_eight = T.axis_namespace T.axis_delim; \r
594         \r
595         abbrevforwardstep          =            T.abbrev_attrib? nodetest;\r
597         reversestep        =    {reverse} reversestep_part | \r
598                                                         {abbrevreverse} abbrevreversestep; \r
599                 reversestep_part = reverseaxis nodetest; \r
601         reverseaxis        =    {reverse1} reverseaxis_part_one | \r
602                                                         {reverse2} reverseaxis_part_two | \r
603                                                         {reverse3} reverseaxis_part_three | \r
604                                                         {reverse4} reverseaxis_part_four | \r
605                                                         {reverse5} reverseaxis_part_five; \r
606                 reverseaxis_part_one = T.axis_parent T.axis_delim; \r
607                 reverseaxis_part_two = T.axis_ancestor T.axis_delim; \r
608                 reverseaxis_part_three = T.axis_preceding_sibling T.axis_delim; \r
609                 reverseaxis_part_four = T.axis_preceding T.axis_delim; \r
610                 reverseaxis_part_five = T.axis_ancestor_or_self T.axis_delim; \r
611                 \r
612                 \r
613         abbrevreversestep          =            T.abbrev_reversestep;\r
615         nodetest           =    {kind} kindtest | \r
616                                                 {name} nametest;\r
617         \r
618         nametest           =    {qname} qname | \r
619                                                 {wildc} wildcard;\r
620         \r
621         wildcard           =    {star} T.star | \r
622                                                 {wild1} wildcard_part_one | \r
623                                                 {wild2} wildcard_part_two; \r
624                 wildcard_part_one = ncname T.colon T.star; \r
625                 wildcard_part_two = T.star T.colon ncname; \r
626                 \r
627         filterexpr         =            primaryexpr predicatelist;\r
628         \r
629         predicatelist      =            predicate*;\r
631         predicate          =            T.lbracket expr T.rbracket;\r
632         \r
633         primaryexpr        =    {literal} literal | \r
634                                                         {varref} varref | \r
635                                                         {parenthex} parenthesizedexpr | \r
636                                                         {contextex} contextitemexpr | \r
637                                                         {function} functioncall;\r
638         \r
639         literal            =    {numeric} numericliteral | \r
640                                                 {string} stringliteral;\r
641         \r
642         numericliteral     =    {integer} integerliteral | \r
643                                                         {decimal} decimalliteral | \r
644                                                         {double} doubleliteral;\r
645         \r
646         varref     =            T.dollar varname;\r
648         varname            =            qname;\r
650         parenthesizedexpr          =            T.lparenth expr? T.rparenth;\r
652         contextitemexpr            =            T.abbrev_context;\r
654         \r
655         /** \r
656          * Functions\r
657          */ \r
658         \r
659         functioncall       =            qname T.lparenth functioncall_part? T.rparenth;         \r
660                 functioncall_part = exprsingle functioncall_part_part*; \r
661                 functioncall_part_part = T.comma exprsingle; \r
662         \r
663         \r
664         singletype         =            atomictype T.question?;\r
665         \r
666         sequencetype       =    {sequencetype1} sequencetype_part_one | \r
667                                                         {sequencetype2} sequencetype_part_two;\r
668                 sequencetype_part_one = T.fn_empty_sequence T.lparenth T.rparenth; \r
669                 sequencetype_part_two = itemtype occurrenceindicator?; \r
670         \r
671         occurrenceindicator        =    {question} T.question | \r
672                                                                         {star} T.star | \r
673                                                                         {plus} T.plus; \r
674         \r
675         \r
676         itemtype           =    {kind} kindtest | \r
677                                                 {item} itemtype_part | \r
678                                                 {atomic} atomictype; \r
679                 itemtype_part = T.fn_item T.lparenth T.rparenth; \r
681         atomictype         =    qname;\r
683         kindtest           =    {document} documenttest | \r
684                                                 {element} elementtest | \r
685                                                 {attribute} attributetest | \r
686                                                 {schemaelem} schemaelementtest | \r
687                                                 {schemaattr} schemaattributetest | \r
688                                                 {pi} pitest | \r
689                                                 {comment} commenttest | \r
690                                                 {text} texttest | \r
691         //                                      {any} anykindtest;\r
692                                                 {any} akindtest;\r
694         //anykindtest      =            T.fn_node T.lparenth T.rparenth;\r
695         akindtest          =            T.fn_node T.lparenth T.rparenth;\r
696         \r
697         documenttest       =            T.fn_document_node T.lparenth documenttest_part? T.rparenth; \r
698                 documenttest_part =     {element} elementtest | \r
699                                                                 {schemaelem} schemaelementtest; \r
700                 \r
702         texttest           =            T.fn_text T.lparenth T.rparenth;\r
704         commenttest        =            T.fn_comment T.lparenth T.rparenth;\r
705         \r
706         pitest     =            T.fn_processing_instruction T.lparenth pitest_part? T.rparenth; \r
707                 pitest_part =   {ncname} ncname | \r
708                                                 {stringlit} stringliteral; \r
709         \r
710         attributetest      =            T.axis_attribute T.lparenth attributetest_part? T.rparenth;     //fn_attribute doesn't work \r
711                 attributetest_part = attribnameorwildcard attributetest_part_part?; \r
712                 attributetest_part_part = T.comma typename; \r
713         \r
714         \r
715         attribnameorwildcard       =    {attrib} attributename | \r
716                                                                         {star} T.star;\r
718         schemaattributetest        =            T.fn_schema_attribute T.lparenth attributedeclaration T.rparenth;\r
720         attributedeclaration       =            attributename;\r
721         \r
722         elementtest        =            T.fn_element T.lparenth elementtest_part? T.rparenth; \r
723                 elementtest_part = elementnameorwildcard elementtest_part_part?; \r
724                 elementtest_part_part = T.comma typename T.question?; \r
725         \r
726         elementnameorwildcard      =    {element} elementname | \r
727                                                                         {star} T.star;\r
729         schemaelementtest          =            T.fn_schema_element T.lparenth elementdeclaration T.rparenth;\r
731         elementdeclaration         =            elementname;\r
733         attributename      =            qname;\r
735         elementname        =            qname;\r
737         typename           =            qname;\r
738         \r
739         \r
740         /** \r
741          * Qualified XML Names \r
742          */\r
743         qname   =       {prefixed} prefixedname | \r
744                                 {unprefixed} unprefixedname; \r
745         \r
746         prefixedname    =       prefix T.colon localpart; \r
747         \r
748         unprefixedname  =       localpart; \r
749         \r
750         prefix     =    ncname; \r
751         \r
752         localpart       =       ncname; \r
753         \r
754         \r
755         /** \r
756          * Attribute Names for Namespace \r
757          */ \r
758         nsattname       =       {prefixed} prefixedattname | \r
759                                         {default} defaultattname; \r
760         \r
761         prefixedattname =       T.xmlns T.colon ncname; \r
762         \r
763         defaultattname  =       T.xmlns; \r
764         \r
765         ncname     =    ncnamestartchar ncnamechar*;            /* An XML Name, minus the ":" */\r
766         \r
767                 \r
768         ncnamestartchar =       {letter} T.letter | \r
769                                                 {underscore} T.underscore ; \r
771         \r
772