1 // groovy.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_GROOVY_PARSER_H
5 #define OHCOUNT_GROOVY_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *GROOVY_LANG = LANG_GROOVY;
12 // the languages entities
13 const char *groovy_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 GROOVY_SPACE = 0, GROOVY_COMMENT, GROOVY_STRING, GROOVY_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action groovy_ccallback {
40 std_internal_newline(GROOVY_LANG)
43 std_newline(GROOVY_LANG)
49 escaped_newline %{ entity = INTERNAL_NL; } %groovy_ccallback
53 (nonnewline - ws) @comment
55 groovy_block_comment =
57 newline %{ entity = INTERNAL_NL; } %groovy_ccallback
61 (nonnewline - ws) @comment
63 groovy_comment = groovy_line_comment | groovy_block_comment;
67 escaped_newline %{ entity = INTERNAL_NL; } %groovy_ccallback
77 escaped_newline %{ entity = INTERNAL_NL; } %groovy_ccallback
85 groovy_string = groovy_sq_str | groovy_dq_str;
88 spaces ${ entity = GROOVY_SPACE; } => groovy_ccallback;
91 newline ${ entity = NEWLINE; } => groovy_ccallback;
92 ^space ${ entity = GROOVY_ANY; } => groovy_ccallback;
97 action groovy_ecallback {
98 callback(GROOVY_LANG, groovy_entities[entity], cint(ts), cint(te),
102 groovy_line_comment_entity = '//' (escaped_newline | nonnewline)*;
103 groovy_block_comment_entity = '/*' any* :>> '*/';
104 groovy_comment_entity =
105 groovy_line_comment_entity | groovy_block_comment_entity;
108 space+ ${ entity = GROOVY_SPACE; } => groovy_ecallback;
109 groovy_comment_entity ${ entity = GROOVY_COMMENT; } => groovy_ecallback;
115 /* Parses a string buffer with Groovy code.
117 * @param *buffer The string to parse.
118 * @param length The length of the string to parse.
119 * @param count Integer flag specifying whether or not to count lines. If yes,
120 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
121 * machine optimized for returning entity positions.
122 * @param *callback Callback function. If count is set, callback is called for
123 * every line of code, comment, or blank with 'lcode', 'lcomment', and
124 * 'lblank' respectively. Otherwise callback is called for each entity found.
126 void parse_groovy(char *buffer, int length, int count,
127 void (*callback) (const char *lang, const char *entity, int s,
134 cs = (count) ? groovy_en_groovy_line : groovy_en_groovy_entity;
137 // if no newline at EOF; callback contents of last line
138 if (count) { process_last_line(GROOVY_LANG) }