Commit Graph

570 Commits

Author SHA1 Message Date
Yorick Peterse 5fde2f9092 Basic tests for the CSS transformer. 2014-10-16 10:25:30 +02:00
Yorick Peterse 48eb4f83df Lexing/parsing of CSS pseudos with ident arguments
This allows the lexing/parsing of expressions such as "html:lang(en)".
2014-10-15 09:42:26 +02:00
Yorick Peterse d9a4221a0a Remove :axis CSS node types.
The various axes are now simply their own node types.
2014-10-12 18:08:35 +02:00
Yorick Peterse ed0cd7826e Fixed precedence of ID/class CSS selectors 2014-10-07 23:05:34 +02:00
Yorick Peterse 91f9cc984b Parsing of pseudo classes without node tests. 2014-10-07 23:01:58 +02:00
Yorick Peterse a6b0bd96c8 Support for parsing CSS class/ID selectors. 2014-10-07 22:57:23 +02:00
Yorick Peterse 6792127600 Reworked CSS parser rules.
This includes better rules for parsing separate path members, pseudo class
arguments and some changes to remove all remaining parsing conflicts.
2014-10-07 22:47:47 +02:00
Yorick Peterse b40c0243ce Tighten up lexing of CSS predicates.
Operators can now only occur inside predicates and any whitespcae in these
predicates is ignored.
2014-10-07 22:17:04 +02:00
Yorick Peterse 625b9eeffd Lexing of CSS axes with surrounding whitespace. 2014-10-07 22:06:45 +02:00
Yorick Peterse 619c0bbc14 Emit tokens for whitespace in the CSS lexer. 2014-10-07 21:55:41 +02:00
Yorick Peterse 6e18287a1d Initial specs for parsing CSS IDs/classes. 2014-10-07 19:01:04 +02:00
Yorick Peterse 09315ea478 Test for operators inside CSS predicates. 2014-10-07 09:32:34 +02:00
Yorick Peterse 16d66a7eb6 Better parsing for the nth-child pseudo class.
This uses stricter (and more correct) rules in both the lexer and the parser.
The resulting AST has also received a small rework to make it more compact and
less confusing.
2014-10-06 23:52:46 +02:00
Yorick Peterse 60da2bdd3a Use RSpec.shared_example vs just shared_example. 2014-10-05 23:52:12 +02:00
Yorick Peterse d0a8a3b18c Basic support for parsing CSS pseudo classes.
This currently does not yet allow chained pseudo classes, nor does it allow for
pseudos such as nth-child(2n).
2014-10-05 23:46:41 +02:00
Yorick Peterse 50ee66419e Rename CSS "node operators" to "axes". 2014-10-05 23:33:46 +02:00
Yorick Peterse e1832adc97 Specs for parsing CSS node test wildcards. 2014-10-05 10:09:21 +02:00
Yorick Peterse 8fef62fca0 Support for parsing CSS operators. 2014-10-05 10:06:58 +02:00
Yorick Peterse 2dd148539d Parsing of CSS predicates.
This adds support for parsing expressions such as "foo[class]".
2014-10-05 09:32:21 +02:00
Yorick Peterse 665d5fe08c Added basic specs for the CSS parser. 2014-10-05 01:28:31 +02:00
Yorick Peterse cc3e752e1f Removed custom AST::Node class.
Since this class did nothing other than extend AST::Node we might as well use
the latter.
2014-10-02 22:49:29 +02:00
Yorick Peterse 331d70e832 Corrected docs of the parse() helper method. 2014-10-02 22:41:22 +02:00
Yorick Peterse 73c5dbe636 Basic setup for lexing CSS pseudo selectors.
This includes support for the crazy 2n+1 syntax you can use with selectors such
as :nth-child().

CSS selectors: doing what XPath already does using an even crazier syntax,
because screw you.
2014-09-28 22:38:25 +02:00
Yorick Peterse ea4a429430 Lexing of various CSS operators. 2014-09-28 22:38:25 +02:00
Yorick Peterse 059e797a42 Re-organized some of the CSS lexer tests. 2014-09-28 22:38:25 +02:00
Yorick Peterse 2ede705f1b Lexing of various primitive CSS tokens.
This includes brackes, commas, pipes (used for namespaces) and more.
2014-09-28 22:38:24 +02:00
Yorick Peterse aa60115c0a Basic boilerplate for lexing CSS selectors. 2014-09-28 22:38:24 +02:00
Yorick Peterse 0299ff1ea4 Support for Enumerator inputs in the XML lexer.
This fixes #48.
2014-09-28 22:27:30 +02:00
Yorick Peterse 5f7256eb8f Encode/decode XML entities.
When lexing XML entities such as & and < these sequences are now
converted into their "actual" forms. In turn, Oga::XML::Text#to_xml ensures they
are encoded when the method is called.

Performance wise this puts some strain on the lexer, for every T_TEXT/T_STRING
node now potentially has to have its content modified. In the benchmark
xml/lexer/string_average_bench.rb the average processing time is now about the
same as before the improvements made in
8db77c0a09. I was hoping that the lexer would
still be a bit faster, but alas this is not the case. Doing this in native code
would be a nightmare as C doesn't have a proper string replacement function. I'm
not old/sadistic enough to write on myself just yet.

This fixes #49
2014-09-28 21:53:25 +02:00
Yorick Peterse 3307e2f4d2 Remove source lines from parser error messages.
This was a gimmick in the first place. It doesn't work well with IO instances
(= requires re-reading of the input), the code was too complex and it wasn't
that useful in the end. Lets just get rid of it.

This fixes #53.
2014-09-25 22:58:06 +02:00
Yorick Peterse 75f4e81533 Use namespace_name in Attribute#to_xml
Instead of using `namespace.name` lets just use `namespace_name`. This fixes the
problem of serializing attributes where the namespace prefix is "xmlns" as the
namespace for this isn't registered by default.

