Parse bare XPath node tests as child axes.

When parsing a bare node test such as "A" this is now parsed as following:

    (axis "child" (test nil "A"))

Instead of this:

    (test nil "A")

According to the XPath specification both are identical and this simplifies some
of the code in the XPath evaluator.
This commit is contained in:
Yorick Peterse committed 2014-07-28 00:34:26 +02:00
1 parent 1916799fef
commit 23de57a3a0
8 files changed
+179 -88

No files matched your search

+9 -2
View File
@@ -34,7 +34,7 @@ rule
;
expression
: node_test
: node_test_as_axis
| operator
| axis
| string
@@ -45,7 +45,7 @@ rule
;
path_member
: node_test
: node_test_as_axis
| axis
| call
;
@@ -66,6 +66,13 @@ rule
| T_SLASH path_member { s(:absolute_path, val[1]) }
;
# Whenever a bare test is used (e.g. just "A") this actually means "child::A".
# Handling this on lexer level requires a look-behind/look-ahead while solving
# this on evaluator level produces inconsistent/confusing code.
node_test_as_axis
: node_test { s(:axis, 'child', val[0]) }
;
node_test
: node_name { s(:test, *val[0]) }
| node_name predicate { s(:test, *val[0], val[1]) }