summaryrefslogtreecommitdiff
path: root/test/ragel.d/scan7.rl
blob: f8ed9a43c57fa825bb0139080fae023278426781 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * @LANG: c
 */

#include <string.h>
#include <stdio.h>

/*
 * DEMONSTRATS FAILURE TO CALL LEAVING ACTIONS
 * leave on lag not called
 * leave swith3a not called
 */

char * ts ;
char * te ;
int act ;
int token ;

%%{
	machine scanner;

	# Warning: changing the patterns or the input string will affect the
	# coverage of the scanner action types.
	main := |*
		'a' %{
			printf( "-> leave on last\n" );
		}
		=> {
			printf( "%s", "on last     " );
			if ( p + 1 == te )
				printf( "%s", "yes" );
			printf( "%s", "\n" );
		};

		'b'+ %{
			printf( "-> leave on next\n" );
		}
		=> {
			printf( "%s", "on next     " );
			if ( p + 1 == te )
				printf( "%s", "yes" );
			printf( "%s", "\n" );
		};

		( 'c1' 'dxxx'? ) %{
			printf( "-> leave on lag\n" );
		}
		=> {
			printf( "%s", "on lag      " );
			if ( p + 1 == te )
				printf( "%s", "yes" );
			printf( "%s", "\n" );
		};

		'd1' %{
			printf( "-> leave lm switch1\n" );
		}
		=> {
			printf( "%s", "lm switch1  " );
			if ( p + 1 == te )
				printf( "%s", "yes" );
			printf( "%s", "\n" );
		};
		'd2' %{
			printf( "-> leave lm switch2\n" );
		}
		=> {
			printf( "%s", "lm switch2  " );
			if ( p + 1 == te )
				printf( "%s", "yes" );
			printf( "%s", "\n" );
		};

		[d0-9]+ '.' @{printf("dot\n");} '+' => { printf( "fake out" ); };

		( 'e1' '...'? ) %{printf("-> leave lm switch3a\n"); } => {printf("lm switch3a\n");};
		( 'e2' '...'? ) %{printf("-> leave lm switch3b\n"); } => {printf("lm switch3b\n");};
		[e0-9]+ '...' => {printf("lm switch4\n");};

		'.' => { printf( ".\n" ); };
		'\n';
	*|;
}%%

%% write data;
int cs;
int blen;
char buffer[1024];

void init()
{
	%% write init;
}

void exec( char *data, int len )
{
	char *p = data;
	char *pe = data + len;
	char *eof = pe;
	%% write exec;
}

void finish( )
{
	if ( cs >= scanner_first_final )
		printf( "ACCEPT\n" );
	else
		printf( "FAIL\n" );
}

char *inp[] = {
"abbc1d1d2d1..d2..e1.e2....\n",
};

int inplen = 1;

int main( )
{
	int i;
	for ( i = 0; i < inplen; i++ ) {
		init();
		exec( inp[i], strlen(inp[i]) );
		finish();
	}
	return 0;
}

##### OUTPUT #####
-> leave on last
on last     yes
-> leave on next
on next     yes
on lag      yes
-> leave lm switch1
dot
lm switch1  yes
-> leave lm switch2
dot
lm switch2  yes
-> leave lm switch1
dot
lm switch1  yes
.
.
-> leave lm switch2
dot
lm switch2  yes
.
.
lm switch3a
.
-> leave lm switch3b
lm switch3b
.
ACCEPT