Cleaned up lexing of comments/cdata.

Thanks to @whitequark for suggesting the use of the "--" operator.
This commit is contained in:
Yorick Peterse 2014-08-16 16:03:55 +02:00
parent 0d7609da88
commit 56341b5585
1 changed files with 7 additions and 32 deletions

View File

@ -50,25 +50,12 @@
comment_start = '<!--'; comment_start = '<!--';
comment_end = '-->'; comment_end = '-->';
comment = comment_start (any* -- comment_end) comment_end;
action start_comment { action start_comment {
mark = te; callback("on_comment", data, encoding, ts + 4, te - 3);
fnext comment_body;
} }
comment_body := |*
comment_end => {
callback("on_comment", data, encoding, mark, te - 3);
mark = 0;
fnext main;
};
any;
*|;
# CDATA # CDATA
# #
# http://www.w3.org/TR/html-markup/syntax.html#cdata-sections # http://www.w3.org/TR/html-markup/syntax.html#cdata-sections
@ -79,25 +66,12 @@
cdata_start = '<![CDATA['; cdata_start = '<![CDATA[';
cdata_end = ']]>'; cdata_end = ']]>';
cdata = cdata_start (any* -- cdata_end) cdata_end;
action start_cdata { action start_cdata {
mark = te; callback("on_cdata", data, encoding, ts + 9, te - 3);
fnext cdata_body;
} }
cdata_body := |*
cdata_end => {
callback("on_cdata", data, encoding, mark, te - 3);
mark = 0;
fnext main;
};
any;
*|;
# Processing Instructions # Processing Instructions
# #
# http://www.w3.org/TR/xpath/#section-Processing-Instruction-Nodes # http://www.w3.org/TR/xpath/#section-Processing-Instruction-Nodes
@ -289,10 +263,11 @@
main := |* main := |*
doctype_start => start_doctype; doctype_start => start_doctype;
xml_decl_start => start_xml_decl; xml_decl_start => start_xml_decl;
comment_start => start_comment; comment => start_comment;
cdata_start => start_cdata; cdata => start_cdata;
proc_ins_start => start_proc_ins; proc_ins_start => start_proc_ins;
# The start of an element. # The start of an element.
'<' => start_element; '<' => start_element;