1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
// mxml.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
/************************* Required for every parser *************************/
#ifndef OHCOUNT_MXML_PARSER_H
#define OHCOUNT_MXML_PARSER_H
#include "../parser_macros.h"
// the name of the language
const char *MXML_LANG = LANG_MXML;
// the languages entities
const char *mxml_entities[] = {
"space", "comment", "doctype",
"tag", "entity", "any"
};
// constants associated with the entities
enum {
MXML_SPACE = 0, MXML_COMMENT, MXML_DOCTYPE,
MXML_TAG, MXML_ENTITY, MXML_ANY
};
/*****************************************************************************/
#include "css.h"
#include "actionscript.h"
%%{
machine mxml;
write data;
include common "common.rl";
#EMBED(css)
#EMBED(actionscript)
# Line counting machine
action mxml_ccallback {
switch(entity) {
case MXML_SPACE:
ls
break;
case MXML_ANY:
code
break;
case INTERNAL_NL:
std_internal_newline(MXML_LANG)
break;
case NEWLINE:
std_newline(MXML_LANG)
break;
case CHECK_BLANK_ENTRY:
check_blank_entry(MXML_LANG)
}
}
mxml_comment =
'<!--' @comment (
newline %{ entity = INTERNAL_NL; } %mxml_ccallback
|
ws
|
(nonnewline - ws) @comment
)* :>> '-->';
mxml_sq_str =
'\'' @code (
newline %{ entity = INTERNAL_NL; } %mxml_ccallback
|
ws
|
[^\r\n\f\t '\\] @code
|
'\\' nonnewline @code
)* '\'';
mxml_dq_str =
'"' @code (
newline %{ entity = INTERNAL_NL; } %mxml_ccallback
|
ws
|
[^\r\n\f\t "\\] @code
|
'\\' nonnewline @code
)* '"';
mxml_string = mxml_sq_str | mxml_dq_str;
ws_or_inl = (ws | newline @{ entity = INTERNAL_NL; } %mxml_ccallback);
mxml_css_entry = '<mx:Style>' @code;
mxml_css_outry = '</mx:Style>' @check_blank_outry @code;
mxml_css_line := |*
mxml_css_outry @{ p = ts; fret; };
# unmodified CSS patterns
spaces ${ entity = CSS_SPACE; } => css_ccallback;
css_comment;
css_string;
newline ${ entity = NEWLINE; } => css_ccallback;
^space ${ entity = CSS_ANY; } => css_ccallback;
*|;
mxml_as_entry = '<mx:Script>' @code;
mxml_as_outry = '</mx:Script>' @check_blank_outry @code;
mxml_as_line := |*
mxml_as_outry @{ p = ts; fret; };
# unmodified Actionscript patterns
spaces ${ entity = AS_SPACE; } => as_ccallback;
as_comment;
as_string;
newline ${ entity = NEWLINE; } => as_ccallback;
^space ${ entity = AS_ANY; } => as_ccallback;
*|;
mxml_line := |*
mxml_css_entry @{ entity = CHECK_BLANK_ENTRY; } @mxml_ccallback
@{ saw(CSS_LANG); } => { fcall mxml_css_line; };
mxml_as_entry @{ entity = CHECK_BLANK_ENTRY; } @mxml_ccallback
@{ saw(AS_LANG); } => { fcall mxml_as_line; };
# standard MXML patterns
spaces ${ entity = MXML_SPACE; } => mxml_ccallback;
mxml_comment;
mxml_string;
newline ${ entity = NEWLINE; } => mxml_ccallback;
^space ${ entity = MXML_ANY; } => mxml_ccallback;
*|;
# Entity machine
action mxml_ecallback {
callback(MXML_LANG, mxml_entities[entity], cint(ts), cint(te), userdata);
}
mxml_css_entry_entity = '<mx:Style>';
mxml_css_outry_entity = '</mx:Style>';
mxml_css_entity := |*
mxml_css_outry_entity @{ fret; };
# unmodified CSS patterns
space+ ${ entity = CSS_SPACE; } => css_ecallback;
css_comment_entity ${ entity = CSS_COMMENT; } => css_ecallback;
# TODO:
^space;
*|;
mxml_as_entry_entity = '<mx:Script>';
mxml_as_outry_entity = '</mx:Script>';
mxml_as_entity := |*
mxml_as_outry_entity @{ fret; };
# unmodified Actionscript patterns
space+ ${ entity = AS_SPACE; } => as_ecallback;
as_comment_entity ${ entity = AS_COMMENT; } => as_ecallback;
# TODO:
^space;
*|;
mxml_comment_entity = '<!--' any* :>> '-->';
mxml_entity := |*
# TODO: mxml_ecallback for mxml_*_{entry,outry}_entity
mxml_css_entry_entity => { fcall mxml_css_entity; };
mxml_as_entry_entity => { fcall mxml_as_entity; };
# standard MXML patterns
space+ ${ entity = MXML_SPACE; } => mxml_ecallback;
mxml_comment_entity ${ entity = MXML_COMMENT; } => mxml_ecallback;
# TODO:
^space;
*|;
}%%
/************************* Required for every parser *************************/
/* Parses a string buffer with MXML markup.
*
* @param *buffer The string to parse.
* @param length The length of the string to parse.
* @param count Integer flag specifying whether or not to count lines. If yes,
* uses the Ragel machine optimized for counting. Otherwise uses the Ragel
* machine optimized for returning entity positions.
* @param *callback Callback function. If count is set, callback is called for
* every line of code, comment, or blank with 'lcode', 'lcomment', and
* 'lblank' respectively. Otherwise callback is called for each entity found.
*/
void parse_mxml(char *buffer, int length, int count,
void (*callback) (const char *lang, const char *entity, int s,
int e, void *udata),
void *userdata
) {
init
%% write init;
cs = (count) ? mxml_en_mxml_line : mxml_en_mxml_entity;
%% write exec;
// if no newline at EOF; callback contents of last line
if (count) { process_last_line(MXML_LANG) }
}
#endif
/*****************************************************************************/
|