diff --git a/ext/ragel/base_lexer.rl b/ext/ragel/base_lexer.rl index b46a540..a27971e 100644 --- a/ext/ragel/base_lexer.rl +++ b/ext/ragel/base_lexer.rl @@ -306,19 +306,34 @@ # Machine that processes the contents of an XML declaration tag. xml_decl := |* xml_decl_end => { + if ( lines > 0 ) + { + advance_line(lines); + + lines = 0; + } + callback_simple(id_on_xml_decl_end); + fnext main; }; # Attributes and their values (e.g. version="1.0"). identifier => { + if ( lines > 0 ) + { + advance_line(lines); + + lines = 0; + } + callback(id_on_attribute, data, encoding, ts, te); }; squote => start_string_squote; dquote => start_string_dquote; - any; + any $count_newlines; *|; # Elements diff --git a/spec/oga/xml/lexer/xml_declaration_spec.rb b/spec/oga/xml/lexer/xml_declaration_spec.rb index 1df8485..ce6843a 100644 --- a/spec/oga/xml/lexer/xml_declaration_spec.rb +++ b/spec/oga/xml/lexer/xml_declaration_spec.rb @@ -23,5 +23,32 @@ describe Oga::XML::Lexer do [:T_XML_DECL_END, nil, 1] ] end + + it 'lexes a declaration with a newline after the open tag' do + lex("").should == [ + [:T_XML_DECL_START, nil, 1], + [:T_XML_DECL_END, nil, 2] + ] + end + + it 'lexes a declaration with a newline followed by an attribute' do + lex("").should == [ + [:T_XML_DECL_START, nil, 1], + [:T_ATTR, 'a', 2], + [:T_STRING_SQUOTE, nil, 2], + [:T_STRING_BODY, 'b', 2], + [:T_STRING_SQUOTE, nil, 2], + [:T_XML_DECL_END, nil, 2] + ] + end + + describe 'using an IO as input' do + it 'lexes a declaration with a newline after the open tag' do + lex_stringio("").should == [ + [:T_XML_DECL_START, nil, 1], + [:T_XML_DECL_END, nil, 2] + ] + end + end end end