tokstart => ts and tokend => te
[ragel.git] / test / atoi1.rl
blobea706c8cb0479ac2b6dc97b1d77476a1ce920165
1 /*
2  * @LANG: indep
3  */
4 bool neg;
5 int val;
6 %%
7 val = 0;
8 neg = false;
9 %%{
10         machine AtoI;
12         action begin {
13                 neg = false;
14                 val = 0;
15         }
17         action see_neg {
18                 neg = true;
19         }
21         action add_digit { 
22                 val = val * 10 + (fc - 48);
23         }
25         action finish {
26                 if ( neg ) {
27                         val = -1 * val;
28                 }
29         }
30         action print {
31                 printi val;
32                 prints "\n";
33         }
35         atoi = (
36                 ('-'@see_neg | '+')? (digit @add_digit)+
37         ) >begin %finish;
39         main := atoi '\n' @print;
40 }%%
41 /* _____INPUT_____
42 "1\n"
43 "12\n"
44 "222222\n"
45 "+2123\n"
46 "213 3213\n"
47 "-12321\n"
48 "--123\n"
49 "-99\n"
50 " -3000\n"
51 _____INPUT_____ */
53 /* _____OUTPUT_____
55 ACCEPT
57 ACCEPT
58 222222
59 ACCEPT
60 2123
61 ACCEPT
62 FAIL
63 -12321
64 ACCEPT
65 FAIL
66 -99
67 ACCEPT
68 FAIL
69 _____OUTPUT_____ */