1 // haxe.rl patched by Niel Drummond from actionscript version written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_HAXE_PARSER_H
5 #define OHCOUNT_HAXE_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *HX_LANG = LANG_HAXE;
12 // the languages entities
13 const char *hx_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 HX_SPACE = 0, HX_COMMENT, HX_STRING, HX_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
40 std_internal_newline(HX_LANG)
49 escaped_newline %{ entity = INTERNAL_NL; } %hx_ccallback
53 (nonnewline - ws) @comment
58 newline %{ entity = INTERNAL_NL; } %hx_ccallback
62 (nonnewline - ws) @comment
64 hx_comment = hx_line_comment | hx_block_comment;
66 hx_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
67 hx_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
68 hx_string = hx_sq_str | hx_dq_str;
71 spaces ${ entity = HX_SPACE; } => hx_ccallback;
74 newline ${ entity = NEWLINE; } => hx_ccallback;
75 ^space ${ entity = HX_ANY; } => hx_ccallback;
81 callback(HX_LANG, hx_entities[entity], cint(ts), cint(te), userdata);
83 hx_line_comment_entity = '//' nonnewline*;
84 hx_block_comment_entity = '/*' any* :>> '*/';
85 hx_comment_entity = hx_line_comment_entity | hx_block_comment_entity;
88 space+ ${ entity = HX_SPACE; } => hx_ecallback;
89 hx_comment_entity ${ entity = HX_COMMENT; } => hx_ecallback;
95 /************************* Required for every parser *************************/
97 /* Parses a string buffer with Haxe 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_haxe(char *buffer, int length, int count,
109 void (*callback) (const char *lang, const char *entity, int s,
116 cs = (count) ? haxe_en_hx_line : haxe_en_hx_entity;
119 // if no newline at EOF; callback contents of last line
120 if (count) { process_last_line(HX_LANG) }
125 /*****************************************************************************/