Added support for parsing comments.
This commit is contained in:
parent
0a396043f8
commit
ed9d8c05a2
|
@ -4,6 +4,7 @@ token T_NEWLINE T_SPACE
|
|||
token T_STRING T_TEXT
|
||||
token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE
|
||||
token T_CDATA_START T_CDATA_END
|
||||
token T_COMMENT_START T_COMMENT_END
|
||||
|
||||
options no_result_var
|
||||
|
||||
|
@ -21,6 +22,7 @@ rule
|
|||
expression
|
||||
: doctype
|
||||
| cdata
|
||||
| comment
|
||||
;
|
||||
|
||||
# Doctypes
|
||||
|
@ -58,6 +60,16 @@ rule
|
|||
| T_CDATA_START T_TEXT T_CDATA_END { s(:cdata, val[1]) }
|
||||
;
|
||||
|
||||
# Comments
|
||||
|
||||
comment
|
||||
# <!---->
|
||||
: T_COMMENT_START T_COMMENT_END { s(:comment) }
|
||||
|
||||
# <!-- foo -->
|
||||
| T_COMMENT_START T_TEXT T_COMMENT_END { s(:comment, val[1]) }
|
||||
;
|
||||
|
||||
whitespaces
|
||||
: whitespaces whitespace
|
||||
| whitespace
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::Parser do
|
||||
context 'comments' do
|
||||
example 'parse an empty comment' do
|
||||
parse_html('<!---->').should == s(:document, s(:comment))
|
||||
end
|
||||
|
||||
example 'parse a comment' do
|
||||
parse_html('<!--foo-->').should == s(:document, s(:comment, 'foo'))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue