1 // xslt.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_XSLT_PARSER
5 #define RAGEL_XSLT_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *XSLT_LANG = "xslt";
12 // the languages entities
13 const char *xslt_entities[] = {
14 "space", "comment", "doctype",
15 "tag", "entity", "any"
18 // constants associated with the entities
20 XSLT_SPACE = 0, XSLT_COMMENT, XSLT_DOCTYPE,
21 XSLT_TAG, XSLT_ENTITY, XSLT_ANY
24 /*****************************************************************************/
29 include common "common.rl";
31 # Line counting machine
33 action xslt_ccallback {
42 std_internal_newline(XSLT_LANG)
45 std_newline(XSLT_LANG)
47 case CHECK_BLANK_ENTRY:
48 check_blank_entry(XSLT_LANG)
54 newline %{ entity = INTERNAL_NL; } %xslt_ccallback
58 (nonnewline - ws) @comment
63 newline %{ entity = INTERNAL_NL; } %xslt_ccallback
73 newline %{ entity = INTERNAL_NL; } %xslt_ccallback
83 newline %{ entity = INTERNAL_NL; } %xslt_ccallback
87 (nonnewline - ws) @code
89 xslt_string = xslt_sq_str | xslt_dq_str | xslt_cdata_str;
92 spaces ${ entity = XSLT_SPACE; } => xslt_ccallback;
95 newline ${ entity = NEWLINE; } => xslt_ccallback;
96 ^space ${ entity = XSLT_ANY; } => xslt_ccallback;
101 action xslt_ecallback {
102 callback(XSLT_LANG, xslt_entities[entity], cint(ts), cint(te));
105 xslt_entity := 'TODO:';
108 /************************* Required for every parser *************************/
110 /* Parses a string buffer with XSLT markup.
112 * @param *buffer The string to parse.
113 * @param length The length of the string to parse.
114 * @param count Integer flag specifying whether or not to count lines. If yes,
115 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
116 * machine optimized for returning entity positions.
117 * @param *callback Callback function. If count is set, callback is called for
118 * every line of code, comment, or blank with 'lcode', 'lcomment', and
119 * 'lblank' respectively. Otherwise callback is called for each entity found.
121 void parse_xslt(char *buffer, int length, int count,
122 void (*callback) (const char *lang, const char *entity, int start, int end)
127 cs = (count) ? xslt_en_xslt_line : xslt_en_xslt_entity;
130 // if no newline at EOF; callback contents of last line
131 if (count) { process_last_line(XSLT_LANG) }
136 /*****************************************************************************/