1 // blitzmax.rl written by Bruce A Henderson (http://brucey.net)
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_BLITZMAX_PARSER_H
5 #define OHCOUNT_BLITZMAX_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *BLITZMAX_LANG = LANG_BLITZMAX;
12 // the languages entities
13 const char *blitzmax_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 BLITZMAX_SPACE = 0, BLITZMAX_COMMENT, BLITZMAX_STRING, BLITZMAX_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action blitzmax_ccallback {
40 std_internal_newline(BLITZMAX_LANG)
43 std_newline(BLITZMAX_LANG)
47 blitzmax_line_comment = '\'' @comment nonnewline*;
48 blitzmax_rem_block_comment =
50 newline %{ entity = INTERNAL_NL; } %blitzmax_ccallback
54 (nonnewline - ws) @comment
55 )* :>> (/end rem/i | /endrem/i);
57 blitzmax_comment = blitzmax_line_comment | blitzmax_rem_block_comment;
59 blitzmax_string = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
62 spaces ${ entity = BLITZMAX_SPACE; } => blitzmax_ccallback;
65 newline ${ entity = NEWLINE; } => blitzmax_ccallback;
66 ^space ${ entity = BLITZMAX_ANY; } => blitzmax_ccallback;
71 action blitzmax_ecallback {
72 callback(BLITZMAX_LANG, blitzmax_entities[entity], cint(ts), cint(te),
76 blitzmax_line_comment_entity = '\'' nonnewline*;
77 blitzmax_rem_block_comment_entity =
79 newline %{ entity = INTERNAL_NL; } %blitzmax_ecallback
84 )* :>> (/end rem/i | /endrem/i);
86 blitzmax_comment_entity = blitzmax_line_comment_entity | blitzmax_line_comment_entity;
89 space+ ${ entity = BLITZMAX_SPACE; } => blitzmax_ecallback;
90 blitzmax_comment_entity ${ entity = BLITZMAX_COMMENT; } => blitzmax_ecallback;
96 /************************* Required for every parser *************************/
98 /* Parses a string buffer with BlitzMax code.
100 * @param *buffer The string to parse.
101 * @param length The length of the string to parse.
102 * @param count Integer flag specifying whether or not to count lines. If yes,
103 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
104 * machine optimized for returning entity positions.
105 * @param *callback Callback function. If count is set, callback is called for
106 * every line of code, comment, or blank with 'lcode', 'lcomment', and
107 * 'lblank' respectively. Otherwise callback is called for each entity found.
109 void parse_blitzmax(char *buffer, int length, int count,
110 void (*callback) (const char *lang, const char *entity,
111 int s, int e, void *udata),
117 cs = (count) ? blitzmax_en_blitzmax_line : blitzmax_en_blitzmax_entity;
120 // if no newline at EOF; callback contents of last line
121 if (count) { process_last_line(BLITZMAX_LANG) }
126 /*****************************************************************************/