1 // autoconf.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_AUTOCONF_PARSER
5 #define RAGEL_AUTOCONF_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *AC_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, entity, cint(ts), cint(te));
83 /************************* Required for every parser *************************/
85 /* Parses a string buffer with Autoconf code.
87 * @param *buffer The string to parse.
88 * @param length The length of the string to parse.
89 * @param count Integer flag specifying whether or not to count lines. If yes,
90 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
91 * machine optimized for returning entity positions.
92 * @param *callback Callback function. If count is set, callback is called for
93 * every line of code, comment, or blank with 'lcode', 'lcomment', and
94 * 'lblank' respectively. Otherwise callback is called for each entity found.
96 void parse_autoconf(char *buffer, int length, int count,
97 void (*callback) (const char *lang, const char *entity, int start, int end)
104 cs = (count) ? autoconf_en_ac_line : autoconf_en_ac_entity;
107 // if no newline at EOF; callback contents of last line
108 if (count) { process_last_line(AC_LANG) }
113 /*****************************************************************************/