diff --git a/lib/oga/lexer.rl b/lib/oga/lexer.rl index 27c9f6c..3e54650 100644 --- a/lib/oga/lexer.rl +++ b/lib/oga/lexer.rl @@ -385,7 +385,7 @@ module Oga # (if any). Remaining work is delegated to a dedicated machine. action start_element { emit_buffer - add_token(:T_ELEM_OPEN, nil) + add_token(:T_ELEM_START, nil) # Add the element name. If the name includes a namespace we'll break # the name up into two separate tokens. @@ -442,7 +442,7 @@ module Oga # element is a void element we'll close it and bail out. '>' => { if html? and HTML_VOID_ELEMENTS.include?(current_element) - add_token(:T_ELEM_CLOSE, nil) + add_token(:T_ELEM_END, nil) @elements.pop end }; @@ -450,14 +450,14 @@ module Oga # Regular closing tags. '' => { emit_buffer - add_token(:T_ELEM_CLOSE, nil) + add_token(:T_ELEM_END, nil) @elements.pop }; # Self closing elements that are not handled by the HTML mode. '/>' => { - add_token(:T_ELEM_CLOSE, nil) + add_token(:T_ELEM_END, nil) @elements.pop }; diff --git a/lib/oga/parser.y b/lib/oga/parser.y index ddd7319..4ee206c 100644 --- a/lib/oga/parser.y +++ b/lib/oga/parser.y @@ -13,7 +13,7 @@ token T_STRING T_TEXT token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE token T_CDATA_START T_CDATA_END token T_COMMENT_START T_COMMENT_END -token T_ELEM_OPEN T_ELEM_NAME T_ELEM_NS T_ELEM_CLOSE T_ATTR +token T_ELEM_START T_ELEM_NAME T_ELEM_NS T_ELEM_END T_ATTR options no_result_var @@ -85,7 +85,7 @@ rule # Elements element - : element_open attributes expressions T_ELEM_CLOSE + : element_open attributes expressions T_ELEM_END { s(:element, val[0], val[1], val[2]) } @@ -93,10 +93,10 @@ rule element_open #

- : T_ELEM_OPEN T_ELEM_NAME { [nil, val[1]] } + : T_ELEM_START T_ELEM_NAME { [nil, val[1]] } # - | T_ELEM_OPEN T_ELEM_NS T_ELEM_NAME { [val[1], val[2]] } + | T_ELEM_START T_ELEM_NS T_ELEM_NAME { [val[1], val[2]] } ; # Attributes diff --git a/spec/oga/lexer/comments_spec.rb b/spec/oga/lexer/comments_spec.rb index 63edafc..ac87f36 100644 --- a/spec/oga/lexer/comments_spec.rb +++ b/spec/oga/lexer/comments_spec.rb @@ -44,9 +44,9 @@ describe Oga::Lexer do example 'lex an element followed by a comment' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], - [:T_ELEM_CLOSE, nil, 1], + [:T_ELEM_END, nil, 1], [:T_COMMENT_START, '', 1] ] diff --git a/spec/oga/lexer/documents_spec.rb b/spec/oga/lexer/documents_spec.rb index 3564b63..839d993 100644 --- a/spec/oga/lexer/documents_spec.rb +++ b/spec/oga/lexer/documents_spec.rb @@ -19,34 +19,34 @@ describe Oga::Lexer do [:T_TEXT, "\n", 1], # - [:T_ELEM_OPEN, nil, 2], + [:T_ELEM_START, nil, 2], [:T_ELEM_NAME, 'html', 2], [:T_TEXT, "\n", 2], # - [:T_ELEM_OPEN, nil, 3], + [:T_ELEM_START, nil, 3], [:T_ELEM_NAME, 'head', 3], [:T_TEXT, "\n", 3], # Title - [:T_ELEM_OPEN, nil, 4], + [:T_ELEM_START, nil, 4], [:T_ELEM_NAME, 'title', 4], [:T_TEXT, 'Title', 4], - [:T_ELEM_CLOSE, nil, 4], + [:T_ELEM_END, nil, 4], [:T_TEXT, "\n", 4], # - [:T_ELEM_CLOSE, nil, 5], + [:T_ELEM_END, nil, 5], [:T_TEXT, "\n", 5], # - [:T_ELEM_OPEN, nil, 6], + [:T_ELEM_START, nil, 6], [:T_ELEM_NAME, 'body', 6], - [:T_ELEM_CLOSE, nil, 6], + [:T_ELEM_END, nil, 6], [:T_TEXT, "\n", 6], # - [:T_ELEM_CLOSE, nil, 7], + [:T_ELEM_END, nil, 7], [:T_TEXT, "\n", 7] ] end diff --git a/spec/oga/lexer/elements_spec.rb b/spec/oga/lexer/elements_spec.rb index 11a534b..710df16 100644 --- a/spec/oga/lexer/elements_spec.rb +++ b/spec/oga/lexer/elements_spec.rb @@ -4,41 +4,41 @@ describe Oga::Lexer do context 'elements' do example 'lex an opening element' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1] ] end example 'lex an opening an closing element' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end example 'lex a paragraph element with text inside it' do lex('

