1 /************************* Required for every parser *************************/
2 #ifndef OHCOUNT_COQ_PARSER_H
3 #define OHCOUNT_COQ_PARSER_H
5 #include "../parser_macros.h"
7 // the name of the language
8 const char *COQ_LANG = LANG_COQ;
10 // the languages entities
11 const char *coq_entities[] = {
12 "space", "comment", "string", "any"
15 // constants associated with the entities
17 COQ_SPACE = 0, COQ_COMMENT, COQ_STRING, COQ_ANY
20 /*****************************************************************************/
25 include common "common.rl";
27 # Line counting machine
29 action coq_ccallback {
38 std_internal_newline(COQ_LANG)
45 action coq_comment_nc_res { nest_count = 0; }
46 action coq_comment_nc_inc { nest_count++; }
47 action coq_comment_nc_dec { nest_count--; }
49 coq_nested_block_comment =
50 '(*' >coq_comment_nc_res @comment (
51 newline %{ entity = INTERNAL_NL; } %coq_ccallback
55 '(*' @coq_comment_nc_inc @comment
57 '*)' @coq_comment_nc_dec @comment
59 (nonnewline - ws) @comment
60 )* :>> ('*)' when { nest_count == 0 }) @comment;
62 coq_comment = coq_nested_block_comment;
66 newline %{ entity = INTERNAL_NL; } %coq_ccallback
74 spaces ${ entity = COQ_SPACE; } => coq_ccallback;
77 newline ${ entity = NEWLINE; } => coq_ccallback;
78 ^space ${ entity = COQ_ANY; } => coq_ccallback;
83 action coq_ecallback {
84 callback(COQ_LANG, coq_entities[entity], cint(ts), cint(te), userdata);
87 coq_comment_entity = '(*' >coq_comment_nc_res (
88 '(*' @coq_comment_nc_inc
90 '*)' @coq_comment_nc_dec
93 )* :>> ('*)' when { nest_count == 0 });
96 space+ ${ entity = COQ_SPACE; } => coq_ecallback;
97 coq_comment_entity ${ entity = COQ_COMMENT; } => coq_ecallback;
103 /************************* Required for every parser *************************/
105 /* Parses a string buffer with Coq code.
107 * @param *buffer The string to parse.
108 * @param length The length of the string to parse.
109 * @param count Integer flag specifying whether or not to count lines. If yes,
110 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
111 * machine optimized for returning entity positions.
112 * @param *callback Callback function. If count is set, callback is called for
113 * every line of code, comment, or blank with 'lcode', 'lcomment', and
114 * 'lblank' respectively. Otherwise callback is called for each entity found.
116 void parse_coq(char *buffer, int length, int count,
117 void (*callback) (const char *lang, const char *entity, int s,
126 cs = (count) ? coq_en_coq_line : coq_en_coq_entity;
129 // if no newline at EOF; callback contents of last line
130 if (count) { process_last_line(COQ_LANG) }
135 /*****************************************************************************/