Commit Graph

684 Commits

Author SHA1 Message Date
Yorick Peterse f653203220 Tests for the Namespace class. 2014-08-07 20:02:56 +02:00
Yorick Peterse 8e8ea64206 Fixed serializing of elements to XML. 2014-08-06 00:04:42 +02:00
Yorick Peterse e0bbc81351 Added a very basic Namespace class. 2014-08-06 00:00:08 +02:00
Yorick Peterse d7df908649 Trimmed XML inspect values. 2014-08-05 23:57:12 +02:00
Yorick Peterse 26d4bdc5b1 Support for the XPath "self" axis. 2014-08-05 21:10:12 +02:00
Yorick Peterse 669ad25000 Corrected following-sibling spec description. 2014-08-05 19:28:47 +02:00
Yorick Peterse 8a9b26fa73 Basic support for the preceding-sibling xpath axis 2014-08-05 19:28:26 +02:00
Yorick Peterse e34a1ed481 Corrected specs for the "parent" xpath axis. 2014-08-05 19:26:01 +02:00
Yorick Peterse fc1d9776f3 Basic support for the XPath "preceding" axis. 2014-08-05 10:16:37 +02:00
Yorick Peterse 375f3d7870 Basic support for the XPath "parent" axis.
The usage of `parent::node()` is not yet supported.
2014-08-05 09:34:57 +02:00
Yorick Peterse c0a6610d65 Use has_parent? in on_axis_following_sibling. 2014-08-04 21:57:16 +02:00
Yorick Peterse a1f80b4995 Support for the "following-sibling" axis.
This also comes with some small cleanups regarding
XPath::Evaluator#node_matches?. This change removes the need to, every time,
also use can_match_node?() to prevent NoMethodError errors from popping up.
2014-08-04 21:51:51 +02:00
Yorick Peterse 57c0f4b35e Renamed `node` to `ast_node`.
This should make it a bit easier to understand what kind of data the variable is
holding.
2014-08-04 19:01:27 +02:00
Yorick Peterse 211caf00c6 Proper support for the XPath "following" axis. 2014-08-04 18:57:21 +02:00
Yorick Peterse 57fcbbd0fc Allow Document#each_node to skip child nodes.
Child nodes can be skipped by throwing :skip_children.
2014-08-04 10:00:32 +02:00
Yorick Peterse ef1ad5406a Don't yield indexes in Document#each_node.
These indexes won't be used so there's no point in yielding them.
2014-08-04 09:08:39 +02:00
Yorick Peterse 4dc85df4e7 Corrected the XPath "following" axis specs. 2014-08-03 22:14:44 +02:00
Yorick Peterse 5c23333f46 Traverse document nodes in document order.
The method Document#each_node now yields the nodes in the correct order.
2014-08-01 23:34:32 +02:00
Yorick Peterse 7fab231992 Unique spec node names for Document#each_node.
This makes it a little bit easier to see if the order is actually correct.
2014-08-01 22:09:08 +02:00
Yorick Peterse 8899542971 Better specs for Document#each_node. 2014-08-01 19:00:47 +02:00
Yorick Peterse c419d8849b Shift instead of pop nodes when yielding all nodes 2014-08-01 19:00:29 +02:00
Yorick Peterse 34e2d28bbd Document#all_nodes -> Document#each_node
This method has been renamed and now yields nodes and their indexes instead of
buffering them in a node set.
2014-07-31 18:57:05 +02:00
Yorick Peterse 4bbf0c98ae Use breadth-first-search for returning all nodes.
This still uses a stack but at least no longer relies on the call stack. I
decided not to go with the Morris in-order algorithm [1] as it modifies the tree
during a search. This would not work well if a document were to be accessed from
multiple threads at once (which should be possible for read-only operations).

I might change this method to actually perform a search (opposed to just
returning everything). This will require some closer inspection of the
available XPath axes to determine if this is needed.

Tests will also be added once I've taken care of the above.

