/usr/share/doc/re2c/examples/go/eof
// Code generated by re2c, DO NOT EDIT. //line "go/eof/02_bounds_checking.re":1 //go:generate re2go $INPUT -o $OUTPUT package main import ( "strings" "testing" ) //line "go/eof/02_bounds_checking.go":12 var YYMAXFILL int = 1 //line "go/eof/02_bounds_checking.re":9 // Expects YYMAXFILL-padded string. func lex(str string) int { var cursor int limit := len(str) count := 0 loop: //line "go/eof/02_bounds_checking.go":24 { var yych byte if (limit - cursor < 1) { return -1 } yych = str[cursor] switch (yych) { case 0x00: goto yy2 case ' ': goto yy6 case '\'': goto yy9 default: goto yy4 } yy2: cursor += 1 //line "go/eof/02_bounds_checking.re":27 { if limit - cursor == YYMAXFILL - 1 { return count } else { return -1 } } //line "go/eof/02_bounds_checking.go":51 yy4: cursor += 1 //line "go/eof/02_bounds_checking.re":24 { return -1 } //line "go/eof/02_bounds_checking.go":58 yy6: cursor += 1 if (limit - cursor < 1) { return -1 } yych = str[cursor] switch (yych) { case ' ': goto yy6 default: goto yy8 } yy8: //line "go/eof/02_bounds_checking.re":38 { goto loop } //line "go/eof/02_bounds_checking.go":76 yy9: cursor += 1 if (limit - cursor < 1) { return -1 } yych = str[cursor] switch (yych) { case '\'': goto yy11 case '\\': goto yy13 default: goto yy9 } yy11: cursor += 1 //line "go/eof/02_bounds_checking.re":34 { count += 1; goto loop } //line "go/eof/02_bounds_checking.go":98 yy13: cursor += 1 if (limit - cursor < 1) { return -1 } yych = str[cursor] goto yy9 } //line "go/eof/02_bounds_checking.re":41 } // Pad string with YYMAXFILL zeroes at the end. func pad(str string) string { return str + strings.Repeat("\000", YYMAXFILL) } func TestLex(t *testing.T) { var tests = []struct { res int str string }{ {0, ""}, {3, "'qu\000tes' 'are' 'fine: \\'' "}, {-1, "'unterminated\\'"}, } for _, x := range tests { t.Run(x.str, func(t *testing.T) { res := lex(pad(x.str)) if res != x.res { t.Errorf("got %d, want %d", res, x.res) } }) } }
.
Edit
..
Edit
01_sentinel.go
Edit
01_sentinel.re
Edit
02_bounds_checking.go
Edit
02_bounds_checking.re
Edit
03_eof_rule.go
Edit
03_eof_rule.re
Edit
04_generic_api_sentinel.go
Edit
04_generic_api_sentinel.re
Edit
05_generic_api_eof_rule.go
Edit
05_generic_api_eof_rule.re
Edit