Commit Graph

738 Commits

Author SHA1 Message Date
Yorick Peterse 448ff56e38 Fixed CSS eval specs for nth-(first|last)-of-type. 2014-11-15 18:27:26 +01:00
Yorick Peterse b464815577 Fixed AST generation for nth-(first|last)-of-type. 2014-11-15 18:27:15 +01:00
Yorick Peterse 9eead81a7c Fixed AST for :only-of-type 2014-11-15 18:08:26 +01:00
Yorick Peterse 1c301d40e2 Properly fixed AST for first-of-type/last-of-type
This requires keeping track of the current element being processed. This in turn
allows the usage of count() + preceding-sibling/following-sibling.
2014-11-15 17:58:56 +01:00
Yorick Peterse e559b4b89b Corrected :first-of-type eval spec. 2014-11-15 17:20:17 +01:00
Yorick Peterse f1d574f342 Evaluate XPath predicates for every context node.
Instead of evaluating a predicate once for all context nodes, they should
instead be evaluated separately per context node.
2014-11-15 00:31:44 +01:00
Yorick Peterse 6daa3e7a00 Reverted AST changes for first-of-type
Functions can't be used in combination with axes, so I'll just need to fix the
position() function to work properly.
2014-11-14 23:51:46 +01:00
Yorick Peterse 2d6a2be2e8 Revert "Fixed XPath AST for :last-of-type"
Axes can't be used in combination with functions.

This reverts commit b0b572a584.
2014-11-14 23:49:49 +01:00
Yorick Peterse 8f3553f8f1 Fixed eval specs of :first-of-type & :last-of-type 2014-11-14 23:27:52 +01:00
Yorick Peterse b0b572a584 Fixed XPath AST for :last-of-type
This should count following nodes, not merely the position.
2014-11-14 23:27:15 +01:00
Yorick Peterse 0128dc50ae Fixed CSS evaluation of :first-of-type
The old XPath "position() = 1" would work in Nokogiri due to the way they
retrieve descendants. In Oga however this would simply always return the first
node.

To fix this Oga now counts the amount of preceding siblings that match the same
full name.
2014-11-14 01:25:03 +01:00
Yorick Peterse e3a26c5d15 Allow querying of nodes using CSS. 2014-11-14 01:05:29 +01:00
Yorick Peterse 913eb6a15a Added various extra pseudos to the CSS spec. 2014-11-14 01:02:58 +01:00
Yorick Peterse d47ca19ffa Remaining CSS evaluation specs. 2014-11-14 00:24:54 +01:00
Yorick Peterse 518bedc3a1 CSS evaluator specs for :nth-of-type 2014-11-14 00:16:35 +01:00
Yorick Peterse abfe6e3d61 CSS evaluator specs for nth-last-of-type 2014-11-14 00:13:11 +01:00
Yorick Peterse c874ceabb9 CSS evaluator specs for :nth-last-child 2014-11-13 23:54:47 +01:00
Yorick Peterse 5964a2cda4 CSS evaluator specs for :nth-child(n) 2014-11-13 22:50:04 +01:00
Yorick Peterse 3237617bf5 CSS eval specs for various pseudo classes.
This includes the following pseudos:

* :empty
* :first-child
* :first-of-type
* :last-child
* :last-of-type
2014-11-13 10:10:31 +01:00
Yorick Peterse 19e9834583 Compare XPath benchmark blocks. 2014-11-13 01:18:16 +01:00
Yorick Peterse 01b88d8c68 Use correct root for preceding/following(-sibling)
This ensures these axes work correctly when scoped to a node instead of a
document.
2014-11-13 01:11:29 +01:00
Yorick Peterse 27ffa4d3d5 Added various failing following/preceding specs. 2014-11-13 01:11:13 +01:00
Yorick Peterse b0f6409d1e Wrap predicate nodes around others in CSS ASTs. 2014-11-13 00:47:26 +01:00
Yorick Peterse 97a9a11db1 Failing CSS evaluation specs for the axes.
These currently fail due to the ~ and + axes not being evaluated properly.
2014-11-12 23:38:17 +01:00
Yorick Peterse 817a5e075b Wrap predicate AST nodes _around_ other nodes.
This means that "foo[1]" uses this AST:

    (predicate (test nil "foo") (int 1))

Instead of this AST:

    (test nil "foo" (int 1))

