1 // fortranfree.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
3 /************************* Required for every parser *************************/
4 #ifndef OHCOUNT_FORTRANFREE_PARSER_H
5 #define OHCOUNT_FORTRANFREE_PARSER_H
7 #include "../parser_macros.h"
9 // the name of the language
10 const char *FORTRANFREE_LANG = LANG_FORTRANFREE;
12 // the languages entities
13 const char *ffree_entities[] = {
14 "space", "comment", "string", "any"
17 // constants associated with the entities
19 FFREE_SPACE = 0, FFREE_COMMENT, FFREE_STRING, FFREE_ANY
22 /*****************************************************************************/
27 include common "common.rl";
29 # Line counting machine
31 action ffree_ccallback {
40 std_internal_newline(FORTRANFREE_LANG)
43 std_newline(FORTRANFREE_LANG)
47 ffree_comment = '!' @comment nonnewline*;
51 newline %{ entity = INTERNAL_NL; } %ffree_ccallback
59 newline %{ entity = INTERNAL_NL; } %ffree_ccallback
65 ffree_string = ffree_sq_str | ffree_dq_str;
68 spaces ${ entity = FFREE_SPACE; } => ffree_ccallback;
71 newline ${ entity = NEWLINE; } => ffree_ccallback;
72 ^space ${ entity = FFREE_ANY; } => ffree_ccallback;
77 action ffree_ecallback {
78 callback(FORTRANFREE_LANG, ffree_entities[entity], cint(ts), cint(te),
82 ffree_comment_entity = '!' nonnewline*;
85 space+ ${ entity = FFREE_SPACE; } => ffree_ecallback;
86 ffree_comment_entity ${ entity = FFREE_COMMENT; } => ffree_ecallback;
92 /* Parses a string buffer with Fortran Freeform code.
94 * @param *buffer The string to parse.
95 * @param length The length of the string to parse.
96 * @param count Integer flag specifying whether or not to count lines. If yes,
97 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
98 * machine optimized for returning entity positions.
99 * @param *callback Callback function. If count is set, callback is called for
100 * every line of code, comment, or blank with 'lcode', 'lcomment', and
101 * 'lblank' respectively. Otherwise callback is called for each entity found.
103 void parse_fortranfree(char *buffer, int length, int count,
104 void (*callback) (const char *lang, const char *entity,
105 int s, int e, void *udata),
111 cs = (count) ? fortranfree_en_ffree_line : fortranfree_en_ffree_entity;
114 // if no newline at EOF; callback contents of last line
115 if (count) { process_last_line(FORTRANFREE_LANG) }