1 // automake.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef RAGEL_AUTOMAKE_PARSER
5 #define RAGEL_AUTOMAKE_PARSER
7 #include "ragel_parser_macros.h"
9 // the name of the language
10 const char *AM_LANG = "automake";
12 // the languages entities
13 const char *am_entities[] = {
14 "space", "comment", "string", "any",
17 // constants associated with the entities
19 AM_SPACE = 0, AM_COMMENT, AM_STRING, AM_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
40 std_internal_newline(AM_LANG)
47 am_comment = '#' @comment nonnewline*;
49 am_sq_str = '\'' @code ([^\r\n\f'\\] | '\\' nonnewline)* '\'';
50 am_dq_str = '"' @code ([^\r\n\f"\\] | '\\' nonnewline)* '"';
51 am_string = am_sq_str | am_dq_str;
54 spaces ${ entity = AM_SPACE; } => am_ccallback;
57 newline ${ entity = NEWLINE; } => am_ccallback;
58 ^space ${ entity = AM_ANY; } => am_ccallback;
64 callback(AM_LANG, am_entities[entity], cint(ts), cint(te));
70 /************************* Required for every parser *************************/
72 /* Parses a string buffer with Automake code.
74 * @param *buffer The string to parse.
75 * @param length The length of the string to parse.
76 * @param count Integer flag specifying whether or not to count lines. If yes,
77 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
78 * machine optimized for returning entity positions.
79 * @param *callback Callback function. If count is set, callback is called for
80 * every line of code, comment, or blank with 'lcode', 'lcomment', and
81 * 'lblank' respectively. Otherwise callback is called for each entity found.
83 void parse_automake(char *buffer, int length, int count,
84 void (*callback) (const char *lang, const char *entity, int start, int end)
89 cs = (count) ? automake_en_am_line : automake_en_am_entity;
92 // if no newline at EOF; callback contents of last line
93 if (count) { process_last_line(AM_LANG) }
98 /*****************************************************************************/