This makes it easier for the XPath evaluator to process predicates correctly.
2014-11-12 22:59:38 +01:00
Yorick Peterse 24350fa457 Added various predicate specs for XPath axes. 2014-11-12 09:40:22 +01:00
Yorick Peterse c15604a86f CSS evaluator specs for IDs. 2014-11-11 00:21:28 +01:00
Yorick Peterse b9e1b51270 CSS evaluator specs for classes. 2014-11-11 00:18:44 +01:00
Yorick Peterse 43200238c5 CSS evaluator specs for predicates and operators. 2014-11-10 23:21:00 +01:00
Yorick Peterse d5002010fe Removed RSpec shared examples. 2014-11-10 00:06:26 +01:00
Yorick Peterse 1f855dc982 Rewrote CSS evaluator paths spec. 2014-11-09 23:51:23 +01:00
Yorick Peterse fb1927a7c7 Removed use of shared examples in Element specs. 2014-11-09 23:44:14 +01:00
Yorick Peterse ccbb19a42d Rewrote all XPath evaluator type specs. 2014-11-09 23:43:01 +01:00
Yorick Peterse c5c3c5dbc3 Rewrote all XPath evaluator type test specs. 2014-11-09 23:39:47 +01:00
Yorick Peterse ca5da3f9c9 Rewrote all XPath evaluator operator tests. 2014-11-09 23:31:05 +01:00
Yorick Peterse 28a1f1b8a9 Rewrote all XPath evaluator call specs. 2014-11-09 23:23:52 +01:00
Yorick Peterse 58209cbad0 Rewrote all XPath axis specs. 2014-11-09 22:53:47 +01:00
Yorick Peterse 5f13cc9d73 Rewrote XPath evaluator wildcards spec. 2014-11-09 18:56:49 +01:00
Yorick Peterse ceed3a6046 Rewrote XPath evaluator predicates spec. 2014-11-09 18:52:04 +01:00
Yorick Peterse 3893e56ca8 Rewrote XPath evaluator paths spec.
This is the first spec of many that will be re-written. Eventually this will
remove the need of the shared examples as well as removing lots of code
duplication and odd context blocks.
2014-11-09 18:47:20 +01:00
Yorick Peterse 857ac517d5 Added XML::NodeSet#==
This method can be used to compare two NodeSet instances. By using
XML::NodeSet#equal_nodes?() the need for exposing the "nodes" instance variable
is also removed.
2014-11-09 18:33:16 +01:00
Yorick Peterse 7e38e20586 Use "include" vs "return" in CSS path spec. 2014-11-07 09:28:18 +01:00
Yorick Peterse a15966b88f Use "descendant" in the CSS selector spec. 2014-11-05 00:50:09 +01:00
Yorick Peterse a586a512b8 Removed support for CSS such as "|X"
This expression could be used to get all elements that _don't_ have any
namespace. The problem is that this can't be expressed as just a node test,
instead the resulting XPath would have to look something like the following:

    X[local-name() = name()]

However, since the XPath predicates are already created for pseudo classes and
such, also injecting the above into it would be a real big pain. As such I've
decided not to support it.
2014-11-05 00:45:40 +01:00
Yorick Peterse 661741268a CSS parser tests for paths with namespaces. 2014-11-05 00:44:23 +01:00
Yorick Peterse 1c20ef52ae XPath idents can't start with a star.
That is, names such as "*foo" are not valid. This was most likely a typo in the
first place.
2014-11-05 00:38:17 +01:00
Yorick Peterse 61801fe562 Allow CSS identifiers to start with an underscore. 2014-11-05 00:37:40 +01:00
Yorick Peterse f1316c50fb Allow XPath idents to start with an underscore.
This is valid in XML so XPath should support it as well.
2014-11-05 00:35:47 +01:00
Yorick Peterse eb3a3e7630 Use the descendant axis for CSS selectors.
Instead of using "descendant-or-self" Oga will use "descendant". This ensures
that expressions such as "foo *" don't return a set also including the "foo"
element.

Nokogiri solves this problem in a somewhat different way by using //foo//* for
the CSS expression "foo *". While this works in Nokogiri the expression
"descendant-or-self::node()" is slow as a snail in Oga (due to its nature of
retrieving _all_ nodes first). By using "descendant" we can work around this
problem.
2014-11-05 00:22:09 +01:00
Yorick Peterse 602f2fe8bb Apply node() type tests to the document too.
When running XPath queries such as "self::node()" the result should be a set
containing the document itself. This in turn fixes expressions such as
descendant-or-self::node()/a.
2014-11-04 23:41:45 +01:00