1//go:generate re2go $INPUT -o $OUTPUT
2package main
3
4func Lex(str string) (a int, b int, c int) {
5	var cursor, marker int
6	/*!stags:re2c format = "\tvar @@ int\n"; */
7
8	/*!re2c
9	re2c:flags:tags = 1;
10	re2c:yyfill:enable = 0;
11	re2c:define:YYCTYPE = byte;
12	re2c:define:YYPEEK = "str[cursor]";
13	re2c:define:YYSKIP = "cursor += 1";
14	re2c:define:YYBACKUP  = "marker = cursor";
15	re2c:define:YYRESTORE = "cursor = marker";
16	re2c:define:YYSTAGP = "@@{tag} = cursor";
17	re2c:define:YYSTAGN = "@@{tag} = -1";
18	re2c:define:YYSHIFTSTAG = "@@{tag} += @@{shift}";
19
20	end = [\x00];
21
22	* {
23		return -2, -2, -2
24	}
25
26	@a [a]+ @b [b] @c [c]+ end {
27		return a, b, c
28	}
29
30	(@a [a]+ | @b [b]+ | @c [c]+) end {
31		return a, b, c
32	}
33
34	(@a [a] (@b [b])? @c [c])* end {
35		return a, b, c
36	}
37	*/
38}
39
40func main() {
41	if a, b, c := Lex("aabcc\000"); !(a == 0 && b == 2 && c == 3) {
42		panic("expected 0,2,3")
43	}
44	if a, b, c := Lex("aaa\000"); !(a == 0 && b == -1 && c == -1) {
45		panic("expected 0,-1,-1")
46	}
47	if a, b, c := Lex("acabc\000"); !(a == 2 && b == 3 && c == 4) {
48		panic("expected 2,3,4")
49	}
50	if a, b, c := Lex("abcac\000"); !(a == 3 && b == -1 && c == 4) {
51		panic("expected 3,-1,4")
52	}
53	if a, b, c := Lex("ab\000"); !(a == -2 && b == -2 && c == -2) {
54		panic("expected -2,-2,-2")
55	}
56}
57