1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_STRUCTURED_BASIC_PARSER_H
3 #define OHCOUNT_STRUCTURED_BASIC_PARSER_H
5 #include "../parser_macros.h"
7 // the name of the language
8 const char *SB_LANG = LANG_STRUCTURED_BASIC;
10 // the languages entities
11 const char *sb_entities[] = {
12 "space", "comment", "string", "any"
15 // constants associated with the entities
17 SB_SPACE = 0, SB_COMMENT, SB_STRING, SB_ANY,
20 /*****************************************************************************/
23 machine structured_basic;
25 include common "common.rl";
27 # Line counting machine
38 std_internal_newline(SB_LANG)
45 sb_comment = ('\'' | /rem/i) @comment nonnewline*;
47 sb_string = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
50 spaces ${ entity = SB_SPACE; } => sb_ccallback;
53 newline ${ entity = NEWLINE; } => sb_ccallback;
54 ^space ${ entity = SB_ANY; } => sb_ccallback;
60 callback(SB_LANG, sb_entities[entity], cint(ts), cint(te), userdata);
63 sb_comment_entity = ('\'' | /rem/i) nonnewline*;
66 space+ ${ entity = SB_SPACE; } => sb_ecallback;
67 sb_comment_entity ${ entity = SB_COMMENT; } => sb_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_structured_basic(char *buffer, int length, int count,
87 void (*callback) (const char *lang,
88 const char *entity, int s, int e,
95 cs = (count) ? structured_basic_en_sb_line : structured_basic_en_sb_entity;
98 // if no newline at EOF; callback contents of last line
99 if (count) { process_last_line(SB_LANG) }
104 /*****************************************************************************/