This fixes #47.
2014-09-24 00:19:58 +02:00
Yorick Peterse 317b49bcf6 Implemented a basic SAX API.
This API is a little bit dodgy (similar to Nokogiri's API) due to the use of
separate parser and handler classes. This is done to ensure that the return
values of callback methods (e.g. on_element) aren't used by Racc for building
AST trees. This also ensures that whatever variables are set by the handler
don't conflict with any variables of the parser.

This fixes #42.
2014-09-16 14:30:46 +02:00
Yorick Peterse cdfeeed85f Provide somewhat more meaningful parser errors.
While still a bit cryptic this is probably as best as we can get it. An example:

    Oga.parse_xml("<namefoo:bar=\"10\"")

    parser.rb:116:in `on_error': Unexpected string on line 1: (Racc::ParseError)

    => 1: <namefoo:bar="10"

This fixes #43.
2014-09-16 01:09:06 +02:00
Yorick Peterse 32b11ef1e2 self-close certain XML/HTML elements.
When an XML element has no child nodes a self-closing tag is used. When parsing
documents/elements in HTML mode this is only done if the element is a so called
"void element" (e.g. <link> tags).

This fixes #46.
2014-09-16 00:44:38 +02:00
Yorick Peterse 6fc7e2e254 Track document types when parsing.
When parsing XML/HTML documents the corresponding document type (:html or :xml)
is stored in Document#type.
2014-09-16 00:25:51 +02:00
Yorick Peterse 9959f5cda4 Don't remove namespace attributes when registering
When registering namespaces from an attributes list the attributes should _not_
be removed.

This fixes #45.
2014-09-15 22:04:03 +02:00
Yorick Peterse 795e669632 Ignore default NS when serializing elements.
When a default namespace is set (using xmlns="...") the method
XML::Element#to_xml should _not_ include the namespace prefix in the output.
2014-09-15 21:42:08 +02:00
Yorick Peterse abbd8d6f84 Handle registering of default XML namespaces.
When the default namespace is registered (using xmlns="...") Oga now properly
sets the namespace of the container and all child elements.

This fixes #44.
2014-09-15 21:36:15 +02:00
Yorick Peterse ad2e040f05 Handle lexing of input such as just "</".
Previously this would cause the lexer to go in an infinite loop in the "text"
state machine.

This fixes #37.
2014-09-15 17:20:06 +02:00
Yorick Peterse b06eadc812 XPath support for absolute paths without tests.
This allows Oga to parse and evaluate the XPath expression "/". This expression
can be used to select just the root node/document.

This fixes #35.
2014-09-15 17:06:58 +02:00
Yorick Peterse 398aaf68bc Return a correct list of available namespaces.
This ensures that inner namespaces take precedence over outer namespaces.

Fixes #40.
2014-09-14 18:42:02 +02:00
Tero Tasanen 3c930433c4 Change Hash syntax to be consistent with other tests 2014-09-14 15:04:15 +03:00
Tero Tasanen d0f48e0e3c Added a lexer test case for uppercase void elements 2014-09-14 14:20:58 +03:00
Tero Tasanen 9c8dd60f92 Fix test cases
- Remove duplicate tests
- use parse_html helper
2014-09-14 14:14:51 +03:00
Tero Tasanen 9f71b1ec7b Ignore casing when testing for html void elements
Fixes #36
2014-09-14 12:02:02 +03:00
Yorick Peterse d082822cdc Removed the node_type method crap.
The logic this was used for now only resides in the pull parser, instead of
being exposed to the public.

This fixes #30.
2014-09-13 15:09:52 +02:00
Yorick Peterse b8a82b2094 Separate XML attributes by spaces.
This was originally reported by @jrochkind and partially patched by @billdueber.
My patches are built upon the latter, but without the need of using Array#map,
Array#join, etc. They also contain a few style changes.

This fixes #32 and #33.
2014-09-13 11:47:06 +02:00
Yorick Peterse 319d622fa5 Include namespaces when converting attrs to XML. 2014-09-11 14:03:04 +02:00
Yorick Peterse c45d32a37e Methods for adding attributes to elements.
The methods XML::Element#add_attribute and XML::Element#set can be used to more
easily add attributes to elements. The first method simply adds an Attribute
instance and links it to the element. This allows for fine grained control over
what data the attribute should contain. The second method ("set") simply sets an
attribute based on a name and value, optionally creating the attribute if it
doesn't already exist.
2014-09-10 23:55:29 +02:00
Yorick Peterse 6cb2d54875 Added XML::Element#inner_text=
This method can be used to more easily set the text of an element, without
having to manually muck around with XML::Text instances.
2014-09-10 23:25:39 +02:00
Yorick Peterse 6d19c9b311 Added XML::Element#get
This method can be used to directly retrieve an attribute value.
2014-09-10 19:03:32 +02:00
Yorick Peterse e2dab952d0 Added XML::Node#before and XML::Node#after
These methods can be used to insert nodes before/after other nodes without
manually having to mess around with node sets.

This fixes #28.
2014-09-09 22:48:31 +02:00
Yorick Peterse 98984de540 Moved Document#each_node into a separate module.
This allows it to be re-used by XML::Node.
2014-09-05 19:42:38 +02:00
Yorick Peterse bcdce306e5 Added NodeSet#concat.
This method allows two sets to be concatenated together without the need of
creating a 3rd node set (as is the case with NodeSet#+).
2014-09-05 10:07:22 +02:00
Yorick Peterse fbf3ae6e36 Manually increment XPath indexes.
This ensures that the index is only incremented for elements that match a node
test.
2014-09-03 23:56:13 +02:00
Yorick Peterse 81a62a6f00 Added XML::Attribute#text
This allows attributes to also be used for axes such as "=".
2014-09-03 23:38:00 +02:00
Yorick Peterse 9b8e9f49c6 Support for lexing empty attribute values.
This ensures that Oga can lex the following properly:

    <input value="" />

Previously Ragel would stop upon finding the empty string. This was caused due
to the string rules being declared as following:

    string_dquote = (dquote ^dquote+ dquote);
    string_squote = (squote ^squote+ squote);

These rules only match strings _with_ content, not without. Since Ragel stops
consuming input the moment it finds unhandled data this resulted in incorrect
tokens being emitted.
2014-09-03 23:10:50 +02:00
Yorick Peterse dc5874f5aa Show XML parsing errors when using IO as input.
Previously this wouldn't display anything due to the IO object being exhausted.
To fix this the input has to be wound back to the start, which means re-reading
it. Sadly I can't think of a way around this that doesn't require buffering
lines while parsing them (which massively increases memory usage).
2014-09-03 22:52:59 +02:00
Yorick Peterse bd31379c85 Fixed processing of nested predicates.
This ensures that nested predicates and functions that depend on predicates are
processed correctly.
2014-09-03 20:56:07 +02:00
Yorick Peterse 3196050978 Specs for nested predicates & self axis. 2014-09-03 20:55:55 +02:00
Yorick Peterse 2b96d65103 XPath "self" axis inside predicates.
The "self" axis should use the current context node when inside a predicate.
2014-09-03 09:40:17 +02:00
Yorick Peterse 71f2b42074 Convenience methods for parsing XML/HTML. 2014-09-03 09:31:48 +02:00
Yorick Peterse efc3827865 Extended the inline JS lexer spec. 2014-09-03 09:26:12 +02:00
Yorick Peterse 145315c26a Spec for inline JS and CDATA tags. 2014-09-03 00:34:10 +02:00
Yorick Peterse f268af5bc6 Fixed token position in the inline JS spec. 2014-09-03 00:30:27 +02:00
Yorick Peterse 868df603ab Added spec for inline JS + comments. 2014-09-03 00:26:45 +02:00
Yorick Peterse 07617a9c47 Failing spec for lexing inline Javascript. 2014-09-02 22:50:36 +02:00
Yorick Peterse 9649b50cc9 XML module for more easily querying using XPath. 2014-09-02 20:16:52 +02:00
Yorick Peterse ad34ab47a0 Support for binding/evaluating XPath variables. 2014-09-02 19:04:02 +02:00
Yorick Peterse 5a0e8c5480 Lexing/parsing of XPath variable references. 2014-09-02 10:52:08 +02:00
Yorick Peterse 5de37bdf81 Support for the XPath ">=" operator. 2014-09-01 22:45:01 +02:00
Yorick Peterse 099227901a Support for the XPath "<=" operator. 2014-09-01 22:40:50 +02:00
Yorick Peterse 6eacf74da4 Fixed comparing node equality in XPath expressions
Previously this would take the text of the entire node set, not of the first
node in the set.
2014-09-01 22:34:18 +02:00
Yorick Peterse 8884db8cb6 Support for the XPath ">" operator. 2014-09-01 22:23:35 +02:00
Yorick Peterse 6b45a03cb4 Support for the XPath "<" operator. 2014-09-01 22:20:32 +02:00
Yorick Peterse e1d9e62b72 Support for the XPath "!=" operator. 2014-09-01 20:48:11 +02:00
Yorick Peterse 9e5f15787d Support for the XPath "=" operator. 2014-09-01 18:57:12 +02:00
Yorick Peterse 1a6c0f0d35 Renamed various XPath operator specs. 2014-09-01 18:50:13 +02:00
Yorick Peterse a70645fb89 Support for the XPath sub/- operator. 2014-08-29 09:41:17 +02:00
Yorick Peterse 89686b6cff Support for the XPath mul/* operator. 2014-08-29 09:36:40 +02:00
Yorick Peterse 034b360d13 Support for the XPath "mod" operator. 2014-08-29 09:31:11 +02:00
Yorick Peterse 78c8cd1323 Support for the XPath "div" operator. 2014-08-28 23:05:12 +02:00
Yorick Peterse ced7f739fc Support for the XPath "add" / "+" operator. 2014-08-28 21:18:09 +02:00
Yorick Peterse 4fa40b58cf Support for the XPath "or" operator. 2014-08-28 21:01:12 +02:00
Yorick Peterse 4f189d9218 Support for the XPath "and" operator. 2014-08-28 09:42:55 +02:00
Yorick Peterse 809ed9bfa6 Handle boolean values in the boolean() function. 2014-08-28 09:36:21 +02:00
Yorick Peterse 543112dcdc Support for the XPath round() function. 2014-08-28 00:00:25 +02:00
Yorick Peterse a2b8e3c954 Support for the XPath ceiling() function. 2014-08-27 23:56:43 +02:00
Yorick Peterse c8fb1ad202 Support for the XPath floor() function. 2014-08-27 23:52:23 +02:00
Yorick Peterse 27d2b6c2c3 number() spec for converting empty strings. 2014-08-27 23:52:12 +02:00
Yorick Peterse 7c68f2a49b Raise for non node sets in the sum() function.
According to the XPath spec this function *can only* take node sets, nothing
else. Lets actually enforce that.
2014-08-27 23:47:19 +02:00
Yorick Peterse ac06670c24 Better conversion of types to numbers.
The XPath number() function should also be capable of converting booleans to
numbers, something it previously was not able to do. In order to do this
reliably we can't rely on the string() function as this would make it impossible
to distinguish between literal string values and booleans. This is due to
true(), which returns a TrueClass, being converted to the string "true". This
string in turn can't be converted to a float.
2014-08-27 23:38:47 +02:00
Yorick Peterse fcb28d5ae8 Specs for various XPath evaluator helper methods. 2014-08-27 23:37:12 +02:00
Yorick Peterse 022d8e0ada Extra test for sum() for default return values. 2014-08-27 23:07:38 +02:00
Yorick Peterse 30a5d01ebd Support for the XPath sum() function. 2014-08-27 23:05:04 +02:00
Yorick Peterse 585b3535b2 Support for the XPath lang() function. 2014-08-27 20:26:27 +02:00
Yorick Peterse 7c41fa814f Default attribute namespaces.
When an attribute is prefixed with "xml" the default namespace should be used
automatically. This namespace is not registered on element level by default as
this namespace isn't registered manually, instead it's a "magic" namespace. This
also ensures we match the behaviour of libxml more closely, hopefully reducing
confusion.
2014-08-27 20:24:40 +02:00
Yorick Peterse d2f991538d Support for the XPath true()/false() functions. 2014-08-27 09:37:28 +02:00
Yorick Peterse 4ef79bad90 Support for the XPath not() function. 2014-08-27 09:35:02 +02:00
Yorick Peterse e288ab88f5 Support for the XPath boolean() function. 2014-08-26 20:22:28 +02:00
Yorick Peterse 564f8859a0 Better XPath evaluation tests for numbers. 2014-08-26 20:22:18 +02:00
Yorick Peterse bcd138a15a Lexing of explicit negative/positive XPath numbers 2014-08-26 20:21:30 +02:00
Yorick Peterse 8295fa5783 Support for the XPath translate() function. 2014-08-26 18:14:44 +02:00
Yorick Peterse 7f3f626744 Support for the XPath normalize-space() function. 2014-08-26 00:06:58 +02:00
Yorick Peterse 06bed1cfdd Support for the XPath string-length() function. 2014-08-25 23:46:18 +02:00
Yorick Peterse a60057db5c Proper handling of decimals for string() calls.
When calling the string() XPath function floats with zero decimals (10.0, 5.0,
etc) should result in a string without any decimals. Ruby converts 10.0 to
"10.0" whereas XPath expects "10".
2014-08-25 23:21:36 +02:00
Yorick Peterse 6c0c5ab720 Revert "Return XPath integers as actual integers."
The particular case of string(10) having to return "10" instead of "10.0" will
be handled separately. Returning integers breaks behaviour/expectations
elsewhere.

This reverts commit 431a253000.
2014-08-25 23:14:22 +02:00
Yorick Peterse a1a2190fe2 Support for the XPath substring() function. 2014-08-25 23:13:34 +02:00
Yorick Peterse 5382891106 Support for the XPath number() function. 2014-08-25 23:13:03 +02:00
Yorick Peterse b2ca18e127 Support for the XPath substring-after() function. 2014-08-25 22:19:13 +02:00
Yorick Peterse b9cdb4a72b Support for the XPath substring-before() function. 2014-08-25 22:11:05 +02:00
Yorick Peterse 83b873e3c1 Support for the XPath contains() function. 2014-08-25 21:52:33 +02:00
Yorick Peterse 5b65d6c31a Support for the xpath starts-with() function. 2014-08-25 09:43:06 +02:00
Yorick Peterse 276a5ab83b Support for lexing empty XPath strings. 2014-08-25 09:42:51 +02:00
Yorick Peterse b688c6dc1b Support for the XPath concat() function. 2014-08-23 20:24:18 +02:00
Yorick Peterse 431a253000 Return XPath integers as actual integers.
This is to ensure that calls such as string(10) return "10" and not "10.0". It
also saves integer -> float conversions when they're not needed.
2014-08-23 20:22:58 +02:00
Yorick Peterse b316fd3e1c Support for the XPath string() function. 2014-08-22 11:06:10 +02:00
Yorick Peterse ff8a4ad3aa Ignore comment nodes in NodeSet#text. 2014-08-22 11:05:39 +02:00
Yorick Peterse 99be3182ae Support for evaluating XPath floats. 2014-08-22 10:59:03 +02:00
Yorick Peterse 6ac3408a71 Match all node types when using node()
Previously this would only match element and text nodes.
2014-08-22 10:58:36 +02:00
Yorick Peterse da09f1296c Support for using namespace-uri() with attributes. 2014-08-21 22:36:18 +02:00
Yorick Peterse 0d41693bfc Support for using name() with attributes. 2014-08-21 21:05:06 +02:00
Yorick Peterse acc056eea4 Support for using local-name() on attributes. 2014-08-21 21:03:28 +02:00
Yorick Peterse 1dd6416bea Basic support for the XPath name() function. 2014-08-21 20:47:20 +02:00
Yorick Peterse 8cc0db2283 Support for the XPath namespace-uri() function. 2014-08-21 19:02:41 +02:00
Yorick Peterse 9e20b5ca3e Support for the XPath local-name() function. 2014-08-21 10:21:02 +02:00
Yorick Peterse 2deb7a6d84 Support for the XPath id() function.
This comes with the limitation that it *always* uses the "id" attribute. This is
due to Oga not supporting DTD parsing/evaluation.
2014-08-20 21:06:35 +02:00
Yorick Peterse d351bc26cc Support for the XPath count() function. 2014-08-20 10:16:06 +02:00
Yorick Peterse 709fa365e0 XPath support for last() + evaluator docs.
I really dislike using a stack as it introduces an internal state. Sadly there
doesn't seem to be an easy way around this.
2014-08-19 22:59:26 +02:00
Yorick Peterse 423af37422 Basic support for the XPath last() function. 2014-08-18 19:00:32 +02:00
Yorick Peterse 2817784e6b Support for the XPath pipe operator. 2014-08-17 22:04:08 +02:00
Yorick Peterse d1735750c1 Only store unique nodes in XML::NodeSet.
It's called a "set" after all.
2014-08-17 22:03:44 +02:00
Yorick Peterse bb503728af XPath support for processing instructions. 2014-08-16 22:37:57 +02:00
Yorick Peterse 0d7609da88 Support for parsing XML processing instructions. 2014-08-15 22:23:26 +02:00
Yorick Peterse 8f4eaf3823 Lexing of XML processing instructions. 2014-08-15 22:04:45 +02:00
Yorick Peterse ccd95d69d8 Support for the XPath comment() test. 2014-08-15 20:49:13 +02:00
Yorick Peterse 4e8cca258c Fixed lexing of XML CDATA tags. 2014-08-15 20:47:58 +02:00
Yorick Peterse 81edce2eb8 Fixed lexing of XML comments.
The previous setup would consume too much. For example the following HTML:

    <a><!--foo--><b><!--bar--></b></a>

would result in the following T_COMMENT token:

    "foo--><b><!--bar"

The new setup requires the marking of a start position. I'm not a huge fan of
this but there doesn't appear to be a way around this.
2014-08-15 20:42:32 +02:00
Yorick Peterse 4d7f224892 Support for the XPath text() type test. 2014-08-15 10:46:00 +02:00
Yorick Peterse 14aa420091 Use a new base class for XML text nodes.
The classes Text, Cdata and Comment now extend CharacterData instead of Text.
2014-08-15 10:43:16 +02:00
Yorick Peterse 24bc84e15e Added XML::Element#text_nodes.
This method returns all the text nodes directly nested in an element.
2014-08-15 10:07:49 +02:00
Yorick Peterse d0092b434d Removed Document#available_namespaces.
Namespaces aren't scoped per document but instead per element, thus this method
doesn't make that much sense. This also fixes the remaining, failing XPath test.
2014-08-14 23:12:33 +02:00
Yorick Peterse d34e4697de Match node types in node_matches?
The method XPath::Evaluator#node_matches? now has a special case to handle
"type-test" nodes. This in turn fixes a bunch of failing tests such as those for
the XPath query "parent::node()".
2014-08-14 22:54:19 +02:00
Yorick Peterse a437d67573 Renamed node_type to type_test. 2014-08-14 22:35:41 +02:00
Yorick Peterse 05f6fc2f8d Implement node() as a type test, not a function. 2014-08-14 22:30:14 +02:00
Yorick Peterse 6ad5170476 Support for lexing/parsing XPath type tests.
Unlike what I thought before syntax such as "node()" is not a function call.
Instead this is a special node test that tests the *types* of nodes, not their
names.
2014-08-14 21:51:58 +02:00
Yorick Peterse 23441bb5a4 Basic support for the XPath node() function. 2014-08-14 18:17:08 +02:00
Yorick Peterse f2fe2a4b47 Failing XPath spec for double slashes.
The lexer doesn't lex things correctly due to "//" and "/" both being separate
rules. As a result the lexer emits two T_SLASH tokens for queries such as
".//foo".
2014-08-13 00:37:12 +02:00
Yorick Peterse f4ae83498e Eval specs for the self axis short form. 2014-08-11 09:35:01 +02:00
Yorick Peterse ffcefa92a7 Eval specs for the descendant-or-self short axis.
This currently fails due to the node() function not being implemented just yet.
2014-08-11 09:33:09 +02:00
Yorick Peterse aef3e0f27e Evaluator specs for the attribute axis short form. 2014-08-11 09:32:45 +02:00
Yorick Peterse 4d956c9ef0 Support for the XPath "namespace" axis. 2014-08-11 00:58:57 +02:00
Yorick Peterse 873bd82273 Stricted matching of namespaced elements. 2014-08-11 00:47:07 +02:00
Yorick Peterse 78da274452 Updated XPath specs for better namespace handling. 2014-08-11 00:42:06 +02:00
Yorick Peterse 33c28f633b Proper namespace support for elements.
This is still a bit rough on the edges but already way better than the broken
setup I had before.
2014-08-11 00:41:36 +02:00
Yorick Peterse 04cbbdcf9e Proper namespace support for attributes.
This separates namespace handling into namespace names and namespace objects.
The namespace objects are retrieved from the element an attribute belongs to.
Once retrieved the namespace is cached, due to the overhead of retrieving
namespaces in large documents.
2014-08-11 00:40:17 +02:00
Yorick Peterse fe8f77cf45 Basic work for supporting namespace URIs. 2014-08-08 19:03:42 +02:00
Yorick Peterse f002061aaa Extra type validation for XML::Element options. 2014-08-07 21:10:01 +02:00
Yorick Peterse b1388ff84a Ripped out inspect fuckery.
The old code used for generating Object#inspect values has been ripped out (for
the most part). The result is a non indented but far more compact #inspect
output. The code for this is also easier and doesn't break the signature of
Object#inspect.
2014-08-07 21:09:10 +02:00
Yorick Peterse 798372d099 Test for element attributes without namespaces. 2014-08-07 20:18:02 +02:00
Yorick Peterse 3b2279e410 Don't create empty Namespace nodes. 2014-08-07 20:16:46 +02:00
Yorick Peterse 97e59fe449 Use the Namespace class for namespaces vs Strings. 2014-08-07 20:03:26 +02:00
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 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 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 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 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 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 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 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 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 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
Yorick Peterse 488000438b Support for querying attributes using XPath. 2014-07-20 07:47:01 +02:00
Yorick Peterse d5569ead0b Use XML::Attribute for element attributes.
Instead of using a raw Hash Oga now uses the XML::Attribute class for storing
information about element attributes.

Attributes are stored as an Array of XML::Attribute instances. This allows the
attributes to be more easily modified. If they were stored as a Hash you'd not
only have to update the attributes themselves but also the Hash that contains
them.

While using an Array has a slight runtime cost in most cases the amount of
attributes is small enough that this doesn't really pose a problem. If webscale
performance is desired at some point in the future Oga could most likely cache
the lookup of an attribute. This however is something for the future.
2014-07-20 07:29:37 +02:00
Yorick Peterse ad4d7a4744 Rewrote an attribute spec.
This way the spec doesn't depend on the attributes object being a Hash.
2014-07-19 21:07:11 +02:00
Yorick Peterse ce86785da6 Added the XML::Attribute class.
This class will replace the use of raw Hash/String values for attributes in
upcoming commits.
2014-07-16 10:08:11 +02:00
Yorick Peterse e0544959ee Specs for the ancestor-or-self axis. 2014-07-15 09:37:47 +02:00
Yorick Peterse 9a8f53bb49 Use a shared example in the axes evaluation specs. 2014-07-15 09:35:13 +02:00
Yorick Peterse 580856dcf7 Cleaned up XPath specs using a shared example. 2014-07-15 09:34:11 +02:00
Yorick Peterse 30bbd2378e Basic specs for the "ancestor" axis. 2014-07-14 00:11:03 +02:00
Yorick Peterse 56982dd543 Fail early when processing (test) nodes.
If a certain segment yields no nodes the on_path() method should not process any
following segments.
2014-07-12 00:22:18 +02:00
Yorick Peterse be4f4ad744 Trimmed the XPath AST even further.
The excessive use of (path) nodes has been dropped and all parsing conflicts
have been dealt with.
2014-07-12 00:13:25 +02:00
Yorick Peterse c89fb571db Fixed typo in the XPath evaluator's wildcard spec. 2014-07-10 10:02:21 +02:00
Yorick Peterse a61540cfc5 XPath specs for wildcard names + namespaces. 2014-07-09 23:55:09 +02:00
Yorick Peterse 8fbc582547 XPath evaluation for name/namespace wildcards. 2014-07-09 22:09:20 +02:00
Yorick Peterse ed45058983 Basic support for evaluating XPath wildcards. 2014-07-09 20:06:31 +02:00
Yorick Peterse f660b11e47 Parsing of closing XML nodes with namespaces. 2014-07-09 19:54:45 +02:00
Yorick Peterse 9c661e1e60 Added XML::NodeSet#+ and XML::NodeSet#to_a 2014-07-08 23:25:09 +02:00
Yorick Peterse 54f0355ea9 Basic specs for XPath::Evaluator.
These currently only cover very simple XPath expressions.
2014-07-08 09:40:06 +02:00
Yorick Peterse 8b381ac970 Added Node#remove.
This method can be used to remove individual nodes without first having to
retrieve the NodeSet they are stored in.
2014-07-04 10:26:41 +02:00
Yorick Peterse e334e50ca6 Added Node#previous_element and Node#next_element.
These methods can be used similar to #previous and #next expect that they only
return Element instances opposed to all Node instances.
2014-07-04 10:18:18 +02:00
Yorick Peterse 94965961ce Added XML::Element#inner_text.
This method can be used to retrieve the text of the given node only. In other
words, unlike Element#text it does not contain the text of any child nodes.
2014-07-04 09:50:47 +02:00
Yorick Peterse 8f2ecf62c6 Specs for XML::Element#text. 2014-07-04 09:45:16 +02:00
Yorick Peterse a15c19c4af Retrieving root nodes using Node#root_node.
This method uses a loop to traverse upwards the DOM tree in order to find the
root document/element. While this might have an impact on performance I don't
expect Oga itself to call this method very often. The benefit is that Node
instances don't require users to manually pass the top level document as an
argument.
2014-07-03 00:26:15 +02:00
Yorick Peterse e69fbc3ea7 Remove ownership when using NodeSet#delete. 2014-07-01 10:15:39 +02:00
Yorick Peterse 4b408eae4f Tests for Node#children=. 2014-07-01 10:09:42 +02:00
Yorick Peterse 75e96ee779 Test for Document#children= with a NodeSet. 2014-07-01 10:07:35 +02:00
Yorick Peterse 30845e3d65 Reliably remove nodes from owned sets.
The combination of iterating over an array and removing values from it results
in not all elements being removed. For example:

    numbers = [10, 20, 30]

    numbers.each do |num|
      numbers.delete(num)
    end

    numbers # => [20]

As a result of this the NodeSet#remove method uses two iterations:

1. One iteration to retrieve all NodeSet instances to remove nodes from.
2. One iteration to actually remove the nodes.

For the second iteration we iterate over the node sets and then over the nodes.
This ensures that we always remove all nodes instead of leaving some behind.
2014-07-01 09:57:43 +02:00
Yorick Peterse 8314d24435 First pass at using the NodeSet class.
The documentation still leaves a lot to be desired and so does the API. There
also appears to be a problem where NodeSet#remove doesn't properly remove all
nodes from a set. Outside of that we're making slow progress towards a proper
DOM API.
2014-06-30 23:03:48 +02:00
Yorick Peterse e71fe3d6fa Indexing of NodeSet instances.
Similar to arrays the NodeSet class now allows one to retrieve nodes for a
given index.
2014-06-29 23:59:27 +02:00
Yorick Peterse d2e74d8a0b Specs for the NodeSet class. 2014-06-26 19:52:03 +02:00
Yorick Peterse 21a0f50457 Added groups for code coverage results. 2014-06-23 09:43:41 +02:00
Yorick Peterse c840a33667 Extra tests for parsing XPath function calls. 2014-06-23 09:37:26 +02:00
Yorick Peterse d2f15e37d0 Corrected XPath operator precedence.
The previous commit didn't fully change the operator precedence according to
the XPath 1.0 specification. Also thanks to @whitequark for clearing up a few
things about Racc's operator precedence system.
2014-06-23 00:30:42 +02:00
Yorick Peterse a440d3f003 Fixed XPath operator precedence.
Apparently using multiple `left` rules with T_AND and T_OR being separate
solves this problem. Riiiiight....
2014-06-23 00:15:43 +02:00
Yorick Peterse 6a2f4fa82d Parsing support for more XPath operators.
This still messes up some tests due to botched token precedence (by the looks
of it).
2014-06-22 21:27:53 +02:00
Yorick Peterse 514c342cab Lex wildcards as T_IDENT instead of T_STAR. 2014-06-20 20:37:34 +02:00
Yorick Peterse 497f57ccd2 Basic parser setup for XPath function calls. 2014-06-17 19:57:17 +02:00
Yorick Peterse 894de7f909 Lex all XPath expressions in a single machine.
This allows literal values such as strings and numbers to be used as function
arguments.
2014-06-17 19:56:57 +02:00
Yorick Peterse bb7af98257 Updated used ASTs for all XPath parser specs. 2014-06-17 18:51:33 +02:00
Yorick Peterse 2298ef618b Reworked handling of relative vs absolute XPaths. 2014-06-16 20:19:39 +02:00
Yorick Peterse a733869f53 Use (name) nodes for @foo axes. 2014-06-13 18:00:55 +02:00
Yorick Peterse ce23cce9bd Added XPath parser specs for all axes. 2014-06-13 16:20:53 +02:00
Yorick Peterse 3ff9057858 Renamed the XPath axes_spec file. 2014-06-13 09:32:46 +02:00
Yorick Peterse f557aaef76 Lexer specs for the various XPath axes. 2014-06-13 00:16:40 +02:00
Yorick Peterse eba2d9954d Support for parsing basic XPath expressions. 2014-06-12 00:20:46 +02:00
Yorick Peterse 70f3b7fa92 Lex XPath operators using individual tokens.
Instead of lexing every operator as T_OP they now use individual tokens such as
T_EQ and T_LT.
2014-06-09 23:35:54 +02:00
Yorick Peterse 114bc0d6e8 Upgrade to RSpec 3.0.
For this I've enabled both the old expectation and stubbing/mocking syntax. The
old syntax is much more compact and to me reads nicer. For example, consider
the following:

    lex('<foo></foo>').should == [...]

To me this reads much nicer than this:

    expect(lex('<foo></foo>')).to eq([...])
2014-06-02 12:09:38 +02:00
Yorick Peterse e11b9ed32c Basic XPath parser setup. 2014-06-01 23:02:28 +02:00
Yorick Peterse 54de2df0c7 Support for lexing XPath wildcard expressions.
To support this we need to require whitespace around the "*" operator. This is
not ideal but it will do for now.
2014-06-01 23:01:24 +02:00
Yorick Peterse b7855c124f XPath lexer test for predicates using axes. 2014-06-01 19:49:37 +02:00
Yorick Peterse 88b06e247d Added a few more XPath lexer tests. 2014-06-01 19:43:36 +02:00
Yorick Peterse 8dd8d7a519 Basic working XPath lexer.
This doesn't lex everything of the XPath specification just yet and needs more
tests.
2014-06-01 19:24:35 +02:00
Yorick Peterse 28edc7726f Rewind IO input upon resetting the lexer. 2014-05-26 00:33:20 +02:00
Yorick Peterse 629dcd3fe6 Support for IO inputs in the lexer.
Using IO/StringIO objects one can parse large XML files without first having to
read the entire file into memory. This can potentially save a lot of memory at
the cost of a slightly slower runtime.

For IO like instances the lexer will consume the input line by line. If a
String is given it's consumed as a whole instead. A small side effect of
reading the input line by line is that text such as "foo\nbar" will be lexed as
two tokens instead of one.

Fixes #19.
2014-05-26 00:30:39 +02:00
Yorick Peterse c56b0395e4 Moved various rules around for the XML lexer.
This moves the element related rules to the element_head machine (where they
belong). This in turn makes it possible to lex ">" as a text node, previously
this was impossible.
2014-05-21 00:04:53 +02:00
Yorick Peterse cd0f3380c4 Merge multiple CDATA tokens into a single token.
The tokens T_CDATA_START, T_TEXT and T_CDATA_END have been merged together into
T_CDATA.
2014-05-19 09:36:19 +02:00
Yorick Peterse a4fb5c1299 Merge multiple comment tokens into a single one.
The tokens T_COMMENT_START, T_TEXT and T_COMMENT_END have been merged into a
single token: T_COMMENT. This simplifies both the lexer and the parser.
2014-05-19 09:30:30 +02:00
Yorick Peterse 723a273e4f Enforce symbols for element attributes.
This comes with a little bit of memory overhead but this should be minor in
most cases.
2014-05-15 01:04:26 +02:00
Yorick Peterse 19f04f98f7 Support for lexing/parsing inline doctypes. 2014-05-10 00:28:11 +02:00
Yorick Peterse 83f6d5437e Contextual pull parsing.
This adds the ability to more easily act upon specific node types and nestings
when using the pull parsing API.

A basic example of this API looks like the following (only including relevant
code):

    parser.parse do |node|
      parser.on(:element, %w{people person}) do
        people << {:name => nil, :age => nil}
      end

      parser.on(:text, %w{people person name}) do
        people.last[:name] = node.text
      end

      parser.on(:text, %w{people person age}) do
        people.last[:age] = node.text.to_i
      end
    end

This fixes #6.
2014-04-29 23:05:49 +02:00
Yorick Peterse 1a413998a3 Track the current node in the pull parser.
The current node is tracked in the instance method `node`.
2014-04-29 21:21:05 +02:00
Yorick Peterse 45b0cdf811 Track element name nesting in the pull parser.
Tracking the names of nested elements makes it a lot easier to do contextual
pull parsing. Without this it's impossible to know what context the parser is
in at a given moment.

For memory reasons the parser currently only tracks the element names. In the
future it might perhaps also track extra information to make parsing easier.
2014-04-28 23:40:36 +02:00
Yorick Peterse 030a0068bd Basic pull parsing setup.
This parser extends the regular DOM parser but instead delegates certain nodes
to a block instead of building a DOM tree.

The API is a bit raw in its current form but I'll extend it and make it a bit
more user friendly in the following commits. In particular I want to make it
easier to figure out if a certain node is nested inside another node.
2014-04-28 17:22:17 +02:00
Yorick Peterse 08d412da7e First shot at removing the AST layer.
The AST layer is being removed because it doesn't really serve a useful
purpose. In particular when creating a streaming parser the AST nodes would
only introduce extra overhead.

As a result of this the parser will instead emit a DOM tree directly instead of
first emitting an AST.
2014-04-21 23:05:39 +02:00
Yorick Peterse d9fa4b7c45 Lex input as a sequence of bytes.
Instead of lexing the input as a raw String or as a set of codepoints it's
treated as a sequence of bytes. This removes the need of String#[] (replaced by
String#byteslice) which in turn reduces the amount of memory needed and speeds
up the lexing time.

Thanks to @headius and @apeiros for suggesting this and rubber ducking along!
2014-04-17 17:45:05 +02:00
Yorick Peterse b96f7c4852 Lex attributes with namespaces.
These are lexed as just the name instead of two separate tokens.
2014-04-10 11:01:49 +02:00
Yorick Peterse 8237d5791d Stream tokens when lexing.
Instead of returning the tokens as a whole they are now streamed using
XML::Lexer#advance. This method returns the next token upon every call. It uses
a small buffer in case a particular block of text results in multiple tokens.
2014-04-09 22:08:13 +02:00
Yorick Peterse 10d0ec1573 Specs for parsing various empty nodes. 2014-04-07 21:33:23 +02:00
Yorick Peterse cb74c7edf9 Specs for XML parser errors. 2014-04-07 21:31:36 +02:00
Yorick Peterse 915d3ee505 Expanded tests for XML::Document#inspect. 2014-04-07 20:11:12 +02:00
Yorick Peterse e9412c9c4e Tests for various inspect methods. 2014-04-07 09:58:31 +02:00
Yorick Peterse a2c525dd7c Insert newlines after XML dec/doctypes. 2014-04-03 23:04:21 +02:00
Yorick Peterse c077988dd6 Tree building of doctypes. 2014-04-03 22:44:00 +02:00
Yorick Peterse 81b1155af3 Lex/parse doctype names separately. 2014-04-03 21:59:57 +02:00
Yorick Peterse 6cf906e500 Lexer tests for single quoted attributes. 2014-04-03 18:50:07 +02:00
Yorick Peterse 30c01a5aee Tests for XML::TreeBuilder#handler_missing. 2014-04-03 09:43:30 +02:00
Yorick Peterse 0f129ceac9 Tests for XML::TreeBuilder#on_comment. 2014-04-03 09:38:18 +02:00
Yorick Peterse bdb76cefc5 Dedicated handling of XML declaration nodes. 2014-04-02 22:30:45 +02:00
Yorick Peterse d6c0a1f3f3 Lex/parser XML declaration attributes. 2014-04-02 22:01:17 +02:00
Yorick Peterse fa2e71c790 Tests for TreeBuilder#on_document. 2014-03-28 18:52:08 +01:00
Yorick Peterse f99c13b516 Tests + docs for the TreeBuilder class. 2014-03-28 17:11:54 +01:00
Yorick Peterse 331726b2ca Tests for the various XML node types. 2014-03-28 16:34:30 +01:00
Yorick Peterse 79818eb349 Added a convenience class for parsing HTML.
This removes the need for users having to set the `:html` option themselves.
2014-03-25 09:40:24 +01:00
Yorick Peterse 58009614f6 Moved XML specs into spec/oga/xml. 2014-03-25 09:36:39 +01:00
Yorick Peterse eae13d21ed Namespaced the lexer/parser under Oga::XML.
With the upcoming XPath and CSS selector lexers/parsers it will be confusing to
keep these in the root namespace.
2014-03-25 09:34:38 +01:00
Yorick Peterse 641c54261e Simplified lexer output for comments. 2014-03-24 21:34:30 +01:00
Yorick Peterse eaf1669b07 Simplified lexer output for CDATA tags. 2014-03-24 21:33:05 +01:00
Yorick Peterse 470be5a839 Simplified the lexer output for doctypes. 2014-03-24 21:32:16 +01:00
Yorick Peterse ac775918ee Lexing/parsing of XML declaration tags.
This closes #12.
2014-03-24 21:30:19 +01:00
Yorick Peterse b695ecf0df Renamed element lexer tags.
T_ELEM_OPEN has been renamed to T_ELEM_START, T_ELEM_CLOSE has been renamed to
T_ELEM_END. This keeps the token names consistent with the other ones (e.g.
T_COMMENT_START).
2014-03-24 20:32:43 +01:00
Yorick Peterse 91fb7523fd Lex open tags with newlines in them. 2014-03-20 23:39:29 +01:00
Yorick Peterse 74bc11a239 Rip out column counting.
This makes both the lexer and parser quite a bit easier to use. Counting column
numbers isn't also really needed when parsing XML/HTML.
2014-03-20 19:44:28 +01:00
Yorick Peterse 192ba9bb54 Expanded the lexer comment tests. 2014-03-19 21:44:57 +01:00
Yorick Peterse 7271e74396 Revert "Compacter parser AST."
Although this AST is compacter it will result in conflicts between (text),
(attributes) and (attribute) nodes in regular XML documents. This is due to XML
allowing elements with these names (unlike in HTML).

This reverts commit 8898d08831.
2014-03-18 18:55:16 +01:00
Yorick Peterse 274ab359ba Don't use separate tokens/nodes for newlines.
Newlines are now lexed together with regular text. The line numbers are
advanced based on the amount of "\n" sequences in a text buffer.
2014-03-17 21:26:21 +01:00
Yorick Peterse 8898d08831 Compacter parser AST.
The AST no longer uses the generic `element` type for element nodes but instead
changes the type based on the element type. That is, a <p> element now results
in an (p) node, <link> in (link), etc.
2014-03-17 21:03:54 +01:00
Yorick Peterse 8d3f3f15d7 Renamed parse_html() to parse(). 2014-03-16 23:46:20 +01:00
Yorick Peterse cb75edc30d Basic support for lexing/parsing HTML5.
This will need a bunch of extra tests before I'll consider closing #7.
2014-03-16 23:42:24 +01:00
Yorick Peterse ce8bbdb64a Parsing support for multiple nested nodes. 2014-03-15 20:19:54 +01:00
Yorick Peterse 05ee3c13c9 Parsing support for nested element/text nodes. 2014-03-14 00:44:11 +01:00
Yorick Peterse 6b2f682c5c Tests for lexing a basic HTML document.
This also comes with some changes to the lexer so that it advances column/line
numbers correctly.
2014-03-13 23:55:18 +01:00
Yorick Peterse edf2e4112b Added a test for parsing bare text tokens. 2014-03-13 00:42:58 +01:00
Yorick Peterse 34f8779c94 Lexing of bare regular text.
This is currently a bit of a hack but at least we're slowly getting there.
2014-03-13 00:42:12 +01:00
Yorick Peterse 2fbca93ae8 Supported for parsing nested elements. 2014-03-12 23:13:28 +01:00
Yorick Peterse 8cfa81aed9 Basic support for parsing elements.
This includes support for elements with namespaces and attributes. Nested
elements are not yet supported.
2014-03-12 23:02:54 +01:00
Yorick Peterse 98b3443e7f Lexing of element attributes without values. 2014-03-12 22:41:17 +01:00
Yorick Peterse ed9d8c05a2 Added support for parsing comments. 2014-03-12 22:20:12 +01:00
Yorick Peterse 0a396043f8 Support for parsing CDATA tags. 2014-03-11 22:22:02 +01:00
Yorick Peterse c9592856f0 Updated parsing of doctypes.
The resulting nodes now separate the type, public and system IDs in to separate
string values.
2014-03-11 22:08:21 +01:00