gtl-parsley-ruby 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. data/CHANGELOG +3 -0
  2. data/README +32 -0
  3. data/Rakefile +57 -0
  4. data/VERSION +1 -0
  5. data/ext/cparsley.c +152 -0
  6. data/ext/extconf.rb +82 -0
  7. data/ext/parsley/.gitignore +32 -0
  8. data/ext/parsley/AUTHORS +1 -0
  9. data/ext/parsley/ChangeLog +0 -0
  10. data/ext/parsley/HACKING +4 -0
  11. data/ext/parsley/INSTALL +73 -0
  12. data/ext/parsley/INTRO +84 -0
  13. data/ext/parsley/Makefile.am +80 -0
  14. data/ext/parsley/Makefile.in +1009 -0
  15. data/ext/parsley/NEWS +0 -0
  16. data/ext/parsley/PAPER +36 -0
  17. data/ext/parsley/Portfile +18 -0
  18. data/ext/parsley/Portfile.in +17 -0
  19. data/ext/parsley/README.C-LANG +92 -0
  20. data/ext/parsley/README.markdown +1 -0
  21. data/ext/parsley/TODO +39 -0
  22. data/ext/parsley/VERSION +1 -0
  23. data/ext/parsley/aclocal.m4 +8918 -0
  24. data/ext/parsley/bootstrap.sh +6 -0
  25. data/ext/parsley/config.guess +1561 -0
  26. data/ext/parsley/config.sub +1686 -0
  27. data/ext/parsley/configure +13437 -0
  28. data/ext/parsley/configure.ac +46 -0
  29. data/ext/parsley/depcomp +630 -0
  30. data/ext/parsley/functions.c +368 -0
  31. data/ext/parsley/functions.h +19 -0
  32. data/ext/parsley/generate_bisect.sh +12 -0
  33. data/ext/parsley/hooks/prepare-commit-msg +16 -0
  34. data/ext/parsley/install-sh +520 -0
  35. data/ext/parsley/json-c-0.9/AUTHORS +2 -0
  36. data/ext/parsley/json-c-0.9/COPYING +19 -0
  37. data/ext/parsley/json-c-0.9/ChangeLog +103 -0
  38. data/ext/parsley/json-c-0.9/INSTALL +302 -0
  39. data/ext/parsley/json-c-0.9/Makefile.am +43 -0
  40. data/ext/parsley/json-c-0.9/Makefile.in +800 -0
  41. data/ext/parsley/json-c-0.9/NEWS +1 -0
  42. data/ext/parsley/json-c-0.9/README +20 -0
  43. data/ext/parsley/json-c-0.9/README-WIN32.html +57 -0
  44. data/ext/parsley/json-c-0.9/README.html +32 -0
  45. data/ext/parsley/json-c-0.9/aclocal.m4 +8909 -0
  46. data/ext/parsley/json-c-0.9/arraylist.c +94 -0
  47. data/ext/parsley/json-c-0.9/arraylist.h +53 -0
  48. data/ext/parsley/json-c-0.9/bits.h +27 -0
  49. data/ext/parsley/json-c-0.9/config.guess +1561 -0
  50. data/ext/parsley/json-c-0.9/config.h +125 -0
  51. data/ext/parsley/json-c-0.9/config.h.in +124 -0
  52. data/ext/parsley/json-c-0.9/config.h.win32 +94 -0
  53. data/ext/parsley/json-c-0.9/config.sub +1686 -0
  54. data/ext/parsley/json-c-0.9/configure +13084 -0
  55. data/ext/parsley/json-c-0.9/configure.in +33 -0
  56. data/ext/parsley/json-c-0.9/debug.c +98 -0
  57. data/ext/parsley/json-c-0.9/debug.h +50 -0
  58. data/ext/parsley/json-c-0.9/depcomp +630 -0
  59. data/ext/parsley/json-c-0.9/doc/html/annotated.html +40 -0
  60. data/ext/parsley/json-c-0.9/doc/html/arraylist_8h.html +240 -0
  61. data/ext/parsley/json-c-0.9/doc/html/bits_8h.html +150 -0
  62. data/ext/parsley/json-c-0.9/doc/html/classes.html +36 -0
  63. data/ext/parsley/json-c-0.9/doc/html/config_8h.html +612 -0
  64. data/ext/parsley/json-c-0.9/doc/html/debug_8h.html +392 -0
  65. data/ext/parsley/json-c-0.9/doc/html/doxygen.css +441 -0
  66. data/ext/parsley/json-c-0.9/doc/html/doxygen.png +0 -0
  67. data/ext/parsley/json-c-0.9/doc/html/files.html +42 -0
  68. data/ext/parsley/json-c-0.9/doc/html/functions.html +206 -0
  69. data/ext/parsley/json-c-0.9/doc/html/functions_vars.html +206 -0
  70. data/ext/parsley/json-c-0.9/doc/html/globals.html +459 -0
  71. data/ext/parsley/json-c-0.9/doc/html/globals_defs.html +202 -0
  72. data/ext/parsley/json-c-0.9/doc/html/globals_enum.html +50 -0
  73. data/ext/parsley/json-c-0.9/doc/html/globals_eval.html +135 -0
  74. data/ext/parsley/json-c-0.9/doc/html/globals_func.html +194 -0
  75. data/ext/parsley/json-c-0.9/doc/html/globals_type.html +70 -0
  76. data/ext/parsley/json-c-0.9/doc/html/globals_vars.html +50 -0
  77. data/ext/parsley/json-c-0.9/doc/html/index.html +25 -0
  78. data/ext/parsley/json-c-0.9/doc/html/json_8h.html +32 -0
  79. data/ext/parsley/json-c-0.9/doc/html/json__object_8h.html +1150 -0
  80. data/ext/parsley/json-c-0.9/doc/html/json__object__private_8h.html +75 -0
  81. data/ext/parsley/json-c-0.9/doc/html/json__tokener_8h.html +366 -0
  82. data/ext/parsley/json-c-0.9/doc/html/json__util_8h.html +106 -0
  83. data/ext/parsley/json-c-0.9/doc/html/linkhash_8h.html +740 -0
  84. data/ext/parsley/json-c-0.9/doc/html/printbuf_8h.html +214 -0
  85. data/ext/parsley/json-c-0.9/doc/html/structarray__list.html +104 -0
  86. data/ext/parsley/json-c-0.9/doc/html/structjson__object.html +141 -0
  87. data/ext/parsley/json-c-0.9/doc/html/structjson__object__iter.html +87 -0
  88. data/ext/parsley/json-c-0.9/doc/html/structjson__tokener.html +206 -0
  89. data/ext/parsley/json-c-0.9/doc/html/structjson__tokener__srec.html +104 -0
  90. data/ext/parsley/json-c-0.9/doc/html/structlh__entry.html +105 -0
  91. data/ext/parsley/json-c-0.9/doc/html/structlh__table.html +275 -0
  92. data/ext/parsley/json-c-0.9/doc/html/structprintbuf.html +87 -0
  93. data/ext/parsley/json-c-0.9/doc/html/tab_b.gif +0 -0
  94. data/ext/parsley/json-c-0.9/doc/html/tab_l.gif +0 -0
  95. data/ext/parsley/json-c-0.9/doc/html/tab_r.gif +0 -0
  96. data/ext/parsley/json-c-0.9/doc/html/tabs.css +105 -0
  97. data/ext/parsley/json-c-0.9/doc/html/unionjson__object_1_1data.html +140 -0
  98. data/ext/parsley/json-c-0.9/install-sh +520 -0
  99. data/ext/parsley/json-c-0.9/json.h +31 -0
  100. data/ext/parsley/json-c-0.9/json.pc +11 -0
  101. data/ext/parsley/json-c-0.9/json.pc.in +11 -0
  102. data/ext/parsley/json-c-0.9/json_object.c +512 -0
  103. data/ext/parsley/json-c-0.9/json_object.h +319 -0
  104. data/ext/parsley/json-c-0.9/json_object_private.h +52 -0
  105. data/ext/parsley/json-c-0.9/json_tokener.c +628 -0
  106. data/ext/parsley/json-c-0.9/json_tokener.h +98 -0
  107. data/ext/parsley/json-c-0.9/json_util.c +122 -0
  108. data/ext/parsley/json-c-0.9/json_util.h +31 -0
  109. data/ext/parsley/json-c-0.9/libjson.la +41 -0
  110. data/ext/parsley/json-c-0.9/libtool +8890 -0
  111. data/ext/parsley/json-c-0.9/linkhash.c +216 -0
  112. data/ext/parsley/json-c-0.9/linkhash.h +272 -0
  113. data/ext/parsley/json-c-0.9/ltmain.sh +8406 -0
  114. data/ext/parsley/json-c-0.9/missing +376 -0
  115. data/ext/parsley/json-c-0.9/printbuf.c +149 -0
  116. data/ext/parsley/json-c-0.9/printbuf.h +64 -0
  117. data/ext/parsley/json-c-0.9/stamp-h1 +1 -0
  118. data/ext/parsley/json-c-0.9/test1 +130 -0
  119. data/ext/parsley/json-c-0.9/test1.c +164 -0
  120. data/ext/parsley/json-c-0.9/test2 +130 -0
  121. data/ext/parsley/json-c-0.9/test2.c +20 -0
  122. data/ext/parsley/json-c-0.9/test3 +130 -0
  123. data/ext/parsley/json-c-0.9/test3.c +23 -0
  124. data/ext/parsley/libtool +8890 -0
  125. data/ext/parsley/ltmain.sh +8406 -0
  126. data/ext/parsley/missing +376 -0
  127. data/ext/parsley/parsed_xpath.c +168 -0
  128. data/ext/parsley/parsed_xpath.h +34 -0
  129. data/ext/parsley/parser.y +631 -0
  130. data/ext/parsley/parsley.c +793 -0
  131. data/ext/parsley/parsley.h +87 -0
  132. data/ext/parsley/parsley_main.c +185 -0
  133. data/ext/parsley/parsleyc_main.c +108 -0
  134. data/ext/parsley/regexp.c +359 -0
  135. data/ext/parsley/regexp.h +36 -0
  136. data/ext/parsley/scanner.l +221 -0
  137. data/ext/parsley/test/ambiguous.html +207 -0
  138. data/ext/parsley/test/ambiguous.json +1 -0
  139. data/ext/parsley/test/ambiguous.let +6 -0
  140. data/ext/parsley/test/array-regression.html +5 -0
  141. data/ext/parsley/test/array-regression.json +1 -0
  142. data/ext/parsley/test/array-regression.let +10 -0
  143. data/ext/parsley/test/backslash.html +5 -0
  144. data/ext/parsley/test/backslash.json +1 -0
  145. data/ext/parsley/test/backslash.let +3 -0
  146. data/ext/parsley/test/bang.html +17 -0
  147. data/ext/parsley/test/bang.json +1 -0
  148. data/ext/parsley/test/bang.let +6 -0
  149. data/ext/parsley/test/collate_regression.html +324 -0
  150. data/ext/parsley/test/collate_regression.json +1 -0
  151. data/ext/parsley/test/collate_regression.let +9 -0
  152. data/ext/parsley/test/contains.html +3 -0
  153. data/ext/parsley/test/contains.json +1 -0
  154. data/ext/parsley/test/contains.let +3 -0
  155. data/ext/parsley/test/content.html +13 -0
  156. data/ext/parsley/test/content.json +1 -0
  157. data/ext/parsley/test/content.let +7 -0
  158. data/ext/parsley/test/cool.html +575 -0
  159. data/ext/parsley/test/cool.json +1 -0
  160. data/ext/parsley/test/cool.let +9 -0
  161. data/ext/parsley/test/craigs-simple.html +207 -0
  162. data/ext/parsley/test/craigs-simple.json +1 -0
  163. data/ext/parsley/test/craigs-simple.let +6 -0
  164. data/ext/parsley/test/craigs.html +207 -0
  165. data/ext/parsley/test/craigs.json +1 -0
  166. data/ext/parsley/test/craigs.let +9 -0
  167. data/ext/parsley/test/crash.html +157 -0
  168. data/ext/parsley/test/crash.json +1 -0
  169. data/ext/parsley/test/crash.let +1 -0
  170. data/ext/parsley/test/css_attr.html +3 -0
  171. data/ext/parsley/test/css_attr.json +1 -0
  172. data/ext/parsley/test/css_attr.let +3 -0
  173. data/ext/parsley/test/default-namespace.json +1 -0
  174. data/ext/parsley/test/default-namespace.let +3 -0
  175. data/ext/parsley/test/default-namespace.xml +1493 -0
  176. data/ext/parsley/test/div.html +8 -0
  177. data/ext/parsley/test/div.json +1 -0
  178. data/ext/parsley/test/div.let +10 -0
  179. data/ext/parsley/test/empty.html +3 -0
  180. data/ext/parsley/test/empty.json +1 -0
  181. data/ext/parsley/test/empty.let +1 -0
  182. data/ext/parsley/test/emptyish.html +207 -0
  183. data/ext/parsley/test/emptyish.let +3 -0
  184. data/ext/parsley/test/fictional-opt.html +43 -0
  185. data/ext/parsley/test/fictional-opt.json +1 -0
  186. data/ext/parsley/test/fictional-opt.let +14 -0
  187. data/ext/parsley/test/fictional.html +43 -0
  188. data/ext/parsley/test/fictional.json +1 -0
  189. data/ext/parsley/test/fictional.let +14 -0
  190. data/ext/parsley/test/function-magic.html +9 -0
  191. data/ext/parsley/test/function-magic.json +1 -0
  192. data/ext/parsley/test/function-magic.let +8 -0
  193. data/ext/parsley/test/hn.html +32 -0
  194. data/ext/parsley/test/hn.json +1 -0
  195. data/ext/parsley/test/hn.let +8 -0
  196. data/ext/parsley/test/malformed-array.html +2329 -0
  197. data/ext/parsley/test/malformed-array.json +1 -0
  198. data/ext/parsley/test/malformed-array.let +22 -0
  199. data/ext/parsley/test/malformed-expr.html +2329 -0
  200. data/ext/parsley/test/malformed-expr.json +1 -0
  201. data/ext/parsley/test/malformed-expr.let +16 -0
  202. data/ext/parsley/test/malformed-function.html +845 -0
  203. data/ext/parsley/test/malformed-function.json +197 -0
  204. data/ext/parsley/test/malformed-function.let +8 -0
  205. data/ext/parsley/test/malformed-json.html +2329 -0
  206. data/ext/parsley/test/malformed-json.json +1 -0
  207. data/ext/parsley/test/malformed-json.let +6 -0
  208. data/ext/parsley/test/malformed-xpath.html +8 -0
  209. data/ext/parsley/test/malformed-xpath.json +1 -0
  210. data/ext/parsley/test/malformed-xpath.let +7 -0
  211. data/ext/parsley/test/match.json +1 -0
  212. data/ext/parsley/test/match.let +9 -0
  213. data/ext/parsley/test/match.xml +11 -0
  214. data/ext/parsley/test/math_ambiguity.html +9 -0
  215. data/ext/parsley/test/math_ambiguity.json +1 -0
  216. data/ext/parsley/test/math_ambiguity.let +5 -0
  217. data/ext/parsley/test/nth-regression.html +13 -0
  218. data/ext/parsley/test/nth-regression.json +1 -0
  219. data/ext/parsley/test/nth-regression.let +3 -0
  220. data/ext/parsley/test/optional.html +2328 -0
  221. data/ext/parsley/test/optional.json +1 -0
  222. data/ext/parsley/test/optional.let +8 -0
  223. data/ext/parsley/test/outer-xml.html +6 -0
  224. data/ext/parsley/test/outer-xml.json +1 -0
  225. data/ext/parsley/test/outer-xml.let +5 -0
  226. data/ext/parsley/test/position.html +8 -0
  227. data/ext/parsley/test/position.json +1 -0
  228. data/ext/parsley/test/position.let +6 -0
  229. data/ext/parsley/test/question_regressions.html +443 -0
  230. data/ext/parsley/test/question_regressions.json +1 -0
  231. data/ext/parsley/test/question_regressions.let +6 -0
  232. data/ext/parsley/test/quote.json +1 -0
  233. data/ext/parsley/test/quote.let +8 -0
  234. data/ext/parsley/test/quote.xml +11 -0
  235. data/ext/parsley/test/reddit.html +1 -0
  236. data/ext/parsley/test/reddit.json +1 -0
  237. data/ext/parsley/test/reddit.let +12 -0
  238. data/ext/parsley/test/remote-fail.json +1 -0
  239. data/ext/parsley/test/remote.html +3 -0
  240. data/ext/parsley/test/remote.json +1 -0
  241. data/ext/parsley/test/remote.let +4 -0
  242. data/ext/parsley/test/replace.json +1 -0
  243. data/ext/parsley/test/replace.let +9 -0
  244. data/ext/parsley/test/replace.xml +11 -0
  245. data/ext/parsley/test/scope.html +10 -0
  246. data/ext/parsley/test/scope.json +1 -0
  247. data/ext/parsley/test/scope.let +6 -0
  248. data/ext/parsley/test/segfault.html +5 -0
  249. data/ext/parsley/test/segfault.json +1 -0
  250. data/ext/parsley/test/segfault.let +9 -0
  251. data/ext/parsley/test/sg-wrap.html +5 -0
  252. data/ext/parsley/test/sg-wrap.json +1 -0
  253. data/ext/parsley/test/sg-wrap.let +3 -0
  254. data/ext/parsley/test/sg_off.html +5 -0
  255. data/ext/parsley/test/sg_off.json +1 -0
  256. data/ext/parsley/test/sg_off.let +3 -0
  257. data/ext/parsley/test/test.json +1 -0
  258. data/ext/parsley/test/test.let +6 -0
  259. data/ext/parsley/test/test.xml +11 -0
  260. data/ext/parsley/test/trivial.html +2329 -0
  261. data/ext/parsley/test/trivial.json +1 -0
  262. data/ext/parsley/test/trivial.let +4 -0
  263. data/ext/parsley/test/trivial2.html +2329 -0
  264. data/ext/parsley/test/trivial2.json +1 -0
  265. data/ext/parsley/test/trivial2.let +7 -0
  266. data/ext/parsley/test/unbang.html +17 -0
  267. data/ext/parsley/test/unbang.json +1 -0
  268. data/ext/parsley/test/unbang.let +6 -0
  269. data/ext/parsley/test/unicode.html +3 -0
  270. data/ext/parsley/test/unicode.json +1 -0
  271. data/ext/parsley/test/unicode.let +1 -0
  272. data/ext/parsley/test/whitespace.html +8 -0
  273. data/ext/parsley/test/whitespace.json +1 -0
  274. data/ext/parsley/test/whitespace.let +3 -0
  275. data/ext/parsley/test/whitespace_regression.html +4 -0
  276. data/ext/parsley/test/whitespace_regression.json +1 -0
  277. data/ext/parsley/test/whitespace_regression.let +3 -0
  278. data/ext/parsley/test/yelp-benchmark.rb +53 -0
  279. data/ext/parsley/test/yelp-home.html +1004 -0
  280. data/ext/parsley/test/yelp-home.json +1 -0
  281. data/ext/parsley/test/yelp-home.let +6 -0
  282. data/ext/parsley/test/yelp.html +2329 -0
  283. data/ext/parsley/test/yelp.json +1 -0
  284. data/ext/parsley/test/yelp.let +12 -0
  285. data/ext/parsley/test/youtube.html +1940 -0
  286. data/ext/parsley/test/youtube.let +11 -0
  287. data/ext/parsley/util.c +237 -0
  288. data/ext/parsley/util.h +34 -0
  289. data/ext/parsley/xml2json.c +47 -0
  290. data/ext/parsley/xml2json.h +14 -0
  291. data/ext/parsley/y.tab.h +222 -0
  292. data/ext/parsley/ylwrap +222 -0
  293. data/lib/parsley.rb +84 -0
  294. data/test/test_parsley.rb +120 -0
  295. data/test/yelp-benchmark.rb +53 -0
  296. data/test/yelp-home.html +1004 -0
  297. data/test/yelp-home.let +6 -0
  298. data/test/yelp.html +2329 -0
  299. metadata +366 -0