Hello

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], [:T_TEXT, 'Hello', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end example 'lex text followed by a paragraph element' do lex('Foo

').should == [ [:T_TEXT, 'Foo', 1], - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1] ] end example 'lex an element with a newline in the open tag' do lex("

").should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], - [:T_ELEM_CLOSE, nil, 2] + [:T_ELEM_END, nil, 2] ] end end @@ -46,21 +46,21 @@ describe Oga::Lexer do context 'elements with attributes' do example 'lex an element with an attribute without a value' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], [:T_ATTR, 'foo', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end example 'lex a paragraph element with attributes' do lex('

Hello

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], [:T_ATTR, 'class', 1], [:T_STRING, 'foo', 1], [:T_TEXT, 'Hello', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end end @@ -68,26 +68,26 @@ describe Oga::Lexer do context 'nested elements' do example 'lex a nested element' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'a', 1], - [:T_ELEM_CLOSE, nil, 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1], + [:T_ELEM_END, nil, 1] ] end example 'lex nested elements and text nodes' do lex('

Foobarbaz

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'p', 1], [:T_TEXT, 'Foo', 1], - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'a', 1], [:T_TEXT, 'bar', 1], - [:T_ELEM_CLOSE, nil, 1], + [:T_ELEM_END, nil, 1], [:T_TEXT, 'baz', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end end @@ -95,19 +95,19 @@ describe Oga::Lexer do context 'void elements' do example 'lex a void element' do lex('
').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'br', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end example 'lex a void element with an attribute' do lex('
').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'br', 1], [:T_ATTR, 'class', 1], [:T_STRING, 'foo', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end end @@ -115,10 +115,10 @@ describe Oga::Lexer do context 'elements with namespaces' do example 'lex an element with namespaces' do lex('

').should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NS, 'foo', 1], [:T_ELEM_NAME, 'p', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end end diff --git a/spec/oga/lexer/html_void_elements_spec.rb b/spec/oga/lexer/html_void_elements_spec.rb index 58754ab..b80fc8e 100644 --- a/spec/oga/lexer/html_void_elements_spec.rb +++ b/spec/oga/lexer/html_void_elements_spec.rb @@ -4,41 +4,41 @@ describe Oga::Lexer do context 'HTML void elements' do example 'lex a void element that omits the closing /' do lex('', :html => true).should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'link', 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1] ] end example 'lex text after a void element' do lex('foo', :html => true).should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'link', 1], - [:T_ELEM_CLOSE, nil, 1], + [:T_ELEM_END, nil, 1], [:T_TEXT, 'foo', 1] ] end example 'lex a void element inside another element' do lex('', :html => true).should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'head', 1], - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'link', 1], - [:T_ELEM_CLOSE, nil, 1], - [:T_ELEM_CLOSE, nil, 1] + [:T_ELEM_END, nil, 1], + [:T_ELEM_END, nil, 1] ] end example 'lex a void element inside another element with whitespace' do lex("\n", :html => true).should == [ - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'head', 1], - [:T_ELEM_OPEN, nil, 1], + [:T_ELEM_START, nil, 1], [:T_ELEM_NAME, 'link', 1], - [:T_ELEM_CLOSE, nil, 1], + [:T_ELEM_END, nil, 1], [:T_TEXT, "\n", 1], - [:T_ELEM_CLOSE, nil, 2] + [:T_ELEM_END, nil, 2] ] end end