1 // actionscript.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_ACTIONSCRIPT_PARSER_H
5 #define OHCOUNT_ACTIONSCRIPT_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *AS_LANG = LANG_ACTIONSCRIPT;
12 // the languages entities
13 const char *as_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 AS_SPACE = 0, AS_COMMENT, AS_STRING, AS_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
40 std_internal_newline(AS_LANG)
47 as_line_comment = '//' @comment nonnewline*;
50 newline %{ entity = INTERNAL_NL; } %as_ccallback
54 (nonnewline - ws) @comment
56 as_comment = as_line_comment | as_block_comment;
58 as_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
59 as_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
60 as_ml_str = '<![CDATA[' @code (
61 newline %{ entity = INTERNAL_NL; } %as_ccallback
65 (nonnewline - ws) @code
67 as_string = as_sq_str | as_dq_str | as_ml_str;
70 spaces ${ entity = AS_SPACE; } => as_ccallback;
73 newline ${ entity = NEWLINE; } => as_ccallback;
74 ^space ${ entity = AS_ANY; } => as_ccallback;
80 callback(AS_LANG, as_entities[entity], cint(ts), cint(te), userdata);
83 as_line_comment_entity = '//' nonnewline*;
84 as_block_comment_entity = '/*' any* :>> '*/';
85 as_comment_entity = as_line_comment_entity | as_block_comment_entity;
88 space+ ${ entity = AS_SPACE; } => as_ecallback;
89 as_comment_entity ${ entity = AS_COMMENT; } => as_ecallback;
95 /************************* Required for every parser *************************/
97 /* Parses a string buffer with Actionscript code.
99 * @param *buffer The string to parse.
100 * @param length The length of the string to parse.
101 * @param count Integer flag specifying whether or not to count lines. If yes,
102 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
103 * machine optimized for returning entity positions.
104 * @param *callback Callback function. If count is set, callback is called for
105 * every line of code, comment, or blank with 'lcode', 'lcomment', and
106 * 'lblank' respectively. Otherwise callback is called for each entity found.
108 void parse_actionscript(char *buffer, int length, int count,
109 void (*callback) (const char *lang, const char *entity,
110 int s, int e, void *udata),
116 cs = (count) ? actionscript_en_as_line : actionscript_en_as_entity;
119 // if no newline at EOF; callback contents of last line
120 if (count) { process_last_line(AS_LANG) }
125 /*****************************************************************************/