1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_CLASSIC_BASIC_PARSER_H
3 #define OHCOUNT_CLASSIC_BASIC_PARSER_H
5 #include "../parser_macros.h"
7 // the name of the language
8 const char *CB_LANG = LANG_CLASSIC_BASIC;
10 // the languages entities
11 const char *cb_entities[] = {
12 "space", "comment", "string", "any"
15 // constants associated with the entities
17 CB_SPACE = 0, CB_COMMENT, CB_STRING, CB_ANY,
20 /*****************************************************************************/
23 machine classic_basic;
25 include common "common.rl";
27 # Line counting machine
38 std_internal_newline(CB_LANG)
45 cb_comment = dec_num spaces ("'" | /rem/i) @comment nonnewline*;
47 cb_string = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
50 spaces ${ entity = CB_SPACE; } => cb_ccallback;
53 newline ${ entity = NEWLINE; } => cb_ccallback;
54 ^space ${ entity = CB_ANY; } => cb_ccallback;
60 callback(CB_LANG, cb_entities[entity], cint(ts), cint(te), userdata);
63 cb_comment_entity = ("'" | /rem/i ws+) nonnewline*;
66 space+ ${ entity = CB_SPACE; } => cb_ecallback;
67 cb_comment_entity ${ entity = CB_COMMENT; } => cb_ecallback;
73 /************************* Required for every parser *************************/
75 /* Parses a string buffer with Structured BASIC code.
77 * @param *buffer The string to parse.
78 * @param length The length of the string to parse.
79 * @param count Integer flag specifying whether or not to count lines. If yes,
80 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
81 * machine optimized for returning entity positions.
82 * @param *callback Callback function. If count is set, callback is called for
83 * every line of code, comment, or blank with 'lcode', 'lcomment', and
84 * 'lblank' respectively. Otherwise callback is called for each entity found.
86 void parse_classic_basic(char *buffer, int length, int count,
87 void (*callback) (const char *lang, const char *entity,
88 int s, int e, void *udata),
94 cs = (count) ? classic_basic_en_cb_line : classic_basic_en_cb_entity;
97 // if no newline at EOF; callback contents of last line
98 if (count) { process_last_line(CB_LANG) }
103 /*****************************************************************************/