From 8135074a62c38b039fbee2d916a196e1e43039f3 Mon Sep 17 00:00:00 2001
From: Yorick Peterse
Date: Tue, 21 Apr 2015 23:38:06 +0200
Subject: [PATCH] Merged on_element_start with on_element_name
This makes it easier to automatically insert preceding tokens when
starting a new element as we now have access to the name. Previously
on_element_start would be invoked first which doesn't receive an
argument.
---
ext/c/lexer.rl | 1 -
ext/java/org/liboga/xml/Lexer.rl | 1 -
ext/ragel/base_lexer.rl | 1 -
lib/oga/xml/lexer.rb | 7 -----
lib/oga/xml/parser.rll | 6 ++--
spec/oga/xml/lexer/cdata_spec.rb | 2 --
spec/oga/xml/lexer/comments_spec.rb | 3 --
spec/oga/xml/lexer/documents_spec.rb | 4 ---
spec/oga/xml/lexer/elements_spec.rb | 29 -------------------
spec/oga/xml/lexer/enumerator_spec.rb | 1 -
spec/oga/xml/lexer/html_attributes_spec.rb | 5 ----
spec/oga/xml/lexer/html_script_spec.rb | 2 --
spec/oga/xml/lexer/html_style_spec.rb | 5 ----
spec/oga/xml/lexer/html_void_elements_spec.rb | 11 -------
spec/oga/xml/lexer/inline_javascript_spec.rb | 6 ----
spec/oga/xml/lexer/invalid_elements_spec.rb | 2 --
spec/oga/xml/lexer/io_spec.rb | 3 --
17 files changed, 3 insertions(+), 86 deletions(-)
diff --git a/ext/c/lexer.rl b/ext/c/lexer.rl
index c122e9f..e952d6f 100644
--- a/ext/c/lexer.rl
+++ b/ext/c/lexer.rl
@@ -113,7 +113,6 @@ VALUE oga_xml_lexer_advance(VALUE self, VALUE data_block)
ID id_on_element_name = rb_intern("on_element_name");
ID id_on_element_ns = rb_intern("on_element_ns");
ID id_on_element_open_end = rb_intern("on_element_open_end");
- ID id_on_element_start = rb_intern("on_element_start");
ID id_on_proc_ins_end = rb_intern("on_proc_ins_end");
ID id_on_proc_ins_name = rb_intern("on_proc_ins_name");
ID id_on_proc_ins_start = rb_intern("on_proc_ins_start");
diff --git a/ext/java/org/liboga/xml/Lexer.rl b/ext/java/org/liboga/xml/Lexer.rl
index 458f9c9..12d219d 100644
--- a/ext/java/org/liboga/xml/Lexer.rl
+++ b/ext/java/org/liboga/xml/Lexer.rl
@@ -121,7 +121,6 @@ public class Lexer extends RubyObject
String id_on_element_name = "on_element_name";
String id_on_element_ns = "on_element_ns";
String id_on_element_open_end = "on_element_open_end";
- String id_on_element_start = "on_element_start";
String id_on_proc_ins_end = "on_proc_ins_end";
String id_on_proc_ins_name = "on_proc_ins_name";
String id_on_proc_ins_start = "on_proc_ins_start";
diff --git a/ext/ragel/base_lexer.rl b/ext/ragel/base_lexer.rl
index 27a6cb0..8a6e469 100644
--- a/ext/ragel/base_lexer.rl
+++ b/ext/ragel/base_lexer.rl
@@ -367,7 +367,6 @@
element_end = '' identifier (':' identifier)* '>';
action start_element {
- callback_simple(id_on_element_start);
fhold;
fnext element_name;
}
diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb
index 63c71a4..03dbc77 100644
--- a/lib/oga/xml/lexer.rb
+++ b/lib/oga/xml/lexer.rb
@@ -337,13 +337,6 @@ module Oga
add_token(:T_XML_DECL_END)
end
- ##
- # Called on the start of an element.
- #
- def on_element_start
- add_token(:T_ELEM_START)
- end
-
##
# Called on the start of a processing instruction.
#
diff --git a/lib/oga/xml/parser.rll b/lib/oga/xml/parser.rll
index 3343ebd..c21f320 100644
--- a/lib/oga/xml/parser.rll
+++ b/lib/oga/xml/parser.rll
@@ -27,7 +27,7 @@
%terminals T_DOCTYPE_INLINE;
%terminals T_COMMENT_START T_COMMENT_BODY T_COMMENT_END;
%terminals T_CDATA_START T_CDATA_BODY T_CDATA_END;
-%terminals T_ELEM_START T_ELEM_NAME T_ELEM_NS T_ELEM_END T_ATTR T_ATTR_NS;
+%terminals T_ELEM_NAME T_ELEM_NS T_ELEM_END T_ATTR T_ATTR_NS;
%terminals T_XML_DECL_START T_XML_DECL_END;
%terminals T_PROC_INS_START T_PROC_INS_NAME T_PROC_INS_BODY T_PROC_INS_END;
@@ -136,9 +136,9 @@ element_name_ns
;
element_start
- = T_ELEM_START element_name_ns attributes
+ = element_name_ns attributes
{
- on_element(val[1][0], val[1][1], val[2])
+ on_element(val[0][0], val[0][1], val[1])
}
;
diff --git a/spec/oga/xml/lexer/cdata_spec.rb b/spec/oga/xml/lexer/cdata_spec.rb
index 48f873d..d1a2aa7 100644
--- a/spec/oga/xml/lexer/cdata_spec.rb
+++ b/spec/oga/xml/lexer/cdata_spec.rb
@@ -37,12 +37,10 @@ describe Oga::XML::Lexer do
it 'lexes two CDATA tags following each other' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1],
[:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, 'foo', 1],
[:T_CDATA_END, nil, 1],
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'b', 1],
[:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, 'bar', 1],
diff --git a/spec/oga/xml/lexer/comments_spec.rb b/spec/oga/xml/lexer/comments_spec.rb
index 772ab5b..442e2f0 100644
--- a/spec/oga/xml/lexer/comments_spec.rb
+++ b/spec/oga/xml/lexer/comments_spec.rb
@@ -59,7 +59,6 @@ describe Oga::XML::Lexer do
it 'lexes an element followed by a comment' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1],
[:T_COMMENT_START, nil, 1],
@@ -69,12 +68,10 @@ describe Oga::XML::Lexer do
it 'lexes two comments following each other' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1],
[:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, 'foo', 1],
[:T_COMMENT_END, nil, 1],
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'b', 1],
[:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, 'bar', 1],
diff --git a/spec/oga/xml/lexer/documents_spec.rb b/spec/oga/xml/lexer/documents_spec.rb
index 2b9c689..a078ccd 100644
--- a/spec/oga/xml/lexer/documents_spec.rb
+++ b/spec/oga/xml/lexer/documents_spec.rb
@@ -20,17 +20,14 @@ describe Oga::XML::Lexer do
[:T_TEXT, "\n", 1],
#
- [:T_ELEM_START, nil, 2],
[:T_ELEM_NAME, 'html', 2],
[:T_TEXT, "\n", 2],
#
- [:T_ELEM_START, nil, 3],
[:T_ELEM_NAME, 'head', 3],
[:T_TEXT, "\n", 3],
# Title
- [:T_ELEM_START, nil, 4],
[:T_ELEM_NAME, 'title', 4],
[:T_TEXT, 'Title', 4],
[:T_ELEM_END, nil, 4],
@@ -41,7 +38,6 @@ describe Oga::XML::Lexer do
[:T_TEXT, "\n", 5],
#
- [:T_ELEM_START, nil, 6],
[:T_ELEM_NAME, 'body', 6],
[:T_ELEM_END, nil, 6],
[:T_TEXT, "\n", 6],
diff --git a/spec/oga/xml/lexer/elements_spec.rb b/spec/oga/xml/lexer/elements_spec.rb
index 0918811..71a6511 100644
--- a/spec/oga/xml/lexer/elements_spec.rb
+++ b/spec/oga/xml/lexer/elements_spec.rb
@@ -4,7 +4,6 @@ describe Oga::XML::Lexer do
describe 'elements' do
it 'lexes an opening element' do
lex('
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -12,7 +11,6 @@ describe Oga::XML::Lexer do
it 'lexes an opening element with a stray double quote' do
lex('
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -20,7 +18,6 @@ describe Oga::XML::Lexer do
it 'lexes an opening element with a stray double quoted string' do
lex('
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -28,7 +25,6 @@ describe Oga::XML::Lexer do
it 'lexes an opening an closing element' do
lex('
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -36,7 +32,6 @@ describe Oga::XML::Lexer do
it 'lexes an opening an closing element with a stray double quote' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -44,7 +39,6 @@ describe Oga::XML::Lexer do
it 'lexes an opening an closing element with a stray double quoted string' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -52,7 +46,6 @@ describe Oga::XML::Lexer do
it 'lexes a paragraph element with text inside it' do
lex('
Hello
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'Hello', 1],
[:T_ELEM_END, nil, 1]
@@ -62,7 +55,6 @@ describe Oga::XML::Lexer do
it 'lexes text followed by a paragraph element' do
lex('Foo
').should == [
[:T_TEXT, 'Foo', 1],
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1]
]
@@ -70,7 +62,6 @@ describe Oga::XML::Lexer do
it 'lexes an element with a newline in the open tag' do
lex("
").should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 2]
]
@@ -78,7 +69,6 @@ describe Oga::XML::Lexer do
it 'lexes an element with a carriage return in the open tag' do
lex("").should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 2]
]
@@ -88,7 +78,6 @@ describe Oga::XML::Lexer do
describe 'elements with attributes' do
it 'lexes an element with an attribute without a value' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_ELEM_END, nil, 1]
@@ -97,7 +86,6 @@ describe Oga::XML::Lexer do
it 'lexes an element with an empty attribute followed by a stray double quote' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_ELEM_END, nil, 1]
@@ -106,7 +94,6 @@ describe Oga::XML::Lexer do
it 'lexes an element with an attribute with an empty value' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1],
@@ -117,7 +104,6 @@ describe Oga::XML::Lexer do
it 'lexes an attribute value followed by a stray double quote' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1],
@@ -128,7 +114,6 @@ describe Oga::XML::Lexer do
it 'lexes an attribute value followed by a stray single quote' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1],
@@ -139,7 +124,6 @@ describe Oga::XML::Lexer do
it 'lexes a paragraph element with attributes' do
lex('
Hello
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'class', 1],
[:T_STRING_DQUOTE, nil, 1],
@@ -152,7 +136,6 @@ describe Oga::XML::Lexer do
it 'lexes a paragraph element with a newline in an attribute' do
lex("
Hello
").should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'class', 1],
[:T_STRING_DQUOTE, nil, 1],
@@ -165,7 +148,6 @@ describe Oga::XML::Lexer do
it 'lexes a paragraph element with single quoted attributes' do
lex("").should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'class', 1],
[:T_STRING_SQUOTE, nil, 1],
@@ -177,7 +159,6 @@ describe Oga::XML::Lexer do
it 'lexes a paragraph element with a namespaced attribute' do
lex('').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
[:T_ATTR_NS, 'foo', 1],
[:T_ATTR, 'bar', 1],
@@ -192,9 +173,7 @@ describe Oga::XML::Lexer do
describe 'nested elements' do
it 'lexes a nested element' do
lex('
').should == [
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
- [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1],
[:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1]
@@ -203,10 +182,8 @@ describe Oga::XML::Lexer do
it 'lexes nested elements and text nodes' do
lex('