1 // xmlschema.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_XMLSCHEMA_PARSER
5 #define RAGEL_XMLSCHEMA_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *XMLSCHEMA_LANG = "xmlschema";
12 // the languages entities
13 const char *xmlschema_entities[] = {
14 "space", "comment", "doctype",
15 "tag", "entity", "any"
18 // constants associated with the entities
20 XMLSCHEMA_SPACE = 0, XMLSCHEMA_COMMENT, XMLSCHEMA_DOCTYPE,
21 XMLSCHEMA_TAG, XMLSCHEMA_ENTITY, XMLSCHEMA_ANY
24 /*****************************************************************************/
29 include common "common.rl";
31 # Line counting machine
33 action xmlschema_ccallback {
42 std_internal_newline(XMLSCHEMA_LANG)
45 std_newline(XMLSCHEMA_LANG)
47 case CHECK_BLANK_ENTRY:
48 check_blank_entry(XMLSCHEMA_LANG)
54 newline %{ entity = INTERNAL_NL; } %xmlschema_ccallback
58 (nonnewline - ws) @comment
61 xmlschema_sq_str = '\'' ([^\r\n\f'\\] | '\\' nonnewline)* '\'' @code;
62 xmlschema_dq_str = '"' ([^\r\n\f"\\] | '\\' nonnewline)* '"' @code;
65 newline %{ entity = INTERNAL_NL; } %xmlschema_ccallback
69 (nonnewline - ws) @code
71 xmlschema_string = xmlschema_sq_str | xmlschema_dq_str | xmlschema_cdata_str;
74 spaces ${ entity = XMLSCHEMA_SPACE; } => xmlschema_ccallback;
77 newline ${ entity = NEWLINE; } => xmlschema_ccallback;
78 ^space ${ entity = XMLSCHEMA_ANY; } => xmlschema_ccallback;
83 action xmlschema_ecallback {
84 callback(XMLSCHEMA_LANG, xmlschema_entities[entity], cint(ts), cint(te));
87 xmlschema_comment_entity = '<!--' any* :>> '-->';
89 xmlschema_entity := |*
90 space+ ${ entity = XMLSCHEMA_SPACE; } => xmlschema_ecallback;
91 xmlschema_comment_entity ${ entity = XMLSCHEMA_COMMENT; } => xmlschema_ecallback;
98 /************************* Required for every parser *************************/
100 /* Parses a string buffer with XML Schema markup.
102 * @param *buffer The string to parse.
103 * @param length The length of the string to parse.
104 * @param count Integer flag specifying whether or not to count lines. If yes,
105 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
106 * machine optimized for returning entity positions.
107 * @param *callback Callback function. If count is set, callback is called for
108 * every line of code, comment, or blank with 'lcode', 'lcomment', and
109 * 'lblank' respectively. Otherwise callback is called for each entity found.
111 void parse_xmlschema(char *buffer, int length, int count,
112 void (*callback) (const char *lang, const char *entity, int start, int end)
117 cs = (count) ? xmlschema_en_xmlschema_line : xmlschema_en_xmlschema_entity;
120 // if no newline at EOF; callback contents of last line
121 if (count) { process_last_line(XMLSCHEMA_LANG) }
126 /*****************************************************************************/