1 // fortranfixed.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_FORTRANFIXED_PARSER_H
5 #define OHCOUNT_FORTRANFIXED_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *FORTRANFIXED_LANG = LANG_FORTRANFIXED;
12 // the languages entities
13 const char *ffixed_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 FFIXED_SPACE = 0, FFIXED_COMMENT, FFIXED_STRING, FFIXED_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action ffixed_ccallback {
40 std_internal_newline(FORTRANFIXED_LANG)
43 std_newline(FORTRANFIXED_LANG)
47 ffixed_comment = 'C' @comment nonnewline*;
49 ffixed_sq_str = '\'' @code nonnewline* '\'';
50 ffixed_dq_str = '"' @code nonnewline* '"';
51 ffixed_string = ffixed_sq_str | ffixed_dq_str;
54 spaces ${ entity = FFIXED_SPACE; } => ffixed_ccallback;
57 newline ${ entity = NEWLINE; } => ffixed_ccallback;
58 ^space ${ entity = FFIXED_ANY; } => ffixed_ccallback;
63 action ffixed_ecallback {
64 callback(FORTRANFIXED_LANG, ffixed_entities[entity], cint(ts), cint(te),
68 ffixed_comment_entity = 'C' nonnewline*;
71 space+ ${ entity = FFIXED_SPACE; } => ffixed_ecallback;
72 ffixed_comment_entity ${ entity = FFIXED_COMMENT; } => ffixed_ecallback;
78 /* Parses a string buffer with Fortran Fixedform code.
80 * @param *buffer The string to parse.
81 * @param length The length of the string to parse.
82 * @param count Integer flag specifying whether or not to count lines. If yes,
83 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
84 * machine optimized for returning entity positions.
85 * @param *callback Callback function. If count is set, callback is called for
86 * every line of code, comment, or blank with 'lcode', 'lcomment', and
87 * 'lblank' respectively. Otherwise callback is called for each entity found.
89 void parse_fortranfixed(char *buffer, int length, int count,
90 void (*callback) (const char *lang, const char *entity,
91 int s, int e, void *udata),
97 cs = (count) ? fortranfixed_en_ffixed_line : fortranfixed_en_ffixed_entity;
100 // if no newline at EOF; callback contents of last line
101 if (count) { process_last_line(FORTRANFIXED_LANG) }