1 // rexx.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_REXX_PARSER_H
5 #define OHCOUNT_REXX_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *REXX_LANG = LANG_REXX;
12 // the languages entities
13 const char *rexx_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 REXX_SPACE = 0, REXX_COMMENT, REXX_STRING, REXX_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action rexx_ccallback {
40 std_internal_newline(REXX_LANG)
43 std_newline(REXX_LANG)
47 action rexx_comment_nc_res { nest_count = 0; }
48 action rexx_comment_nc_inc { nest_count++; }
49 action rexx_comment_nc_dec { nest_count--; }
52 '/*' >rexx_comment_nc_res @comment (
53 newline %{ entity = INTERNAL_NL; } %rexx_ccallback
57 '/*' @rexx_comment_nc_inc @comment
59 '*/' @rexx_comment_nc_dec @comment
62 )* :>> ('*/' when { nest_count == 0 }) @comment;
64 rexx_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
65 rexx_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
66 rexx_string = rexx_sq_str | rexx_dq_str;
69 spaces ${ entity = REXX_SPACE; } => rexx_ccallback;
72 newline ${ entity = NEWLINE; } => rexx_ccallback;
73 ^space ${ entity = REXX_ANY; } => rexx_ccallback;
78 action rexx_ecallback {
79 callback(REXX_LANG, rexx_entities[entity], cint(ts), cint(te), userdata);
82 rexx_comment_entity = '/*' >rexx_comment_nc_res (
83 '/*' @rexx_comment_nc_inc
85 '*/' @rexx_comment_nc_dec
88 )* :>> ('*/' when { nest_count == 0 });
91 space+ ${ entity = REXX_SPACE; } => rexx_ecallback;
92 rexx_comment_entity ${ entity = REXX_COMMENT; } => rexx_ecallback;
98 /************************* Required for every parser *************************/
100 /* Parses a string buffer with Pike code.
102 * @param *buffer The string to parse.
103 * @param length The length of the string to parse.
104 * @param count Integer flag specifying whether or not to count lines. If yes,
105 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
106 * machine optimized for returning entity positions.
107 * @param *callback Callback function. If count is set, callback is called for
108 * every line of code, comment, or blank with 'lcode', 'lcomment', and
109 * 'lblank' respectively. Otherwise callback is called for each entity found.
111 void parse_rexx(char *buffer, int length, int count,
112 void (*callback) (const char *lang, const char *entity, int s,
121 cs = (count) ? rexx_en_rexx_line : rexx_en_rexx_entity;
124 // if no newline at EOF; callback contents of last line
125 if (count) { process_last_line(REXX_LANG) }
130 /*****************************************************************************/