Lex comments in chunks

Similar to this being added for CDATA tags in
8acc7fc743 comments are now also lexed in
chunks.

Related issue: #93
This commit is contained in:
Yorick Peterse committed 2015-04-14 23:11:22 +02:00
1 parent 8acc7fc743
commit ea8b4aa92f
7 files changed
+129 -18

No files matched your search

+3 -1
View File
@@ -93,7 +93,9 @@ VALUE oga_xml_lexer_advance(VALUE self, VALUE data_block)
ID id_on_cdata_start = rb_intern("on_cdata_start");
ID id_on_cdata_body = rb_intern("on_cdata_body");
ID id_on_cdata_end = rb_intern("on_cdata_end");
ID id_on_comment = rb_intern("on_comment");
ID id_on_comment_start = rb_intern("on_comment_start");
ID id_on_comment_body = rb_intern("on_comment_body");
ID id_on_comment_end = rb_intern("on_comment_end");
ID id_on_doctype_end = rb_intern("on_doctype_end");
ID id_on_doctype_inline = rb_intern("on_doctype_inline");
ID id_on_doctype_name = rb_intern("on_doctype_name");
+3 -1
View File
@@ -107,7 +107,9 @@ public class Lexer extends RubyObject
String id_on_cdata_start = "on_cdata_start";
String id_on_cdata_body = "on_cdata_body";
String id_on_cdata_end = "on_cdata_end";
String id_on_comment = "on_comment";
String id_on_comment_start = "on_comment_start";
String id_on_comment_body = "on_comment_body";
String id_on_comment_end = "on_comment_end";
String id_on_doctype_end = "on_doctype_end";
String id_on_doctype_inline = "on_doctype_inline";
String id_on_doctype_name = "on_doctype_name";
+26 -3
View File
@@ -67,12 +67,35 @@
comment_start = '<!--';
comment_end = '-->';
comment = comment_start (any* -- comment_end) comment_end;
# Everything except "-" OR a single "-"
comment_allowed = (^'-'+ | '-') $count_newlines;
action start_comment {
callback(id_on_comment, data, encoding, ts + 4, te - 3);
callback_simple(id_on_comment_start);
fnext comment_body;
}
comment_body := |*
comment_allowed => {
callback(id_on_comment_body, data, encoding, ts, te);
if ( lines > 0 )
{
advance_line(lines);
lines = 0;
}
};
comment_end => {
callback_simple(id_on_comment_end);
fnext main;
};
*|;
# CDATA
#
# http://www.w3.org/TR/html-markup/syntax.html#cdata-sections
@@ -461,7 +484,7 @@
main := |*
doctype_start => start_doctype;
xml_decl_start => start_xml_decl;
comment => start_comment;
comment_start => start_comment;
cdata_start => start_cdata;
proc_ins_start => start_proc_ins;
element_start => start_element;