1 // mxml.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_MXML_PARSER_H
5 #define OHCOUNT_MXML_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *MXML_LANG = LANG_MXML;
12 // the languages entities
13 const char *mxml_entities[] = {
14 "space", "comment", "doctype",
15 "tag", "entity", "any"
18 // constants associated with the entities
20 MXML_SPACE = 0, MXML_COMMENT, MXML_DOCTYPE,
21 MXML_TAG, MXML_ENTITY, MXML_ANY
24 /*****************************************************************************/
27 #include "actionscript.h"
32 include common "common.rl";
36 # Line counting machine
38 action mxml_ccallback {
47 std_internal_newline(MXML_LANG)
50 std_newline(MXML_LANG)
52 case CHECK_BLANK_ENTRY:
53 check_blank_entry(MXML_LANG)
59 newline %{ entity = INTERNAL_NL; } %mxml_ccallback
63 (nonnewline - ws) @comment
68 newline %{ entity = INTERNAL_NL; } %mxml_ccallback
78 newline %{ entity = INTERNAL_NL; } %mxml_ccallback
86 mxml_string = mxml_sq_str | mxml_dq_str;
88 ws_or_inl = (ws | newline @{ entity = INTERNAL_NL; } %mxml_ccallback);
90 mxml_css_entry = '<mx:Style>' @code;
91 mxml_css_outry = '</mx:Style>' @check_blank_outry @code;
93 mxml_css_outry @{ p = ts; fret; };
94 # unmodified CSS patterns
95 spaces ${ entity = CSS_SPACE; } => css_ccallback;
98 newline ${ entity = NEWLINE; } => css_ccallback;
99 ^space ${ entity = CSS_ANY; } => css_ccallback;
102 mxml_as_entry = '<mx:Script>' @code;
103 mxml_as_outry = '</mx:Script>' @check_blank_outry @code;
105 mxml_as_outry @{ p = ts; fret; };
106 # unmodified Actionscript patterns
107 spaces ${ entity = AS_SPACE; } => as_ccallback;
110 newline ${ entity = NEWLINE; } => as_ccallback;
111 ^space ${ entity = AS_ANY; } => as_ccallback;
115 mxml_css_entry @{ entity = CHECK_BLANK_ENTRY; } @mxml_ccallback
116 @{ saw(CSS_LANG); } => { fcall mxml_css_line; };
117 mxml_as_entry @{ entity = CHECK_BLANK_ENTRY; } @mxml_ccallback
118 @{ saw(AS_LANG); } => { fcall mxml_as_line; };
119 # standard MXML patterns
120 spaces ${ entity = MXML_SPACE; } => mxml_ccallback;
123 newline ${ entity = NEWLINE; } => mxml_ccallback;
124 ^space ${ entity = MXML_ANY; } => mxml_ccallback;
129 action mxml_ecallback {
130 callback(MXML_LANG, mxml_entities[entity], cint(ts), cint(te), userdata);
133 mxml_css_entry_entity = '<mx:Style>';
134 mxml_css_outry_entity = '</mx:Style>';
135 mxml_css_entity := |*
136 mxml_css_outry_entity @{ fret; };
137 # unmodified CSS patterns
138 space+ ${ entity = CSS_SPACE; } => css_ecallback;
139 css_comment_entity ${ entity = CSS_COMMENT; } => css_ecallback;
144 mxml_as_entry_entity = '<mx:Script>';
145 mxml_as_outry_entity = '</mx:Script>';
147 mxml_as_outry_entity @{ fret; };
148 # unmodified Actionscript patterns
149 space+ ${ entity = AS_SPACE; } => as_ecallback;
150 as_comment_entity ${ entity = AS_COMMENT; } => as_ecallback;
155 mxml_comment_entity = '<!--' any* :>> '-->';
158 # TODO: mxml_ecallback for mxml_*_{entry,outry}_entity
159 mxml_css_entry_entity => { fcall mxml_css_entity; };
160 mxml_as_entry_entity => { fcall mxml_as_entity; };
161 # standard MXML patterns
162 space+ ${ entity = MXML_SPACE; } => mxml_ecallback;
163 mxml_comment_entity ${ entity = MXML_COMMENT; } => mxml_ecallback;
169 /************************* Required for every parser *************************/
171 /* Parses a string buffer with MXML markup.
173 * @param *buffer The string to parse.
174 * @param length The length of the string to parse.
175 * @param count Integer flag specifying whether or not to count lines. If yes,
176 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
177 * machine optimized for returning entity positions.
178 * @param *callback Callback function. If count is set, callback is called for
179 * every line of code, comment, or blank with 'lcode', 'lcomment', and
180 * 'lblank' respectively. Otherwise callback is called for each entity found.
182 void parse_mxml(char *buffer, int length, int count,
183 void (*callback) (const char *lang, const char *entity, int s,
190 cs = (count) ? mxml_en_mxml_line : mxml_en_mxml_entity;
193 // if no newline at EOF; callback contents of last line
194 if (count) { process_last_line(MXML_LANG) }
199 /*****************************************************************************/