Fixed advancing column numbers.
In a bunch of cases the column number would not be increased correctly.
This commit is contained in:
parent
1c9a6c8b76
commit
cd53d5e426
|
@ -73,7 +73,7 @@ module Oga
|
|||
def add_token(type, value)
|
||||
token = [type, value, @line, @column]
|
||||
|
||||
advance_column(value.length)
|
||||
advance_column(value.length) if value
|
||||
|
||||
@tokens << token
|
||||
end
|
||||
|
@ -125,12 +125,10 @@ module Oga
|
|||
}
|
||||
|
||||
action string_dquote {
|
||||
advance_column
|
||||
fcall string_dquote;
|
||||
}
|
||||
|
||||
action string_squote {
|
||||
advance_column
|
||||
fcall string_squote;
|
||||
}
|
||||
|
||||
|
@ -138,6 +136,7 @@ module Oga
|
|||
^dquote => buffer_string;
|
||||
dquote => {
|
||||
emit_string_buffer
|
||||
advance_column
|
||||
fret;
|
||||
};
|
||||
*|;
|
||||
|
@ -146,6 +145,7 @@ module Oga
|
|||
^squote => buffer_string;
|
||||
squote => {
|
||||
emit_string_buffer
|
||||
advance_column
|
||||
fret;
|
||||
};
|
||||
*|;
|
||||
|
@ -236,7 +236,7 @@ module Oga
|
|||
# First emit the token, then advance the column. This way the column
|
||||
# number points to the < and not the "p" in <p>.
|
||||
action open_element {
|
||||
t(:T_ELEM_OPEN, p)
|
||||
t(:T_ELEM_OPEN, @ts + 1)
|
||||
|
||||
advance_column
|
||||
|
||||
|
@ -268,10 +268,11 @@ module Oga
|
|||
element_name
|
||||
%{
|
||||
t(:T_ATTR, @ts, p)
|
||||
advance_column
|
||||
}
|
||||
'=' (dquote @string_dquote | squote @string_squote);
|
||||
|
||||
# Non self-closing tags.
|
||||
# Non self-closing elements.
|
||||
'</' element_name {
|
||||
emit_text_buffer
|
||||
t(:T_ELEM_CLOSE, p)
|
||||
|
@ -282,6 +283,13 @@ module Oga
|
|||
advance_column(2)
|
||||
fret;
|
||||
};
|
||||
|
||||
# self-closing / void elements.
|
||||
'/>' => {
|
||||
advance_column
|
||||
add_token(:T_ELEM_CLOSE, nil)
|
||||
fret;
|
||||
};
|
||||
*|;
|
||||
|
||||
main := |*
|
||||
|
|
|
@ -13,8 +13,8 @@ describe Oga::Lexer do
|
|||
lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
|
||||
[:T_DOCTYPE_START, '<!DOCTYPE HTML', 1, 1],
|
||||
[:T_DOCTYPE_TYPE, 'PUBLIC', 1, 16],
|
||||
[:T_STRING, 'foobar', 1, 24],
|
||||
[:T_STRING, 'baz', 1, 33],
|
||||
[:T_STRING, 'foobar', 1, 23],
|
||||
[:T_STRING, 'baz', 1, 32],
|
||||
[:T_DOCTYPE_END, '>', 1, 37]
|
||||
]
|
||||
end
|
||||
|
@ -23,8 +23,8 @@ describe Oga::Lexer do
|
|||
lex("<!DOCTYPE HTML PUBLIC 'foobar' 'baz'>").should == [
|
||||
[:T_DOCTYPE_START, '<!DOCTYPE HTML', 1, 1],
|
||||
[:T_DOCTYPE_TYPE, 'PUBLIC', 1, 16],
|
||||
[:T_STRING, 'foobar', 1, 24],
|
||||
[:T_STRING, 'baz', 1, 33],
|
||||
[:T_STRING, 'foobar', 1, 23],
|
||||
[:T_STRING, 'baz', 1, 32],
|
||||
[:T_DOCTYPE_END, '>', 1, 37]
|
||||
]
|
||||
end
|
||||
|
|
|
@ -28,8 +28,8 @@ describe Oga::Lexer do
|
|||
[:T_ELEM_OPEN, 'p', 1, 1],
|
||||
[:T_ATTR, 'class', 1, 4],
|
||||
[:T_STRING, 'foo', 1, 10],
|
||||
[:T_TEXT, 'Hello', 1, 15],
|
||||
[:T_ELEM_CLOSE, 'p', 1, 20]
|
||||
[:T_TEXT, 'Hello', 1, 16],
|
||||
[:T_ELEM_CLOSE, 'p', 1, 21]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
@ -56,4 +56,22 @@ describe Oga::Lexer do
|
|||
]
|
||||
end
|
||||
end
|
||||
|
||||
context 'void elements' do
|
||||
example 'lex a void element' do
|
||||
lex('<br />').should == [
|
||||
[:T_ELEM_OPEN, 'br', 1, 1],
|
||||
[:T_ELEM_CLOSE, nil, 1, 6]
|
||||
]
|
||||
end
|
||||
|
||||
example 'lex a void element with an attribute' do
|
||||
lex('<br class="foo" />').should == [
|
||||
[:T_ELEM_OPEN, 'br', 1, 1],
|
||||
[:T_ATTR, 'class', 1, 5],
|
||||
[:T_STRING, 'foo', 1, 11],
|
||||
[:T_ELEM_CLOSE, nil, 1, 18]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue