1 // xslt.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_XSLT_PARSER_H
5 #define OHCOUNT_XSLT_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *XSLT_LANG = 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
61 xslt_sq_str = '\'' ([^\r\n\f'\\] | '\\' nonnewline)* '\'' @code;
62 xslt_dq_str = '"' ([^\r\n\f"\\] | '\\' nonnewline)* '"' @code;
65 newline %{ entity = INTERNAL_NL; } %xslt_ccallback
69 (nonnewline - ws) @code
71 xslt_string = xslt_sq_str | xslt_dq_str | xslt_cdata_str;
74 spaces ${ entity = XSLT_SPACE; } => xslt_ccallback;
77 newline ${ entity = NEWLINE; } => xslt_ccallback;
78 ^space ${ entity = XSLT_ANY; } => xslt_ccallback;
83 action xslt_ecallback {
84 callback(XSLT_LANG, xslt_entities[entity], cint(ts), cint(te), userdata);
87 xslt_comment_entity = '<!--' any* :>> '-->';
90 space+ ${ entity = XSLT_SPACE; } => xslt_ecallback;
91 xslt_comment_entity ${ entity = XSLT_COMMENT; } => xslt_ecallback;
97 /************************* Required for every parser *************************/
99 /* Parses a string buffer with XSLT markup.
101 * @param *buffer The string to parse.
102 * @param length The length of the string to parse.
103 * @param count Integer flag specifying whether or not to count lines. If yes,
104 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
105 * machine optimized for returning entity positions.
106 * @param *callback Callback function. If count is set, callback is called for
107 * every line of code, comment, or blank with 'lcode', 'lcomment', and
108 * 'lblank' respectively. Otherwise callback is called for each entity found.
110 void parse_xslt(char *buffer, int length, int count,
111 void (*callback) (const char *lang, const char *entity, int s,
118 cs = (count) ? xslt_en_xslt_line : xslt_en_xslt_entity;
121 // if no newline at EOF; callback contents of last line
122 if (count) { process_last_line(XSLT_LANG) }
127 /*****************************************************************************/