blob: 80904b5da6971213656f3793195cfbd80676865e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
* @LANG: c++
*/
#include <iostream>
#include <string.h>
using std::cout;
using std::endl;
%%{
machine foo;
action hit_5 {c == 5}
action done { cout << " done" << endl; }
action inc {c++;}
# The any* includes '\n' when hit_5 is true, so use guarded concatenation.
main := (any @inc)* :> '\n' when hit_5 @done;
}%%
%% write data noerror;
void test( const char *str )
{
int cs = foo_start;
int c = 0;
const char *p = str;
const char *pe = str + strlen( str );
cout << "run:" << endl;
%% write exec;
if ( cs >= foo_first_final )
cout << " success" << endl;
else
cout << " failure" << endl;
cout << endl;
}
int main()
{
test( "12345\n" ); // success
test( "\n2345\n" ); // success, first newline ignored
test( "1234\n" ); // failure, didn't get 5 chars before newline.
return 0;
}
#ifdef _____OUTPUT_____
run:
done
success
run:
done
success
run:
failure
#endif
|