@@ -0,0 +1,34 @@
1
+ #ifndef _parsed_xpath_h_
2
+ #define _parsed_xpath_h_
3
+
4
+ #include <stdarg.h>
5
+
6
+ typedef struct __pxpath_node {
7
+ int type;
8
+ char* value;
9
+ struct __pxpath_node * next;
10
+ struct __pxpath_node * child;
11
+ } pxpath_node;
12
+
13
+ typedef pxpath_node * pxpathPtr;
14
+
15
+ enum {
16
+ PXPATH_FUNCTION = 1,
17
+ PXPATH_PATH = 2,
18
+ PXPATH_LITERAL = 3,
19
+ PXPATH_LIT_EXPR = 4,
20
+ PXPATH_OPERATOR = 3
21
+ };
22
+
23
+ pxpathPtr pxpath_new(int type, char* value);
24
+ pxpathPtr pxpath_new_func(char* value, pxpathPtr child);
25
+ pxpathPtr pxpath_cat_paths(int n, ...);
26
+ pxpathPtr pxpath_cat_literals(int n, ...);
27
+ pxpathPtr pxpath_new_path(int n, ...);
28
+ pxpathPtr pxpath_dup(pxpathPtr p);
29
+ pxpathPtr pxpath_new_literal(int n, ...);
30
+ pxpathPtr pxpath_new_operator(int n, ...);
31
+ void pxpath_free(pxpathPtr ptr);
32
+ char* pxpath_to_string(pxpathPtr ptr);
33
+
34
+ #endif
@@ -0,0 +1,631 @@
1
+ %{
2
+ #include <math.h>
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+ #include "parsed_xpath.h"
7
+ #include <libxml/hash.h>
8
+
9
+ #ifndef PARSER_Y_H_INCLUDED
10
+ #define PARSER_Y_H_INCLUDED
11
+
12
+ static pxpathPtr parsed_answer;
13
+
14
+ int yylex (void);
15
+ void yyerror (char const *);
16
+
17
+ void prepare_parse(char*);
18
+ void cleanup_parse(void);
19
+ void start_debugging(void);
20
+
21
+ static xmlHashTablePtr alias_hash;
22
+
23
+ char* xpath_alias(char*);
24
+ void init_xpath_alias();
25
+
26
+ int yyparse(void);
27
+ pxpathPtr myparse(char*);
28
+ void answer(pxpathPtr);
29
+
30
+ #define LIT_BIN_OP(A, B, C) pxpath_cat_literals(3, A, LIT(B), C)
31
+ #define BIN_OP(A, B, C) pxpath_cat_paths(3, A, OP(B), C)
32
+ #define PREP_OP(A, B) pxpath_cat_paths(2, OP(A), B)
33
+ #define PXP(A) pxpath_new_path(1, A)
34
+ #define LIT(A) pxpath_new_literal(1, A)
35
+ #define OP(A) pxpath_new_operator(1, A)
36
+ #define APPEND(A, S) pxpath_cat_paths(2, A, PXP(S));
37
+ #define PREPEND(A, S) pxpath_cat_paths(2, PXP(S), A);
38
+ #define PXPWRAP(A, B, C) pxpath_cat_paths(3, PXP(A), B, PXP(C))
39
+ #define P4E(A, B, C, D) pxpath_cat_paths(4, A, PXP(B), C, PXP(D))
40
+ #define P4O(A, B, C, D) pxpath_cat_paths(4, PXP(A), B, PXP(C), D)
41
+ #define P6E(A, B, C, D, E, F) pxpath_cat_paths(6, A, PXP(B), C, PXP(D), E, PXP(F));
42
+ #define INPUT_TYPE(A, S) APPEND(A, "[lower-case(name())='input' and lower-case(@type)='" #S "']")
43
+ #define TRACE(A, B) fprintf(stderr, "trace(%s): ", A); fprintf(stderr, "%s\n", pxpath_to_string(B));
44
+
45
+ #endif
46
+
47
+ %}
48
+
49
+ %glr-parser
50
+ %token_table
51
+ %debug
52
+
53
+ %union {
54
+ int empty;
55
+ char* string;
56
+ pxpathPtr node;
57
+ }
58
+
59
+ %token <string> NUMBER
60
+ %token <string> S
61
+ %token <string> AT
62
+ %token <string> LPAREN
63
+ %token <string> RPAREN
64
+ %token <string> PIPE
65
+ %token <string> LT
66
+ %token <string> SLASH
67
+ %token <string> DBLSLASH
68
+ %token <string> BANG
69
+ %token <string> COLON
70
+ %token <string> DBLCOLON
71
+ %token <string> QUERY
72
+ %token <string> HASH
73
+ %token <string> COMMA
74
+ %token <string> DOT
75
+ %token <string> DBLDOT
76
+ %token <string> GT
77
+ %token <string> LBRA
78
+ %token <string> RBRA
79
+ %token <string> TILDE
80
+ %token <string> SPLAT
81
+ %token <string> PLUS
82
+ %token <string> DASH
83
+ %token <string> EQ
84
+ %token <string> LTE
85
+ %token <string> GTE
86
+ %token <string> DOLLAR
87
+ %token <string> BSLASHLIT
88
+ %token <string> OTHER
89
+ %token <string> XANCESTOR
90
+ %token <string> XANCESTORSELF
91
+ %token <string> XATTR
92
+ %token <string> XCHILD
93
+ %token <string> XDESC
94
+ %token <string> XDESCSELF
95
+ %token <string> XFOLLOW
96
+ %token <string> XFOLLOWSIB
97
+ %token <string> XNS
98
+ %token <string> XPARENT
99
+ %token <string> XPRE
100
+ %token <string> XPRESIB
101
+ %token <string> XSELF
102
+ %token <string> XOR
103
+ %token <string> XAND
104
+ %token <string> XDIV
105
+ %token <string> XMOD
106
+ %token <string> XCOMMENT
107
+ %token <string> XTEXT
108
+ %token <string> XPI
109
+ %token <string> XNODE
110
+ %token <string> CXEQUATION
111
+ %token <string> CXOPHE
112
+ %token <string> CXOPNE
113
+ %token <string> CXOPSTARTEQ
114
+ %token <string> CXOPENDEQ
115
+ %token <string> CXOPCONTAINS
116
+ %token <string> CXOPCONTAINS2
117
+ %token <string> CXFIRST
118
+ %token <string> CXLAST
119
+ %token <string> CXNOT
120
+ %token <string> CXEVEN
121
+ %token <string> CXODD
122
+ %token <string> CXEQ
123
+ %token <string> CXGT
124
+ %token <string> CXLT
125
+ %token <string> CXCONTENT
126
+ %token <string> CXHEADER
127
+ %token <string> CXCONTAINS
128
+ %token <string> CXEMPTY
129
+ %token <string> CXHAS
130
+ %token <string> CXPARENT
131
+ %token <string> CXNTHCH
132
+ %token <string> CXNTHLASTCH
133
+ %token <string> CXNTHTYPE
134
+ %token <string> CXNTHLASTTYPE
135
+ %token <string> CXFIRSTCH
136
+ %token <string> CXLASTCH
137
+ %token <string> CXFIRSTTYPE
138
+ %token <string> CXLASTTYPE
139
+ %token <string> CXONLYCH
140
+ %token <string> CXONLYTYPE
141
+ %token <string> CXINPUT
142
+ %token <string> CXTEXT
143
+ %token <string> CXPASSWORD
144
+ %token <string> CXRADIO
145
+ %token <string> CXCHECKBOX
146
+ %token <string> CXSUBMIT
147
+ %token <string> CXIMAGE
148
+ %token <string> CXRESET
149
+ %token <string> CXBUTTON
150
+ %token <string> CXFILE
151
+ %token <string> CXENABLED
152
+ %token <string> CXDISABLED
153
+ %token <string> CXCHECKED
154
+ %token <string> CXSELECTED
155
+ %token <string> NAME
156
+ %token <string> STRING
157
+ %type <node> Root
158
+ %type <empty> OptS
159
+ %type <node> LocationPath
160
+ %type <node> AbsoluteLocationPath
161
+ %type <node> RelativeLocationPath
162
+ %type <node> Step
163
+ %type <node> AxisSpecifier
164
+ %type <string> AxisName
165
+ %type <node> NodeTest
166
+ %type <node> Predicates
167
+ %type <node> Predicate
168
+ %type <node> PredicateExpr
169
+ %type <node> AbbreviatedAbsoluteLocationPath
170
+ %type <node> AbbreviatedRelativeLocationPath
171
+ %type <string> AbbreviatedStep
172
+ %type <string> AbbreviatedAxisSpecifier
173
+ %type <node> Expr
174
+ %type <node> NumberLike
175
+ %type <node> PrimaryExpr
176
+ %type <node> FunctionCall
177
+ %type <node> Arguments
178
+ %type <node> ArgumentSet
179
+ %type <node> PrefixedName
180
+ %type <node> Argument
181
+ %type <node> UnionExpr
182
+ %type <node> PathExpr
183
+ %type <node> FunctionName
184
+ %type <node> FilterExpr
185
+ %type <node> OrExpr
186
+ %type <node> AndExpr
187
+ %type <node> EqualityExpr
188
+ %type <node> RelationalExpr
189
+ %type <node> AdditiveExpr
190
+ %type <node> MultiplicativeExpr
191
+ %type <node> UnaryExpr
192
+ %type <string> Literal
193
+ %type <node> Number
194
+ %type <node> simple_selector_anchor
195
+ %type <string> MultiplyOperator
196
+ %type <node> VariableReference
197
+ %type <node> NameTest
198
+ %type <string> NodeType
199
+ %type <string> UnprefixedName
200
+ %type <string> combinator
201
+ %type <node> possibly_empty_sequence
202
+ %type <string> keyword
203
+ %type <node> StringLike
204
+ %type <node> selectors_group
205
+ %type <node> QName
206
+ %type <string> NCName
207
+ %type <string> Prefix
208
+ %type <string> LocalPart
209
+ %type <node> attribute_extended_selector
210
+ %type <node> Ident
211
+ %type <node> universal
212
+ %type <node> selector
213
+ %type <node> namespace_prefix
214
+ %type <node> type_selector
215
+ %type <node> element_name
216
+ %type <node> simple_selector_sequence
217
+ %%
218
+
219
+ Root
220
+ : Expr OptS { answer($1); }
221
+ ;
222
+
223
+ LocationPath
224
+ : RelativeLocationPath %dprec 1
225
+ | AbsoluteLocationPath %dprec 2
226
+ | selectors_group %dprec 3
227
+ ;
228
+
229
+ AbsoluteLocationPath
230
+ : SLASH RelativeLocationPath { $$ = PREP_OP($1, $2); }
231
+ | SLASH { $$ = PXP($1); }
232
+ | AbbreviatedAbsoluteLocationPath
233
+ ;
234
+
235
+ RelativeLocationPath
236
+ : Step
237
+ | RelativeLocationPath SLASH Step { $$ = BIN_OP($1, $2, $3); }
238
+ | AbbreviatedRelativeLocationPath
239
+ ;
240
+
241
+ Step
242
+ : AxisSpecifier NodeTest { $$ = pxpath_cat_paths(2, $1, $2); }
243
+ | AxisSpecifier NodeTest Predicates { $$ = pxpath_cat_paths(3, $1, $2, $3); }
244
+ | AbbreviatedStep { $$ = PXP($1); }
245
+ ;
246
+
247
+ AxisSpecifier
248
+ : AxisName DBLCOLON { $$ = pxpath_new_path(2, $1, $2); }
249
+ | AbbreviatedAxisSpecifier { $$ = PXP($1); }
250
+ ;
251
+ AxisName
252
+ : XANCESTOR
253
+ | XANCESTORSELF
254
+ | XATTR
255
+ | XCHILD
256
+ | XDESC
257
+ | XDESCSELF
258
+ | XFOLLOW
259
+ | XFOLLOWSIB
260
+ | XNS
261
+ | XPARENT
262
+ | XPRE
263
+ | XPRESIB
264
+ | XSELF
265
+ ;
266
+
267
+ NodeTest
268
+ : NameTest
269
+ | NodeType LPAREN RPAREN { $$ = pxpath_new_path(3, $1, $2, $3); }
270
+ | XPI LPAREN Literal RPAREN { $$ = pxpath_new_path(4, $1, $2, $3, $4); }
271
+ ;
272
+
273
+ Predicates
274
+ : Predicates Predicate { $$ = pxpath_cat_paths(2, $1, $2); }
275
+ | Predicate
276
+ ;
277
+
278
+ Predicate
279
+ : LBRA PredicateExpr RBRA { $$ = PXPWRAP($1, $2, $3); }
280
+ ;
281
+
282
+ PredicateExpr
283
+ : Expr
284
+ ;
285
+
286
+ AbbreviatedAbsoluteLocationPath
287
+ : DBLSLASH RelativeLocationPath { $$ = PREP_OP($1, $2); }
288
+ ;
289
+
290
+ AbbreviatedRelativeLocationPath
291
+ : RelativeLocationPath DBLSLASH Step { $$ = BIN_OP($1, $2, $3); }
292
+ ;
293
+
294
+ AbbreviatedStep
295
+ : DOT
296
+ | DBLDOT
297
+ ;
298
+
299
+ AbbreviatedAxisSpecifier
300
+ : AT
301
+ | { $$ = ""; }
302
+ ;
303
+ Expr
304
+ : LPAREN Argument RPAREN %dprec 2 { $$ = PXPWRAP($1, $2, $3); }
305
+ | OrExpr %dprec 1
306
+ ;
307
+ PrimaryExpr
308
+ : VariableReference
309
+ | LPAREN Expr RPAREN { $$ = PXPWRAP($1, $2, $3); }
310
+ | Literal { $$ = LIT($1); }
311
+ | Number
312
+ | FunctionCall
313
+ ;
314
+
315
+ FunctionCall
316
+ : FunctionName LPAREN Arguments RPAREN { $$ = pxpath_new_func(xpath_alias(pxpath_to_string($1)), $3); }
317
+ ;
318
+ Arguments
319
+ : ArgumentSet
320
+ | { $$ = NULL; }
321
+ ;
322
+ ArgumentSet
323
+ : Argument COMMA ArgumentSet %dprec 2 { $$ = $1; $1->next = $3; }
324
+ | Argument %dprec 1
325
+ ;
326
+ Argument
327
+ : OptS Expr OptS { $$ = $2; }
328
+ ;
329
+ UnionExpr
330
+ : PathExpr
331
+ | UnionExpr PIPE PathExpr { $$ = BIN_OP($1, $2, $3); }
332
+ ;
333
+
334
+ PathExpr
335
+ : LocationPath
336
+ | FilterExpr
337
+ | FilterExpr SLASH RelativeLocationPath { $$ = BIN_OP($1, $2, $3); }
338
+ | FilterExpr DBLSLASH RelativeLocationPath { $$ = BIN_OP($1, $2, $3); }
339
+ ;
340
+
341
+ FilterExpr
342
+ : PrimaryExpr
343
+ | FilterExpr Predicates { $$ = pxpath_cat_paths(2, $1, $2); }
344
+ ;
345
+
346
+ OrExpr
347
+ : AndExpr
348
+ | OrExpr XOR AndExpr { $$ = LIT_BIN_OP($1, $2, $3); }
349
+ ;
350
+
351
+ AndExpr
352
+ : EqualityExpr
353
+ | AndExpr XAND EqualityExpr { $$ = LIT_BIN_OP($1, $2, $3); }
354
+ ;
355
+
356
+ EqualityExpr
357
+ : RelationalExpr
358
+ | EqualityExpr EQ RelationalExpr { $$ = LIT_BIN_OP($1, $2, $3); }
359
+ | EqualityExpr CXOPNE RelationalExpr { $$ = LIT_BIN_OP($1, $2, $3); }
360
+ ;
361
+
362
+ RelationalExpr
363
+ : AdditiveExpr %dprec 2
364
+ | RelationalExpr OptS LT OptS AdditiveExpr %dprec 3 { $$ = LIT_BIN_OP($1, $3, $5); }
365
+ | RelationalExpr OptS GT OptS AdditiveExpr %dprec 1 { $$ = LIT_BIN_OP($1, $3, $5); }
366
+ | RelationalExpr OptS LTE OptS AdditiveExpr %dprec 3 { $$ = LIT_BIN_OP($1, $3, $5); }
367
+ | RelationalExpr OptS GTE OptS AdditiveExpr %dprec 3 { $$ = LIT_BIN_OP($1, $3, $5); }
368
+ ;
369
+
370
+ AdditiveExpr
371
+ : MultiplicativeExpr %dprec 3
372
+ | AdditiveExpr OptS PLUS OptS MultiplicativeExpr %dprec 1 { $$ = LIT_BIN_OP($1, $3, $5); }
373
+ | AdditiveExpr OptS DASH OptS MultiplicativeExpr %dprec 2 { $$ = LIT_BIN_OP($1, $3, $5); }
374
+ ;
375
+
376
+ MultiplicativeExpr
377
+ : UnaryExpr %dprec 2
378
+ | MultiplicativeExpr OptS MultiplyOperator OptS UnaryExpr %dprec 2 { $$ = LIT_BIN_OP($1, $3, $5); }
379
+ | MultiplicativeExpr OptS XDIV OptS UnaryExpr %dprec 1 { $$ = LIT_BIN_OP($1, $3, $5); }
380
+ | MultiplicativeExpr OptS XMOD OptS UnaryExpr %dprec 2 { $$ = LIT_BIN_OP($1, $3, $5); }
381
+ ;
382
+
383
+ UnaryExpr
384
+ : UnionExpr
385
+ | DASH UnaryExpr { $$ = PREP_OP($1, $2); }
386
+ ;
387
+
388
+ Literal
389
+ : STRING
390
+ ;
391
+ Number
392
+ : NUMBER { $$ = LIT($1); }
393
+ | NUMBER DOT { $$ = pxpath_new_literal(2, $1, $2); }
394
+ | NUMBER DOT NUMBER { $$ = pxpath_new_literal(3, $1, $2, $3); }
395
+ | DOT NUMBER { $$ = pxpath_new_literal(2, $1, $2); }
396
+ ;
397
+
398
+ MultiplyOperator
399
+ : SPLAT
400
+ ;
401
+
402
+ VariableReference
403
+ : DOLLAR QName { $$ = PREP_OP($1, $2); }
404
+ ;
405
+
406
+ NameTest
407
+ : SPLAT { $$ = PXP($1); }
408
+ | NCName COLON SPLAT { $$ = pxpath_new_path(3, $1, $2, $3); }
409
+ | QName
410
+ ;
411
+
412
+ NodeType
413
+ : XCOMMENT
414
+ | XTEXT
415
+ | XPI
416
+ | XNODE
417
+ ;
418
+
419
+ FunctionName
420
+ : QName
421
+ ;
422
+
423
+ QName
424
+ : PrefixedName
425
+ | UnprefixedName { $$ = PXP($1); }
426
+ ;
427
+
428
+ PrefixedName
429
+ : Prefix COLON LocalPart { $$ = pxpath_new_path(3, $1, $2, $3); }
430
+ ;
431
+
432
+ UnprefixedName
433
+ : LocalPart
434
+ ;
435
+
436
+ Prefix
437
+ : NCName
438
+ ;
439
+
440
+ LocalPart
441
+ : NCName
442
+ ;
443
+
444
+ NCName
445
+ : NAME
446
+ | keyword
447
+ ;
448
+
449
+ selectors_group
450
+ : attribute_extended_selector COMMA OptS selectors_group { $$ = pxpath_cat_paths(4, pxpath_new_literal(1, ".//"), $1, pxpath_new_literal(1, "|"), $4); }
451
+ | attribute_extended_selector { $$ = pxpath_cat_paths(2, pxpath_new_literal(1, ".//"), $1); }
452
+ ;
453
+
454
+ attribute_extended_selector
455
+ : selector
456
+ | selector S AT NAME { $$ = pxpath_cat_paths(3, $1, PXP("/@"), PXP($4)); }
457
+ ;
458
+
459
+ selector
460
+ : simple_selector_sequence combinator selector { $$ = pxpath_cat_paths(3, $1, PXP($2), $3); }
461
+ | simple_selector_sequence
462
+ ;
463
+
464
+ combinator
465
+ : OptS PLUS OptS { $$ = "/following-sibling::*[1]/self::"; }
466
+ | OptS GT OptS { $$ = "/"; }
467
+ | OptS TILDE OptS { $$ = "/following-sibling::*/self::"; }
468
+ | S { $$ = "//"; }
469
+ ;
470
+
471
+ simple_selector_sequence
472
+ : simple_selector_anchor
473
+ | possibly_empty_sequence LBRA type_selector OptS CXOPHE OptS StringLike OptS RBRA { $$ = pxpath_cat_paths(10, $1, PXP("[@"), $3, PXP(" = "), $7, PXP(" or starts-with(@"), $3, PXP(", concat("), $7, PXP(", '-' ))]")); }
474
+ | possibly_empty_sequence CXNOT LPAREN selectors_group RPAREN { $$ = pxpath_cat_paths(5, PXP("set-difference("), $1, PXP(", "), $4, PXP(")")); }
475
+ | possibly_empty_sequence HASH Ident { $$ = P4E($1, "[@id='", $3, "']"); }
476
+ | possibly_empty_sequence DOT Ident { $$ = P4E($1, "[contains(concat( ' ', @class, ' ' ), concat( ' ', '", $3, "', ' ' ))]"); }
477
+ | possibly_empty_sequence LBRA type_selector RBRA { $$ = P4E($1, "[@", $3, "]"); }
478
+ | possibly_empty_sequence CXEQ LPAREN NumberLike RPAREN { $$ = P4E($1, "[position() = ", $3, "]"); }
479
+ | possibly_empty_sequence CXGT LPAREN NumberLike RPAREN { $$ = P4E($1, "[position() > ", $3, "]"); }
480
+ | possibly_empty_sequence CXLT LPAREN NumberLike RPAREN { $$ = P4E($1, "[position() < ", $3, "]"); }
481
+ | possibly_empty_sequence CXCONTAINS LPAREN StringLike RPAREN { $$ = P4E($1, "[contains(., ", $4, ")]"); }
482
+ | possibly_empty_sequence CXHAS LPAREN selectors_group RPAREN { $$ = P4E($1, "[", $3, "]"); }
483
+ | possibly_empty_sequence CXNTHTYPE LPAREN NumberLike RPAREN { $$ = P4E($1, "[position() = ", $3, "]"); }
484
+ | possibly_empty_sequence CXNTHLASTTYPE LPAREN NumberLike RPAREN { $$ = P4E($1, "[position() = last() - ", $3, "]"); }
485
+ | possibly_empty_sequence LBRA type_selector OptS EQ OptS StringLike OptS RBRA { $$ = P6E($1, "[@", $3, " = ", $7, "]"); }
486
+ | possibly_empty_sequence LBRA type_selector OptS CXOPNE OptS StringLike OptS RBRA { $$ = P6E($1, "[@", $3, " != ", $7, "]"); }
487
+ | possibly_empty_sequence LBRA type_selector OptS CXOPSTARTEQ OptS StringLike OptS RBRA { $$ = P6E($1, "[starts-with(@", $3, ", ", $7, ")]"); }
488
+ | possibly_empty_sequence LBRA type_selector OptS CXOPENDEQ OptS StringLike OptS RBRA { $$ = P6E($1, "[ends-with(@", $3, ", ", $7, ")]"); }
489
+ | possibly_empty_sequence LBRA type_selector OptS CXOPCONTAINS OptS StringLike OptS RBRA { $$ = P6E($1, "[contains(@", $3, ", ", $7, ")]"); }
490
+ | possibly_empty_sequence LBRA type_selector OptS CXOPCONTAINS2 OptS StringLike OptS RBRA { $$ = P6E($1, "[contains(@", $3, ", ", $7, ")]"); }
491
+ | possibly_empty_sequence CXNTHCH LPAREN NumberLike RPAREN { $$ = P4O("*[", $4, "]/self::", $1); }
492
+ | possibly_empty_sequence CXNTHLASTCH LPAREN NumberLike RPAREN { $$ = P4O("*[last() - ", $4, "]/self::", $1); }
493
+ | possibly_empty_sequence CXFIRST { $$ = APPEND($1, "[1]"); }
494
+ | possibly_empty_sequence CXLAST { $$ = APPEND($1, "[last()]"); }
495
+ | possibly_empty_sequence CXEVEN { $$ = APPEND($1, "[position() % 2 = 0]"); }
496
+ | possibly_empty_sequence CXODD { $$ = APPEND($1, "[position() % 2 = 1]"); }
497
+ | possibly_empty_sequence CXCONTENT LPAREN StringLike RPAREN { $$ = P4E($1, "[translate(normalize-space(.), $nbsp, ' ')=", $4, "]"); }
498
+ | possibly_empty_sequence CXHEADER { $$ = APPEND($1, "[contains('h1 h2 h3 h4 h5 h6', lower-case(local-name()))]"); }
499
+ | possibly_empty_sequence CXEMPTY { $$ = APPEND($1, "[not(node())]"); }
500
+ | possibly_empty_sequence CXPARENT { $$ = APPEND($1, "[node()]"); }
501
+ | possibly_empty_sequence CXFIRSTTYPE { $$ = APPEND($1, "[1]"); }
502
+ | possibly_empty_sequence CXLASTTYPE { $$ = APPEND($1, "[last()]"); }
503
+ | possibly_empty_sequence CXONLYTYPE { $$ = APPEND($1, "[count()=1]"); }
504
+ | possibly_empty_sequence CXINPUT { $$ = APPEND($1, "[lower-case(name())='input']"); }
505
+ | possibly_empty_sequence CXENABLED { $$ = APPEND($1, "[lower-case(name())='input' and not(@disabled)]"); }
506
+ | possibly_empty_sequence CXDISABLED { $$ = APPEND($1, "[lower-case(name())='input' and @disabled]"); }
507
+ | possibly_empty_sequence CXCHECKED { $$ = APPEND($1, "[@checked]"); }
508
+ | possibly_empty_sequence CXSELECTED { $$ = APPEND($1, "[@selected]"); }
509
+ | possibly_empty_sequence CXFIRSTCH { $$ = PREPEND($1, "*[1]/self::"); }
510
+ | possibly_empty_sequence CXLASTCH { $$ = PREPEND($1, "*[last()]/self::"); }
511
+ | possibly_empty_sequence CXONLYCH { $$ = PREPEND($1, "*[count()=1]/self::"); }
512
+ | possibly_empty_sequence CXTEXT { $$ = INPUT_TYPE($1, text); }
513
+ | possibly_empty_sequence CXPASSWORD { $$ = INPUT_TYPE($1, password); }
514
+ | possibly_empty_sequence CXRADIO { $$ = INPUT_TYPE($1, radio); }
515
+ | possibly_empty_sequence CXCHECKBOX { $$ = INPUT_TYPE($1, checkbox); }
516
+ | possibly_empty_sequence CXSUBMIT { $$ = INPUT_TYPE($1, submit); }
517
+ | possibly_empty_sequence CXIMAGE { $$ = INPUT_TYPE($1, image); }
518
+ | possibly_empty_sequence CXRESET { $$ = INPUT_TYPE($1, reset); }
519
+ | possibly_empty_sequence CXBUTTON { $$ = INPUT_TYPE($1, button); }
520
+ | possibly_empty_sequence CXFILE { $$ = INPUT_TYPE($1, file); }
521
+ ;
522
+
523
+ possibly_empty_sequence
524
+ : simple_selector_sequence
525
+ | { $$ = PXP("*"); }
526
+ ;
527
+
528
+ simple_selector_anchor
529
+ : type_selector
530
+ | universal
531
+ ;
532
+
533
+ type_selector
534
+ : namespace_prefix element_name { $$ = pxpath_cat_paths(3, $1, PXP(":"), $2); }
535
+ | element_name
536
+ ;
537
+
538
+ namespace_prefix
539
+ : SPLAT PIPE { $$ = PXP("*"); }
540
+ | Ident PIPE { $$ = $1; }
541
+ | PIPE { $$ = PXP("*"); }
542
+ ;
543
+
544
+ element_name
545
+ : Ident { $$ = $1; }
546
+ ;
547
+
548
+ universal
549
+ : namespace_prefix SPLAT { $$ = pxpath_cat_paths(3, $1, PXP(":"), PXP($2)); }
550
+ | SPLAT { $$ = PXP($1); }
551
+ ;
552
+
553
+ NumberLike
554
+ : NUMBER { $$ = PXP($1); }
555
+ ;
556
+
557
+ Ident
558
+ : NAME { $$ = PXP($1); }
559
+ | BSLASHLIT { $$ = PXP($1 + 1); }
560
+ | NAME Ident { $$ = pxpath_cat_paths(2, PXP($1), $2); }
561
+ | BSLASHLIT Ident { $$ = pxpath_cat_paths(2, PXP($1 + 1), $2); }
562
+ | keyword { $$ = PXP($1); }
563
+ ;
564
+
565
+ keyword
566
+ : XANCESTOR
567
+ | XANCESTORSELF
568
+ | XATTR
569
+ | XCHILD
570
+ | XDESC
571
+ | XDESCSELF
572
+ | XFOLLOW
573
+ | XFOLLOWSIB
574
+ | XNS
575
+ | XPARENT
576
+ | XPRE
577
+ | XPRESIB
578
+ | XSELF
579
+ | XOR
580
+ | XAND
581
+ | XDIV
582
+ | XMOD
583
+ | XCOMMENT
584
+ | XTEXT
585
+ | XPI
586
+ | XNODE
587
+ ;
588
+
589
+ StringLike
590
+ : Ident
591
+ | STRING { $$ = pxpath_new_literal(1, $1); }
592
+ ;
593
+
594
+ OptS
595
+ : S { $$ = 0; }
596
+ | { $$ = 0; }
597
+ ;
598
+
599
+ %%
600
+
601
+ char* xpath_alias(char* key) {
602
+ char* value = (char*) xmlHashLookup(alias_hash, key);
603
+ return value == NULL ? key : value;
604
+ }
605
+
606
+ void init_xpath_alias() {
607
+ alias_hash = xmlHashCreate(100);
608
+ xmlHashAddEntry(alias_hash, "html", "lib:html-document");
609
+ xmlHashAddEntry(alias_hash, "match", "regexp:match");
610
+ xmlHashAddEntry(alias_hash, "replace", "regexp:replace");
611
+ xmlHashAddEntry(alias_hash, "test", "regexp:test");
612
+ xmlHashAddEntry(alias_hash, "with-newlines", "lib:nl");
613
+ }
614
+
615
+ pxpathPtr myparse(char* string){
616
+ // start_debugging();
617
+ parsed_answer = NULL;
618
+ prepare_parse(string);
619
+ yyparse();
620
+ cleanup_parse();
621
+ return parsed_answer;
622
+ }
623
+
624
+ void answer(pxpathPtr a){
625
+ parsed_answer = a;
626
+ }
627
+
628
+ void start_debugging(){
629
+ yydebug = 1;
630
+ return;
631
+ }