Renamed ragel_parser_defines.h to ragel_parser_macros.h; updated parsers.
[ohcount] / ext / ohcount_native / ragel_parser_macros.h
1 /* Sets the line_start variable to ts.
2  * This is typically used for the SPACE entity in the main action.
3  */
4 #define ls { if (!line_start) line_start = ts; }
5
6 /* The C equivalent of the Ragel 'code' action.
7  * This is tyically used in the main action for entities where Ragel actions
8  * cannot, for one reason or another, be used.
9  */
10 #define code {\
11   if (!line_contains_code && !line_start) line_start = ts; \
12   line_contains_code = 1; \
13 }
14
15 /* The C equivalent of the Ragel 'comment' action.
16  * This is typically unused, but here for consistency.
17  */
18 #define comment {\
19   if (!line_contains_code) { \
20     whole_line_comment = 1; \
21     if (!line_start) line_start = ts; \
22   } \
23 }
24
25 /* Executes standard line counting actions for INTERNAL_NL entities.
26  * This is typically used in the main action for the INTERNAL_NL entity.
27  * @param lang The language name string.
28  */
29 #define std_internal_newline(lang) { \
30   if (callback && p > line_start) { \
31     if (line_contains_code) \
32       callback(lang, "lcode", cint(line_start), cint(p)); \
33     else if (whole_line_comment) \
34       callback(lang, "lcomment", cint(line_start), cint(p)); \
35     else \
36       callback(lang, "lblank", cint(line_start), cint(p)); \
37   } \
38   whole_line_comment = 0; \
39   line_contains_code = 0; \
40   line_start = p; \
41 }
42
43 /* Executes standard line counting actions for NEWLINE entities.
44  * This is typically used in the main action for the NEWLINE entity.
45  * @param lang The language name string.
46  */
47 #define std_newline(lang) {\
48   if (callback && te > line_start) { \
49     if (line_contains_code) \
50       callback(lang, "lcode", cint(line_start), cint(te)); \
51     else if (whole_line_comment) \
52       callback(lang, "lcomment", cint(line_start), cint(te)); \
53     else \
54       callback(lang, "lblank", cint(ts), cint(te)); \
55   } \
56   whole_line_comment = 0; \
57   line_contains_code = 0; \
58   line_start = 0; \
59 }
60
61 /* Processes the last line for buffers that don't have a newline at EOF.
62  * This is typically used at the end of the parse_lang function after the Ragel
63  * parser has been executed.
64  * @param lang The language name string.
65  */
66 #define process_last_line(lang) {\
67   if ((whole_line_comment || line_contains_code) && callback) { \
68     if (line_contains_code) \
69       callback(lang, "lcode", cint(line_start), cint(pe)); \
70     else if (whole_line_comment) \
71       callback(lang, "lcomment", cint(line_start), cint(pe)); \
72   } \
73 }