Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
usr
/
share
/
doc
/
re2c
/
examples
/
go
/
eof
/
Filename :
01_sentinel.go
back
Copy
// Code generated by re2c, DO NOT EDIT. //line "go/eof/01_sentinel.re":1 //go:generate re2go $INPUT -o $OUTPUT package main import "testing" // expect a null-terminated string func lex(str string) int { var cursor int count := 0 loop: //line "go/eof/01_sentinel.go":15 { var yych byte yych = str[cursor] 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/01_sentinel.re":18 { return count } //line "go/eof/01_sentinel.go":83 yy4: cursor += 1 //line "go/eof/01_sentinel.re":17 { return -1 } //line "go/eof/01_sentinel.go":88 yy6: cursor += 1 yych = str[cursor] switch (yych) { case ' ': goto yy6 default: goto yy8 } yy8: //line "go/eof/01_sentinel.re":20 { goto loop } //line "go/eof/01_sentinel.go":101 yy9: cursor += 1 yych = str[cursor] 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/01_sentinel.re":19 { count += 1; goto loop } //line "go/eof/01_sentinel.go":164 } //line "go/eof/01_sentinel.re":21 } func TestLex(t *testing.T) { var tests = []struct { res int str string }{ {0, "\000"}, {3, "one two three\000"}, {-1, "f0ur\000"}, } 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) } }) } }