1 // autoconf.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_AUTOCONF_PARSER_H
5 #define OHCOUNT_AUTOCONF_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *AC_LANG = LANG_AUTOCONF;
12 // the languages entities
13 const char *ac_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 AC_SPACE = 0, AC_COMMENT, AC_STRING, AC_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
40 std_internal_newline(AC_LANG)
47 action ac_str_nc_res { nest_count = 0; }
48 action ac_str_nc_inc { nest_count++; }
49 action ac_str_nc_dec { nest_count--; }
51 ac_comment = 'dnl' @comment (ws+ nonnewline+)?;
54 '[' >ac_str_nc_res @code (
55 newline %{ entity = INTERNAL_NL; } %ac_ccallback
59 '[' @ac_str_nc_inc @code
61 ']' @ac_str_nc_dec @code
63 (nonnewline - ws - [\[\]]) @code
64 )* :>> (']' when { nest_count == 0 });
67 spaces ${ entity = AC_SPACE; } => ac_ccallback;
70 newline ${ entity = NEWLINE; } => ac_ccallback;
71 ^space ${ entity = AC_ANY; } => ac_ccallback;
77 callback(AC_LANG, ac_entities[entity], cint(ts), cint(te), userdata);
80 ac_comment_entity = 'dnl' ws+ nonnewline*;
83 space+ ${ entity = AC_SPACE; } => ac_ecallback;
84 ac_comment_entity ${ entity = AC_COMMENT; } => ac_ecallback;
90 /************************* Required for every parser *************************/
92 /* Parses a string buffer with Autoconf code.
94 * @param *buffer The string to parse.
95 * @param length The length of the string to parse.
96 * @param count Integer flag specifying whether or not to count lines. If yes,
97 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
98 * machine optimized for returning entity positions.
99 * @param *callback Callback function. If count is set, callback is called for
100 * every line of code, comment, or blank with 'lcode', 'lcomment', and
101 * 'lblank' respectively. Otherwise callback is called for each entity found.
103 void parse_autoconf(char *buffer, int length, int count,
104 void (*callback) (const char *lang, const char *entity,
105 int s, int e, void *udata),
113 cs = (count) ? autoconf_en_ac_line : autoconf_en_ac_entity;
116 // if no newline at EOF; callback contents of last line
117 if (count) { process_last_line(AC_LANG) }
122 /*****************************************************************************/