summaryrefslogtreecommitdiff
path: root/test/ragel.d/conderr1.rl
blob: 4e1288c0a7befbd5410936aa72706d0ace8f2173 (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
60
61
/* 
 * @LANG: c++
 */

#include <iostream>
#include <string.h>
using std::cout;
using std::endl;

%%{
	machine foo;

	action c {c}
	main := 
		( ( 'a' when c )+ ) $err{ cout << "  bail" << endl; }
		'\n';
}%%

%% write data noerror;

void test( int c, const char *str )
{
	int cs = foo_start;
	const char *p = str;
	const char *pe = str + strlen( str );
	const char *eof = pe;

	cout << "run:" << endl;
	%% write exec;
	if ( cs >= foo_first_final )
		cout << "  success" << endl;
	else
		cout << "  failure" << endl;
	cout << endl;
}

int main()
{
	test( 1, "aa\n" );
	test( 1, "ab\n" );
	test( 0, "aa\n" );
	test( 0, "ab\n" );
	return 0;
}

##### OUTPUT #####
run:
  success

run:
  bail
  failure

run:
  bail
  failure

run:
  bail
  failure