1 // tcl.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_TCL_PARSER_H
5 #define OHCOUNT_TCL_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *TCL_LANG = LANG_TCL;
12 // the languages entities
13 const char *tcl_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 TCL_SPACE = 0, TCL_COMMENT, TCL_STRING, TCL_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action tcl_ccallback {
40 std_internal_newline(TCL_LANG)
49 escaped_newline %{ entity = INTERNAL_NL; } %tcl_ccallback
53 (nonnewline - ws) @comment
58 escaped_newline %{ entity = INTERNAL_NL; } %tcl_ccallback
68 spaces ${ entity = TCL_SPACE; } => tcl_ccallback;
71 newline ${ entity = NEWLINE; } => tcl_ccallback;
72 ^space ${ entity = TCL_ANY; } => tcl_ccallback;
77 action tcl_ecallback {
78 callback(TCL_LANG, tcl_entities[entity], cint(ts), cint(te), userdata);
81 tcl_comment_entity = '#' (escaped_newline | nonnewline)*;
84 space+ ${ entity = TCL_SPACE; } => tcl_ecallback;
85 tcl_comment_entity ${ entity = TCL_COMMENT; } => tcl_ecallback;
91 /************************* Required for every parser *************************/
93 /* Parses a string buffer with Tcl code.
95 * @param *buffer The string to parse.
96 * @param length The length of the string to parse.
97 * @param count Integer flag specifying whether or not to count lines. If yes,
98 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
99 * machine optimized for returning entity positions.
100 * @param *callback Callback function. If count is set, callback is called for
101 * every line of code, comment, or blank with 'lcode', 'lcomment', and
102 * 'lblank' respectively. Otherwise callback is called for each entity found.
104 void parse_tcl(char *buffer, int length, int count,
105 void (*callback) (const char *lang, const char *entity, int s,
112 cs = (count) ? tcl_en_tcl_line : tcl_en_tcl_entity;
115 // if no newline at EOF; callback contents of last line
116 if (count) { process_last_line(TCL_LANG) }
121 /*****************************************************************************/