Yorick Peterse
365a9e9fa9
Replace (path) nodes with nested nodes
...
This changes the XPath AST so that every segment in a path (e.g.
foo/bar) is parsed as a child node of the node that precedes it. For
example, take the following expression:
foo/bar
This used to be parsed into the following AST:
(path
(axis "child" (test nil "foo"))
(axis "child" (test nil "bar")))
This is now parsed into the following AST:
(axis "child"
(test nil "foo")
(axis "child"
(test nil "bar")))
This new AST is much easier to deal with in the XPath::Compiler class,
especially when trying to ensure that each segment operates on the
correct input.
This commit also fixes parsing of type tests with predicates, such as:
comment()[10]
This used to throw a parser error.
2015-08-26 10:16:48 +02:00
Yorick Peterse
866044f94f
Removed useless block passes in the XPath compiler
2015-08-22 14:28:20 +02:00
Yorick Peterse
c5b30d1eae
Refactor XPath compiler support for predicates
...
Handling of predicates is delegated to 3 different methods:
* on_predicate_direct: for predicates such as foo[bar] and foo[x < y].
* on_predicate_temporary: for predicates that use the last() function
somewhere.
* on_predicate_index: for predicates that only contain a literal index,
foo[10] being an example.
This enables the compiler to use more optimized code depending on the
type of predicate while still being able to support last() and
position().
The code is currently still quite rough on the edges, this will be taken
care of in following commits.
2015-08-20 01:01:30 +02:00
Yorick Peterse
37ac844ebe
Fixed spec for sum() in a predicate
...
The return value of sum() should be used as a NodeSet index, not merely
just a truthy value.
2015-08-20 00:54:06 +02:00
Yorick Peterse
94ec1b5f5d
Corrected the last() compiler spec
...
This spec didn't match the correct nodes due to `1 < last()` always
evaluating to true in this particular case.
2015-08-20 00:23:58 +02:00
Yorick Peterse
7a4cb76d39
Cleaned up XPath last() specs a bit
2015-08-19 23:05:25 +02:00
Yorick Peterse
ee44907ca5
Started removing usage of backup_variable
...
This was a hack that never should've made it into the code in the first
place. This breaks some of the CSS specs, but this should be taken care
of when I refactor predicate support.
2015-08-19 20:14:24 +02:00
Yorick Peterse
15ecca4a64
Removed extra throw from following-sibling()
...
I can't quite recall why this throw was present in the Evaluator in the
first place, but removing it doesn't seem to break anything (in the
Evaluator). In fact, removing it actually fixes some of the CSS specs
that were broken when using the Compiler.
2015-08-19 20:14:24 +02:00
Yorick Peterse
d72f5eb07f
Removed left-over assignment
2015-08-19 20:14:24 +02:00
Yorick Peterse
f41f6ff0c8
Only wrap followed_by nodes in begin/end
2015-08-19 20:14:24 +02:00
Yorick Peterse
a661bf8c12
Predicate support for all on_call handlers
2015-08-19 20:14:24 +02:00
Yorick Peterse
a30cdba8d0
Fixed XPath compiler support for not()
2015-08-19 20:14:24 +02:00
Yorick Peterse
7cbc53c64e
XPath compiler support for not() in predicates
2015-08-19 20:14:24 +02:00
Yorick Peterse
8e60c69def
Added spec for not() in a predicate
2015-08-19 20:14:24 +02:00
Yorick Peterse
0dcee637d3
Added Ruby::Node#if_false
2015-08-19 20:14:24 +02:00
Yorick Peterse
4b50a161ed
Wrap all compiler assignments in begin/end
...
This is much safer than having to explicitly call "wrap" in a potential
large amount of places.
2015-08-19 20:14:24 +02:00
Yorick Peterse
aaba0049ab
Updated XPath compiler arity spec
2015-08-19 20:14:24 +02:00
Yorick Peterse
b217aab2cb
XPath compiler support for translate()
2015-08-19 20:14:24 +02:00
Yorick Peterse
106d83e780
XPath compiler support for sum()
2015-08-19 20:14:24 +02:00
Yorick Peterse
e7e5b123cf
XPath compiler support for substring()
2015-08-19 20:14:24 +02:00
Yorick Peterse
be05008be9
Added substring-after() spec for a predicate
2015-08-19 20:14:24 +02:00
Yorick Peterse
b60ed03bb4
Added substring-before() spec for a predicate
2015-08-19 20:14:24 +02:00
Yorick Peterse
32dba554d7
Ruby generator support for Ranges
2015-08-19 20:14:23 +02:00
Yorick Peterse
ec19875530
XPath compiler support for substring-before()
2015-08-19 20:14:23 +02:00
Yorick Peterse
eeab14af4d
XPath compiler support for substring-after()
2015-08-19 20:14:23 +02:00
Yorick Peterse
d6b3461a9a
XPath compiler support for string()
2015-08-19 20:14:23 +02:00
Yorick Peterse
728bd45e48
XPath compiler support for string-length()
2015-08-19 20:14:23 +02:00
Yorick Peterse
0e3451881b
Specs for contains/starts-with in a predicate
2015-08-19 20:14:23 +02:00
Yorick Peterse
37a410a012
XPath compiler support for starts-with()
2015-08-19 20:14:23 +02:00
Yorick Peterse
64d9ecfd53
XPath compiler support for number()
2015-08-19 20:14:23 +02:00
Yorick Peterse
58aa8f0833
Boolean support for Conversion.to_float
2015-08-19 20:14:23 +02:00
Yorick Peterse
43dab548e9
XPath compiler support for not()
2015-08-19 20:14:23 +02:00
Yorick Peterse
2585fbd0b7
XPath compiler support for normalize-space()
2015-08-19 20:14:23 +02:00
Yorick Peterse
e677a5abdf
XPath compiler support for namespace-uri()
2015-08-19 20:14:23 +02:00
Yorick Peterse
9cb589cb34
XPath compiler support for name()
2015-08-19 20:14:23 +02:00
Yorick Peterse
d408989499
Added expanded_name for Element and Attribute
2015-08-19 20:14:23 +02:00
Yorick Peterse
25e2f57a8d
XPath compiler support for local-name()
2015-08-19 20:14:23 +02:00
Yorick Peterse
49a7c2c782
Fixed incorrect spelling of "predicate"
2015-08-19 20:14:23 +02:00
Yorick Peterse
db93f845f3
Renamed on_predicate methods
...
This ensures they all start with "on_predicate".
2015-08-19 20:14:23 +02:00
Yorick Peterse
c026244f6e
XPath compiler support for id() in predicates
2015-08-19 20:14:23 +02:00
Yorick Peterse
49196c285f
XPath compiler support for lang()
2015-08-19 20:14:23 +02:00
Yorick Peterse
eb6cf68140
Tidied up YARD documentation of the XPath compiler
2015-08-19 20:14:23 +02:00
Yorick Peterse
54473d9865
Allow followed_by to take a block
...
This removes the need for a lot of local variables in the Compiler
class, at the cost of some extra indentation levels.
2015-08-19 20:14:22 +02:00
Yorick Peterse
7bcd462e22
XPath compiler support for id()
...
This has been largely ported over from the Evaluator implementation.
2015-08-19 20:14:22 +02:00
Yorick Peterse
2ff1f9ab4f
XPath compiler support for a bucket of functions
...
This includes the following functions:
* boolean()
* ceiling()
* floor()
* round()
* concat()
* contains()
* count()
2015-08-19 20:14:22 +02:00
Yorick Peterse
e3b45fddfc
to_float support for non String values
2015-08-19 20:14:22 +02:00
Yorick Peterse
f3f3c7d31c
Cleaned up literal usage in the XPath compiler
2015-08-19 20:14:22 +02:00
Yorick Peterse
44bd0751bc
Removed commented out code
...
Something something I should just get a decent debugging mode.
2015-08-19 20:14:22 +02:00
Yorick Peterse
e4e777ac4a
XPath compiler support for preceding-sibling
2015-08-19 20:14:22 +02:00
Yorick Peterse
7362a783b8
XPath compiler support for the preceding axis
2015-08-19 20:14:22 +02:00