1 // ada.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_ADA_PARSER_H
5 #define OHCOUNT_ADA_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *ADA_LANG = LANG_ADA;
12 // the languages entities
13 const char *ada_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 ADA_SPACE = 0, ADA_COMMENT, ADA_STRING, ADA_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action ada_ccallback {
40 std_internal_newline(ADA_LANG)
47 ada_comment = '--' @comment nonnewline*;
49 ada_string = '"' @code [^\r\n\f"]* '"';
52 spaces ${ entity = ADA_SPACE; } => ada_ccallback;
55 newline ${ entity = NEWLINE; } => ada_ccallback;
56 ^space ${ entity = ADA_ANY; } => ada_ccallback;
61 action ada_ecallback {
62 callback(ADA_LANG, ada_entities[entity], cint(ts), cint(te), userdata);
65 ada_comment_entity = '--' nonnewline*;
68 space+ ${ entity = ADA_SPACE; } => ada_ecallback;
69 ada_comment_entity ${ entity = ADA_COMMENT; } => ada_ecallback;
75 /************************* Required for every parser *************************/
77 /* Parses a string buffer with Ada code.
79 * @param *buffer The string to parse.
80 * @param length The length of the string to parse.
81 * @param count Integer flag specifying whether or not to count lines. If yes,
82 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
83 * machine optimized for returning entity positions.
84 * @param *callback Callback function. If count is set, callback is called for
85 * every line of code, comment, or blank with 'lcode', 'lcomment', and
86 * 'lblank' respectively. Otherwise callback is called for each entity found.
88 void parse_ada(char *buffer, int length, int count,
89 void (*callback) (const char *lang, const char *entity, int s,
96 cs = (count) ? ada_en_ada_line : ada_en_ada_entity;
99 // if no newline at EOF; callback contents of last line
100 if (count) { process_last_line(ADA_LANG) }
105 /*****************************************************************************/