Added support for parsing comments.

This commit is contained in:
Yorick Peterse 2014-03-12 22:20:12 +01:00
parent 0a396043f8
commit ed9d8c05a2
2 changed files with 25 additions and 0 deletions

View File

@ -4,6 +4,7 @@ token T_NEWLINE T_SPACE
token T_STRING T_TEXT token T_STRING T_TEXT
token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE token T_DOCTYPE_START T_DOCTYPE_END T_DOCTYPE_TYPE
token T_CDATA_START T_CDATA_END token T_CDATA_START T_CDATA_END
token T_COMMENT_START T_COMMENT_END
options no_result_var options no_result_var
@ -21,6 +22,7 @@ rule
expression expression
: doctype : doctype
| cdata | cdata
| comment
; ;
# Doctypes # Doctypes
@ -58,6 +60,16 @@ rule
| T_CDATA_START T_TEXT T_CDATA_END { s(:cdata, val[1]) } | 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
: whitespaces whitespace : whitespaces whitespace
| whitespace | whitespace

View File

@ -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