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).
This commit is contained in:
parent
0b6ba6e6b5
commit
b695ecf0df
|
@ -385,7 +385,7 @@ module Oga
|
||||||
# (if any). Remaining work is delegated to a dedicated machine.
|
# (if any). Remaining work is delegated to a dedicated machine.
|
||||||
action start_element {
|
action start_element {
|
||||||
emit_buffer
|
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
|
# Add the element name. If the name includes a namespace we'll break
|
||||||
# the name up into two separate tokens.
|
# 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.
|
# element is a void element we'll close it and bail out.
|
||||||
'>' => {
|
'>' => {
|
||||||
if html? and HTML_VOID_ELEMENTS.include?(current_element)
|
if html? and HTML_VOID_ELEMENTS.include?(current_element)
|
||||||
add_token(:T_ELEM_CLOSE, nil)
|
add_token(:T_ELEM_END, nil)
|
||||||
@elements.pop
|
@elements.pop
|
||||||
end
|
end
|
||||||
};
|
};
|
||||||
|
@ -450,14 +450,14 @@ module Oga
|
||||||
# Regular closing tags.
|
# Regular closing tags.
|
||||||
'</' element_name '>' => {
|
'</' element_name '>' => {
|
||||||
emit_buffer
|
emit_buffer
|
||||||
add_token(:T_ELEM_CLOSE, nil)
|
add_token(:T_ELEM_END, nil)
|
||||||
|
|
||||||
@elements.pop
|
@elements.pop
|
||||||
};
|
};
|
||||||
|
|
||||||
# Self closing elements that are not handled by the HTML mode.
|
# 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
|
@elements.pop
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@ token T_STRING T_TEXT
|
||||||
token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE
|
token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE
|
||||||
token T_CDATA_START T_CDATA_END
|
token T_CDATA_START T_CDATA_END
|
||||||
token T_COMMENT_START T_COMMENT_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
|
options no_result_var
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ rule
|
||||||
# Elements
|
# Elements
|
||||||
|
|
||||||
element
|
element
|
||||||
: element_open attributes expressions T_ELEM_CLOSE
|
: element_open attributes expressions T_ELEM_END
|
||||||
{
|
{
|
||||||
s(:element, val[0], val[1], val[2])
|
s(:element, val[0], val[1], val[2])
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,10 @@ rule
|
||||||
|
|
||||||
element_open
|
element_open
|
||||||
# <p>
|
# <p>
|
||||||
: T_ELEM_OPEN T_ELEM_NAME { [nil, val[1]] }
|
: T_ELEM_START T_ELEM_NAME { [nil, val[1]] }
|
||||||
|
|
||||||
# <foo:p>
|
# <foo:p>
|
||||||
| 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
|
# Attributes
|
||||||
|
|
|
@ -44,9 +44,9 @@ describe Oga::Lexer do
|
||||||
|
|
||||||
example 'lex an element followed by a comment' do
|
example 'lex an element followed by a comment' do
|
||||||
lex('<p></p><!---->').should == [
|
lex('<p></p><!---->').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_COMMENT_START, '<!--', 1],
|
[:T_COMMENT_START, '<!--', 1],
|
||||||
[:T_COMMENT_END, '-->', 1]
|
[:T_COMMENT_END, '-->', 1]
|
||||||
]
|
]
|
||||||
|
|
|
@ -19,34 +19,34 @@ describe Oga::Lexer do
|
||||||
[:T_TEXT, "\n", 1],
|
[:T_TEXT, "\n", 1],
|
||||||
|
|
||||||
# <html>
|
# <html>
|
||||||
[:T_ELEM_OPEN, nil, 2],
|
[:T_ELEM_START, nil, 2],
|
||||||
[:T_ELEM_NAME, 'html', 2],
|
[:T_ELEM_NAME, 'html', 2],
|
||||||
[:T_TEXT, "\n", 2],
|
[:T_TEXT, "\n", 2],
|
||||||
|
|
||||||
# <head>
|
# <head>
|
||||||
[:T_ELEM_OPEN, nil, 3],
|
[:T_ELEM_START, nil, 3],
|
||||||
[:T_ELEM_NAME, 'head', 3],
|
[:T_ELEM_NAME, 'head', 3],
|
||||||
[:T_TEXT, "\n", 3],
|
[:T_TEXT, "\n", 3],
|
||||||
|
|
||||||
# <title>Title</title>
|
# <title>Title</title>
|
||||||
[:T_ELEM_OPEN, nil, 4],
|
[:T_ELEM_START, nil, 4],
|
||||||
[:T_ELEM_NAME, 'title', 4],
|
[:T_ELEM_NAME, 'title', 4],
|
||||||
[:T_TEXT, 'Title', 4],
|
[:T_TEXT, 'Title', 4],
|
||||||
[:T_ELEM_CLOSE, nil, 4],
|
[:T_ELEM_END, nil, 4],
|
||||||
[:T_TEXT, "\n", 4],
|
[:T_TEXT, "\n", 4],
|
||||||
|
|
||||||
# </head>
|
# </head>
|
||||||
[:T_ELEM_CLOSE, nil, 5],
|
[:T_ELEM_END, nil, 5],
|
||||||
[:T_TEXT, "\n", 5],
|
[:T_TEXT, "\n", 5],
|
||||||
|
|
||||||
# <body></body>
|
# <body></body>
|
||||||
[:T_ELEM_OPEN, nil, 6],
|
[:T_ELEM_START, nil, 6],
|
||||||
[:T_ELEM_NAME, 'body', 6],
|
[:T_ELEM_NAME, 'body', 6],
|
||||||
[:T_ELEM_CLOSE, nil, 6],
|
[:T_ELEM_END, nil, 6],
|
||||||
[:T_TEXT, "\n", 6],
|
[:T_TEXT, "\n", 6],
|
||||||
|
|
||||||
# </html>
|
# </html>
|
||||||
[:T_ELEM_CLOSE, nil, 7],
|
[:T_ELEM_END, nil, 7],
|
||||||
[:T_TEXT, "\n", 7]
|
[:T_TEXT, "\n", 7]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,41 +4,41 @@ describe Oga::Lexer do
|
||||||
context 'elements' do
|
context 'elements' do
|
||||||
example 'lex an opening element' do
|
example 'lex an opening element' do
|
||||||
lex('<p>').should == [
|
lex('<p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1]
|
[:T_ELEM_NAME, 'p', 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex an opening an closing element' do
|
example 'lex an opening an closing element' do
|
||||||
lex('<p></p>').should == [
|
lex('<p></p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex a paragraph element with text inside it' do
|
example 'lex a paragraph element with text inside it' do
|
||||||
lex('<p>Hello</p>').should == [
|
lex('<p>Hello</p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_TEXT, 'Hello', 1],
|
[:T_TEXT, 'Hello', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex text followed by a paragraph element' do
|
example 'lex text followed by a paragraph element' do
|
||||||
lex('Foo<p>').should == [
|
lex('Foo<p>').should == [
|
||||||
[:T_TEXT, 'Foo', 1],
|
[:T_TEXT, 'Foo', 1],
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1]
|
[:T_ELEM_NAME, 'p', 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex an element with a newline in the open tag' do
|
example 'lex an element with a newline in the open tag' do
|
||||||
lex("<p\n></p>").should == [
|
lex("<p\n></p>").should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 2]
|
[:T_ELEM_END, nil, 2]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -46,21 +46,21 @@ describe Oga::Lexer do
|
||||||
context 'elements with attributes' do
|
context 'elements with attributes' do
|
||||||
example 'lex an element with an attribute without a value' do
|
example 'lex an element with an attribute without a value' do
|
||||||
lex('<p foo></p>').should == [
|
lex('<p foo></p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ATTR, 'foo', 1],
|
[:T_ATTR, 'foo', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex a paragraph element with attributes' do
|
example 'lex a paragraph element with attributes' do
|
||||||
lex('<p class="foo">Hello</p>').should == [
|
lex('<p class="foo">Hello</p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ATTR, 'class', 1],
|
[:T_ATTR, 'class', 1],
|
||||||
[:T_STRING, 'foo', 1],
|
[:T_STRING, 'foo', 1],
|
||||||
[:T_TEXT, 'Hello', 1],
|
[:T_TEXT, 'Hello', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,26 +68,26 @@ describe Oga::Lexer do
|
||||||
context 'nested elements' do
|
context 'nested elements' do
|
||||||
example 'lex a nested element' do
|
example 'lex a nested element' do
|
||||||
lex('<p><a></a></p>').should == [
|
lex('<p><a></a></p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'a', 1],
|
[:T_ELEM_NAME, 'a', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex nested elements and text nodes' do
|
example 'lex nested elements and text nodes' do
|
||||||
lex('<p>Foo<a>bar</a>baz</p>').should == [
|
lex('<p>Foo<a>bar</a>baz</p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_TEXT, 'Foo', 1],
|
[:T_TEXT, 'Foo', 1],
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'a', 1],
|
[:T_ELEM_NAME, 'a', 1],
|
||||||
[:T_TEXT, 'bar', 1],
|
[:T_TEXT, 'bar', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_TEXT, 'baz', 1],
|
[:T_TEXT, 'baz', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -95,19 +95,19 @@ describe Oga::Lexer do
|
||||||
context 'void elements' do
|
context 'void elements' do
|
||||||
example 'lex a void element' do
|
example 'lex a void element' do
|
||||||
lex('<br />').should == [
|
lex('<br />').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'br', 1],
|
[:T_ELEM_NAME, 'br', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex a void element with an attribute' do
|
example 'lex a void element with an attribute' do
|
||||||
lex('<br class="foo" />').should == [
|
lex('<br class="foo" />').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'br', 1],
|
[:T_ELEM_NAME, 'br', 1],
|
||||||
[:T_ATTR, 'class', 1],
|
[:T_ATTR, 'class', 1],
|
||||||
[:T_STRING, 'foo', 1],
|
[:T_STRING, 'foo', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,10 +115,10 @@ describe Oga::Lexer do
|
||||||
context 'elements with namespaces' do
|
context 'elements with namespaces' do
|
||||||
example 'lex an element with namespaces' do
|
example 'lex an element with namespaces' do
|
||||||
lex('<foo:p></p>').should == [
|
lex('<foo:p></p>').should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NS, 'foo', 1],
|
[:T_ELEM_NS, 'foo', 1],
|
||||||
[:T_ELEM_NAME, 'p', 1],
|
[:T_ELEM_NAME, 'p', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,41 +4,41 @@ describe Oga::Lexer do
|
||||||
context 'HTML void elements' do
|
context 'HTML void elements' do
|
||||||
example 'lex a void element that omits the closing /' do
|
example 'lex a void element that omits the closing /' do
|
||||||
lex('<link>', :html => true).should == [
|
lex('<link>', :html => true).should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'link', 1],
|
[:T_ELEM_NAME, 'link', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex text after a void element' do
|
example 'lex text after a void element' do
|
||||||
lex('<link>foo', :html => true).should == [
|
lex('<link>foo', :html => true).should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'link', 1],
|
[:T_ELEM_NAME, 'link', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_TEXT, 'foo', 1]
|
[:T_TEXT, 'foo', 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex a void element inside another element' do
|
example 'lex a void element inside another element' do
|
||||||
lex('<head><link></head>', :html => true).should == [
|
lex('<head><link></head>', :html => true).should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'head', 1],
|
[:T_ELEM_NAME, 'head', 1],
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'link', 1],
|
[:T_ELEM_NAME, 'link', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1]
|
[:T_ELEM_END, nil, 1]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'lex a void element inside another element with whitespace' do
|
example 'lex a void element inside another element with whitespace' do
|
||||||
lex("<head><link>\n</head>", :html => true).should == [
|
lex("<head><link>\n</head>", :html => true).should == [
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'head', 1],
|
[:T_ELEM_NAME, 'head', 1],
|
||||||
[:T_ELEM_OPEN, nil, 1],
|
[:T_ELEM_START, nil, 1],
|
||||||
[:T_ELEM_NAME, 'link', 1],
|
[:T_ELEM_NAME, 'link', 1],
|
||||||
[:T_ELEM_CLOSE, nil, 1],
|
[:T_ELEM_END, nil, 1],
|
||||||
[:T_TEXT, "\n", 1],
|
[:T_TEXT, "\n", 1],
|
||||||
[:T_ELEM_CLOSE, nil, 2]
|
[:T_ELEM_END, nil, 2]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue