'\r' is now recognized in common.rl.
[ohcount] / ext / ohcount_native / ragel_parsers / common.rl
1 %%{
2 machine common;
3
4 # common definitions
5
6 # whitespace, non-printables
7 ws = [\t ];
8 spaces = [\t ]+;
9 newline = ('\r\n' | '\r' | '\n' | '\f');
10 escaped_newline = '\\' newline;
11 nonnewline = any - [\r\n\f];
12 nonprintable_char = cntrl - [\r\n\f];
13
14 # numbers
15 dec_num = digit+;
16 hex_num = 0 [xX] [a-fA-F0-9]+;
17 oct_num = 0 [0-7]+;
18 integer = [+\-]? (hex_num | oct_num | dec_num);
19 float = [+\-]? ((digit* '.' digit+) | (digit+ '.' digit*) | digit+)
20         [eE] [+\-]? digit+;
21
22 # common actions
23
24 action ls { if (!line_start) line_start = ts; }
25
26 action code {
27   if (!line_contains_code && !line_start) line_start = ts;
28   line_contains_code = 1;
29 }
30
31 action comment {
32   if (!line_contains_code) {
33     whole_line_comment = 1;
34     if (!line_start) line_start = ts;
35   }
36 }
37
38 # common conditionals
39
40 action no_code { !line_contains_code }
41 action no_comment { !whole_line_comment }
42 action no_code_or_comment { !line_contains_code && !whole_line_comment }
43
44 action starts_line {
45   p == buffer || *(p-1) == '\r' || *(p-1) == '\n' || *(p-1) == '\f'
46 }
47 action starts_line2 {
48   p == buffer || *(p-2) == '\r' || *(p-2) == '\n' || *(p-2) == '\f'
49 }
50 }%%