From 7271e74396d7f611c8b3bc16a3dfec3cc589856a Mon Sep 17 00:00:00 2001
From: Yorick Peterse
Date: Tue, 18 Mar 2014 18:55:16 +0100
Subject: [PATCH] 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 8898d08831c57fffee49f3aa7fd6188241f5ff93.
---
lib/oga/parser.y | 8 ++--
spec/oga/parser/documents_spec.rb | 11 ++++--
spec/oga/parser/elements_spec.rb | 46 +++++++++++++---------
spec/oga/parser/html_void_elements_spec.rb | 29 ++++++++++----
4 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/lib/oga/parser.y b/lib/oga/parser.y
index d844f1c..6c86e5c 100644
--- a/lib/oga/parser.y
+++ b/lib/oga/parser.y
@@ -77,18 +77,16 @@ rule
element
: element_open attributes element_body T_ELEM_CLOSE
{
- namespace, name = val[0]
-
- s(name, namespace, val[1], val[2])
+ s(:element, val[0], val[1], val[2])
}
;
element_open
#
').should == s(
:document,
- s(:p, nil, nil, s(:text, 'foo'))
+ s(:element, nil, 'p', nil, s(:text, 'foo'))
)
end
example 'parse an element with a single attribute' do
parse('').should == s(
:document,
- s(:p, nil, s(:attributes, s(:attribute, 'foo')), nil)
+ s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo')), nil)
)
end
example 'parse an element with a single attribute with a value' do
parse('').should == s(
:document,
- s(:p, nil, s(:attributes, s(:attribute, 'foo', 'bar')), nil)
+ s(:element, nil, 'p', s(:attributes, s(:attribute, 'foo', 'bar')), nil)
)
end
@@ -31,8 +34,9 @@ describe Oga::Parser do
parse('').should == s(
:document,
s(
- :p,
+ :element,
nil,
+ 'p',
s(
:attributes,
s(:attribute, 'foo', 'bar'),
@@ -47,8 +51,9 @@ describe Oga::Parser do
parse('
Bar
').should == s(
:document,
s(
- :p,
+ :element,
nil,
+ 'p',
s(:attributes, s(:attribute, 'class', 'foo')),
s(:text, 'Bar')
)
@@ -58,7 +63,7 @@ describe Oga::Parser do
example 'parse an element with a namespace' do
parse('