summaryrefslogtreecommitdiff
path: root/test/ragel.d/args1.rl
blob: e4f8332df1745a3d6327964c0793f6e960f0d20b (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* 
 * @LANG: c++
 *
 * This is a conds test modified to exercise actions arguments.
 */

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

%%{
	machine foo;

	action c(v) { $v }

	action c1 {i}
	action c2 {j}

	action one {"one"}
	action pr(str) { cout << "  " $str << endl;}

	main := (
			[a-z] |
			('\n' when c(c1) @pr( one ) )
		)*
		('\n' when c({j}) @pr( {"two"} ) );
}%%

%% write data noerror;

void test( int i, int j, const char *str )
{
	int cs = foo_start;
	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( 0, 0, "hi\n\n" );
	test( 1, 0, "hi\n\n" );
	test( 0, 1, "hi\n" );
	test( 0, 1, "hi\n\n" );
	test( 1, 1, "hi\n" );
	test( 1, 1, "hi\n\n" );
	test( 1, 1, "hi\n\nx" );
	return 0;
}

##### OUTPUT #####
run:
  failure

run:
  one
  one
  failure

run:
  two
  success

run:
  two
  failure

run:
  one
  two
  success

run:
  one
  two
  one
  two
  success

run:
  one
  two
  one
  two
  failure