Use separate Ragel machines for script/style tags

Previously a single Ragel machine was used for processing HTML
script and style tags. This had the unfortunate side-effect that the
following was not parsed correctly (while being valid HTML):

    <script>
    var foo = "</style>";
    </script>

The same applied to style tags:

    <style>
    /* </script> */
    </style>

By using separate machines we can work around the above issue. The
downside is that this can produce multiple T_TEXT nodes, which have to
be stitched back together in the parser.
This commit is contained in:
Yorick Peterse committed 2015-04-16 01:45:39 +02:00
1 parent 2d43e459a1
commit 73fbbfbdbd
7 files changed
+118 -54

No files matched your search

+11 -6
View File
@@ -19,11 +19,15 @@ on `ts` and `te`) so the macro ignores this argument.
#define advance_line(amount) \
rb_funcall(self, id_advance_line, 1, INT2NUM(amount));
#define literal_html_element_p() \
rb_funcall(self, id_literal_html_element_p, 0) == Qtrue
#define html_script_p() \
rb_funcall(self, id_html_script_p, 0) == Qtrue
#define html_style_p() \
rb_funcall(self, id_html_style_p, 0) == Qtrue
ID id_advance_line;
ID id_literal_html_element_p;
ID id_html_script_p;
ID id_html_style_p;
ID id_html;
%%machine c_lexer;
@@ -183,9 +187,10 @@ void Init_liboga_xml_lexer()
VALUE mXML = rb_const_get(mOga, rb_intern("XML"));
VALUE cLexer = rb_define_class_under(mXML, "Lexer", rb_cObject);
id_advance_line = rb_intern("advance_line");
id_literal_html_element_p = rb_intern("literal_html_element?");
id_html = rb_intern("html");
id_advance_line = rb_intern("advance_line");
id_html_script_p = rb_intern("html_script?");
id_html_style_p = rb_intern("html_style?");
id_html = rb_intern("html");
rb_define_method(cLexer, "advance_native", oga_xml_lexer_advance, 1);
rb_define_method(cLexer, "reset_native", oga_xml_lexer_reset, 0);