diff --git a/lib/oga/parser.y b/lib/oga/parser.y index 1ff0cd9..de2abd7 100644 --- a/lib/oga/parser.y +++ b/lib/oga/parser.y @@ -1,8 +1,8 @@ class Oga::Parser -token T_SPACE T_NEWLINE T_SMALLER T_GREATER T_SLASH -token T_DQUOTE T_SQUOTE T_DASH T_RBRACKET T_LBRACKET -token T_COLON T_BANG T_EQUALS T_TEXT T_DOCTYPE +token T_NEWLINE T_SPACE +token T_STRING +token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE options no_result_var @@ -18,38 +18,32 @@ rule ; expression - : tag - | doctype + : doctype ; # Doctypes doctype - : T_DOCTYPE { s(:doctype, val[0]) } - ; + # + : T_DOCTYPE_START T_DOCTYPE_END { s(:doctype) } - # Generic HTML tags - - tag_start - #

- : T_SMALLER T_TEXT T_GREATER { val[1] } - ; - - tag_end - #

- : T_SMALLER T_SLASH T_TEXT T_GREATER - ; - - tag - #

foo

- : tag_start tag_body tag_end + # + | T_DOCTYPE_START T_DOCTYPE_TYPE T_DOCTYPE_END { - s(:element, val[0], val[1]) + s(:doctype, val[1]) } - ; - tag_body - : T_TEXT + # + | T_DOCTYPE_START T_DOCTYPE_TYPE T_STRING T_DOCTYPE_END + { + s(:doctype, val[1], val[2]) + } + + # + | T_DOCTYPE_START T_DOCTYPE_TYPE T_STRING T_STRING T_DOCTYPE_END + { + s(:doctype, val[1], val[2], val[3]) + } ; whitespaces diff --git a/spec/oga/parser/doctype_spec.rb b/spec/oga/parser/doctype_spec.rb index 58072ad..5457220 100644 --- a/spec/oga/parser/doctype_spec.rb +++ b/spec/oga/parser/doctype_spec.rb @@ -6,17 +6,24 @@ describe Oga::Parser do parse_html('').should == s(:document, s(:doctype)) end - example 'parse a doctype with a public ID' do - parse_html('').should == s( + example 'parse a doctype with the doctype type' do + parse_html('').should == s( :document, - s(:doctype, 'foo') + s(:doctype, 'PUBLIC') + ) + end + + example 'parse a doctype with a public ID' do + parse_html('').should == s( + :document, + s(:doctype, 'PUBLIC', 'foo') ) end example 'parse a doctype with a public and private ID' do - parse_html('').should == s( + parse_html('').should == s( :document, - s(:doctype, 'foo', 'bar') + s(:doctype, 'PUBLIC', 'foo', 'bar') ) end @@ -28,6 +35,7 @@ describe Oga::Parser do :document, s( :doctype, + 'PUBLIC', '-//W3C//DTD HTML 4.01//EN', 'http://www.w3.org/TR/html4/strict.dtd' )