[1]: http://en.wikipedia.org/wiki/Tree_traversal#Morris_in-order_traversal_using_threading
2014-07-30 22:27:09 +02:00
Yorick Peterse 8fe71f298b Half-assed way of retrieving all document nodes.
This currently only works for documents, is not tested and most likely will leak
memory due to being recursive.
2014-07-30 19:56:56 +02:00
Yorick Peterse 52a4375278 Prepare setup for *actual* following support.
The previous commit was nonsense as I didn't understand XPath's "following" axis
properly. This commit introduces proper tests and a note for future me so that I
can implement it properly.
2014-07-30 00:16:44 +02:00
Yorick Peterse 9a97d936e3 Support for the XPath "following" axis. 2014-07-29 23:09:16 +02:00
Yorick Peterse 023e7c6583 Spec for absolute XPath paths from elements. 2014-07-29 09:29:56 +02:00
Yorick Peterse 55e3388e30 Unfuck XPath axes evaluation.
The evaluation of axes has been fixed by changing the initial context as well as
the behaviour of some of the handler methods.

The initial context has been changed so that it's simply a NodeSet of whatever
the root object is, either a Document or an Element instance. Previously this
would be set to the child nodes of a Document in case the root object was a
Document. This in turn would prevent "child" axes from operating correctly.
2014-07-28 00:44:05 +02:00
Yorick Peterse 28f77b6d9b Corrected XPath attribute axis specs. 2014-07-28 00:43:52 +02:00
Yorick Peterse 23de57a3a0 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.
2014-07-28 00:34:26 +02:00
Yorick Peterse 1916799fef Basic boilerplate for descendant-or-self. 2014-07-25 21:24:39 +02:00
Yorick Peterse 766b35d9ce Specs for descendant-or-self. 2014-07-25 21:23:52 +02:00
Yorick Peterse 6e2be78546 Rewrote context names of some XPath specs. 2014-07-25 00:49:13 +02:00
Yorick Peterse cdf48979d5 Re-organized XPath axis evaluation specs. 2014-07-24 21:42:05 +02:00
Yorick Peterse dd37b028a0 Support for the XPath descendant axis. 2014-07-24 09:49:05 +02:00
Yorick Peterse 2ed7c457a5 Run tests in a random order. 2014-07-23 18:54:47 +02:00
Yorick Peterse fd37bcff1f Corrected an XPath example. 2014-07-23 18:48:53 +02:00
Yorick Peterse 1941b133ec Cleaned up the README requirements section. 2014-07-22 21:42:58 +02:00
Yorick Peterse 0eccbc145f Don't rely on GFM to automatically render links. 2014-07-22 21:32:07 +02:00
Yorick Peterse 57be239900 YARD CSS for blockquotes. 2014-07-22 21:31:31 +02:00
Yorick Peterse c12afdc477 Rake task for generating docs. 2014-07-22 21:29:16 +02:00
Yorick Peterse 54e109bf97 Corrected various YARD tags. 2014-07-22 21:28:44 +02:00
Yorick Peterse a0ecba6321 Support for the XPath child axis. 2014-07-22 21:25:02 +02:00
Yorick Peterse ec08b41737 Specs for various XPath::Evaluator helper methods. 2014-07-22 21:04:09 +02:00
Yorick Peterse 1f9d2ede95 Skip node matching for incompatible nodes. 2014-07-22 20:45:15 +02:00
Yorick Peterse 713d8a092b Rake task for displaying TODO/FIXME notes. 2014-07-22 16:38:05 +02:00
Yorick Peterse 05cf07755d Basic docs for the XPath evaluator. 2014-07-22 16:12:21 +02:00
Yorick Peterse 4142504101 Revert "Lex XPath axes without a node test."
Upon further investigation this change turned out to be useless. Nokogiri/libxml
does not allow the use of long axes without tests, instead it ends up
lexing/parsing such a value as a simple node test.

This reverts commit f699b0d097.
2014-07-22 15:53:00 +02:00
Yorick Peterse c43c38fab9 Emit node() calls for certain short axes.
An axes such as "." is the same as "self::node()". To simplify things on
parser/evaluator level we'll emit the corresponding tokens for a "node()"
function call for these axes.
2014-07-22 15:50:39 +02:00
Yorick Peterse f699b0d097 Lex XPath axes without a node test. 2014-07-20 07:57:45 +02:00