1 // groovy.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_GROOVY_PARSER
5 #define RAGEL_GROOVY_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *GROOVY_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, entity, cint(ts), cint(te));
101 groovy_entity := 'TODO:';
104 /* Parses a string buffer with Groovy code.
106 * @param *buffer The string to parse.
107 * @param length The length of the string to parse.
108 * @param count Integer flag specifying whether or not to count lines. If yes,
109 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
110 * machine optimized for returning entity positions.
111 * @param *callback Callback function. If count is set, callback is called for
112 * every line of code, comment, or blank with 'lcode', 'lcomment', and
113 * 'lblank' respectively. Otherwise callback is called for each entity found.
115 void parse_groovy(char *buffer, int length, int count,
116 void (*callback) (const char *lang, const char *entity, int start, int end)
121 cs = (count) ? groovy_en_groovy_line : groovy_en_groovy_entity;
124 // if no newline at EOF; callback contents of last line
125 if (count) { process_last_line(GROOVY_LANG) }