1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_EIFFEL_PARSER_H
3 #define OHCOUNT_EIFFEL_PARSER_H
5 #include "../parser_macros.h"
7 // the name of the language
8 const char *EIFFEL_LANG = LANG_EIFFEL;
10 // the languages entities
11 const char *eiffel_entities[] = {
12 "space", "comment", "string", "any"
15 // constants associated with the entities
17 EIFFEL_SPACE = 0, EIFFEL_COMMENT, EIFFEL_STRING, EIFFEL_ANY
20 /*****************************************************************************/
25 include common "common.rl";
27 # Line counting machine
29 action eiffel_ccallback {
38 std_internal_newline(EIFFEL_LANG)
41 std_newline(EIFFEL_LANG)
45 eiffel_comment = '--' @comment nonnewline*;
47 eiffel_string = '"' @code [^\r\n\f"]* '"';
50 spaces ${ entity = EIFFEL_SPACE; } => eiffel_ccallback;
53 newline ${ entity = NEWLINE; } => eiffel_ccallback;
54 ^space ${ entity = EIFFEL_ANY; } => eiffel_ccallback;
59 action eiffel_ecallback {
60 callback(EIFFEL_LANG, eiffel_entities[entity], cint(ts), cint(te),
64 eiffel_comment_entity = '--' nonnewline*;
67 space+ ${ entity = EIFFEL_SPACE; } => eiffel_ecallback;
68 eiffel_comment_entity ${ entity = EIFFEL_COMMENT; } => eiffel_ecallback;
74 /************************* Required for every parser *************************/
76 /* Parses a string buffer with Eiffel code.
78 * @param *buffer The string to parse.
79 * @param length The length of the string to parse.
80 * @param count Integer flag specifying whether or not to count lines. If yes,
81 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
82 * machine optimized for returning entity positions.
83 * @param *callback Callback function. If count is set, callback is called for
84 * every line of code, comment, or blank with 'lcode', 'lcomment', and
85 * 'lblank' respectively. Otherwise callback is called for each entity found.
87 void parse_eiffel(char *buffer, int length, int count,
88 void (*callback) (const char *lang, const char *entity, int s,
95 cs = (count) ? eiffel_en_eiffel_line : eiffel_en_eiffel_entity;
98 // if no newline at EOF; callback contents of last line
99 if (count) { process_last_line(EIFFEL_LANG) }
104 /*****************************************************************************/