/usr/share/doc/re2c/examples/go/eof
// Code generated by re2c, DO NOT EDIT. //line "go/eof/04_generic_api_sentinel.re":1 //go:generate re2go $INPUT -o $OUTPUT package main import "testing" // Returns "fake" terminating null if cursor has reached limit. func peek(str string, cursor int, limit int) byte { if cursor >= limit { return 0 // fake null } else { return str[cursor] } } // Expects a string without terminating null. func lex(str string) int { var cursor int limit := len(str) count := 0 loop: //line "go/eof/04_generic_api_sentinel.go":25 { var yych byte yych = peek(str, cursor, limit) switch (yych) { case 0x00: goto yy2 case ' ': goto yy6 case 'a': fallthrough case 'b': fallthrough case 'c': fallthrough case 'd': fallthrough case 'e': fallthrough case 'f': fallthrough case 'g': fallthrough case 'h': fallthrough case 'i': fallthrough case 'j': fallthrough case 'k': fallthrough case 'l': fallthrough case 'm': fallthrough case 'n': fallthrough case 'o': fallthrough case 'p': fallthrough case 'q': fallthrough case 'r': fallthrough case 's': fallthrough case 't': fallthrough case 'u': fallthrough case 'v': fallthrough case 'w': fallthrough case 'x': fallthrough case 'y': fallthrough case 'z': goto yy9 default: goto yy4 } yy2: cursor += 1 //line "go/eof/04_generic_api_sentinel.re":29 { return count } //line "go/eof/04_generic_api_sentinel.go":93 yy4: cursor += 1 //line "go/eof/04_generic_api_sentinel.re":28 { return -1 } //line "go/eof/04_generic_api_sentinel.go":98 yy6: cursor += 1 yych = peek(str, cursor, limit) switch (yych) { case ' ': goto yy6 default: goto yy8 } yy8: //line "go/eof/04_generic_api_sentinel.re":31 { goto loop } //line "go/eof/04_generic_api_sentinel.go":111 yy9: cursor += 1 yych = peek(str, cursor, limit) switch (yych) { case 'a': fallthrough case 'b': fallthrough case 'c': fallthrough case 'd': fallthrough case 'e': fallthrough case 'f': fallthrough case 'g': fallthrough case 'h': fallthrough case 'i': fallthrough case 'j': fallthrough case 'k': fallthrough case 'l': fallthrough case 'm': fallthrough case 'n': fallthrough case 'o': fallthrough case 'p': fallthrough case 'q': fallthrough case 'r': fallthrough case 's': fallthrough case 't': fallthrough case 'u': fallthrough case 'v': fallthrough case 'w': fallthrough case 'x': fallthrough case 'y': fallthrough case 'z': goto yy9 default: goto yy11 } yy11: //line "go/eof/04_generic_api_sentinel.re":30 { count += 1; goto loop } //line "go/eof/04_generic_api_sentinel.go":174 } //line "go/eof/04_generic_api_sentinel.re":32 } func TestLex(t *testing.T) { var tests = []struct { res int str string }{ {0, ""}, {3, "one two three"}, {-1, "f0ur"}, } for _, x := range tests { t.Run(x.str, func(t *testing.T) { res := lex(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