Fixes recursion bug in disambiguate_in().
[ohcount] / doc / examples / parser_doc_2
1 /************************* Required for every parser *************************/
2
3 /* Parses a string buffer with C/C++ code.
4  *
5  * @param *buffer The string to parse.
6  * @param length The length of the string to parse.
7  * @param count Integer flag specifying whether or not to count lines. If yes,
8  *   uses the Ragel machine optimized for counting. Otherwise uses the Ragel
9  *   machine optimized for returning entity positions.
10  * @param *callback Callback function. If count is set, callback is called for
11  *   every line of code, comment, or blank with 'lcode', 'lcomment', and
12  *   'lblank' respectively. Otherwise callback is called for each entity found.
13  */
14 void parse_c(char *buffer, int length, int count,
15              void (*callback) (const char *lang, const char *entity, int s,
16                                int e, void *udata),
17              void *userdata
18   ) {
19   init
20
21   %% write init;
22   cs = (count) ? c_en_c_line : c_en_c_entity;
23   %% write exec;
24
25   // if no newline at EOF; callback contents of last line
26   if (count) { process_last_line(C_LANG) }
27 }
28
29 #endif
30
31 /*****************************************************************************/