Simplified lexer output for comments.

This commit is contained in:
Yorick Peterse 2014-03-24 21:34:30 +01:00
parent eaf1669b07
commit 641c54261e
2 changed files with 14 additions and 14 deletions

View File

@ -356,7 +356,7 @@ module Oga
action start_comment { action start_comment {
emit_buffer emit_buffer
t(:T_COMMENT_START) add_token(:T_COMMENT_START, nil)
start_buffer start_buffer
@ -368,7 +368,7 @@ module Oga
comment := |* comment := |*
comment_end => { comment_end => {
emit_buffer emit_buffer
t(:T_COMMENT_END) add_token(:T_COMMENT_END, nil)
fret; fret;
}; };

View File

@ -4,32 +4,32 @@ describe Oga::Lexer do
context 'comments' do context 'comments' do
example 'lex a comment' do example 'lex a comment' do
lex('<!-- foo -->').should == [ lex('<!-- foo -->').should == [
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_TEXT, ' foo ', 1], [:T_TEXT, ' foo ', 1],
[:T_COMMENT_END, '-->', 1] [:T_COMMENT_END, nil, 1]
] ]
end end
example 'lex a comment containing --' do example 'lex a comment containing --' do
lex('<!-- -- -->').should == [ lex('<!-- -- -->').should == [
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_TEXT, ' -- ', 1], [:T_TEXT, ' -- ', 1],
[:T_COMMENT_END, '-->', 1] [:T_COMMENT_END, nil, 1]
] ]
end end
example 'lex a comment containing ->' do example 'lex a comment containing ->' do
lex('<!-- -> -->').should == [ lex('<!-- -> -->').should == [
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_TEXT, ' -> ', 1], [:T_TEXT, ' -> ', 1],
[:T_COMMENT_END, '-->', 1] [:T_COMMENT_END, nil, 1]
] ]
end end
example 'lex a comment followed by text' do example 'lex a comment followed by text' do
lex('<!---->foo').should == [ lex('<!---->foo').should == [
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, '-->', 1], [:T_COMMENT_END, nil, 1],
[:T_TEXT, 'foo', 1] [:T_TEXT, 'foo', 1]
] ]
end end
@ -37,8 +37,8 @@ describe Oga::Lexer do
example 'lex text followed by a comment' do example 'lex text followed by a comment' do
lex('foo<!---->').should == [ lex('foo<!---->').should == [
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, '-->', 1] [:T_COMMENT_END, nil, 1]
] ]
end end
@ -47,8 +47,8 @@ describe Oga::Lexer do
[:T_ELEM_START, nil, 1], [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_COMMENT_START, '<!--', 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, '-->', 1] [:T_COMMENT_END, nil, 1]
] ]
end end
end end