Merge pull request #239 from octo/scanner

scanner: Don't call unread() after reading EOF.
This commit is contained in:
Mitchell Hashimoto 2018-04-03 10:01:18 -07:00 committed by GitHub
commit 061bf373e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View File

@ -552,7 +552,7 @@ func (s *Scanner) scanDigits(ch rune, base, n int) rune {
s.err("illegal char escape") s.err("illegal char escape")
} }
if n != start { if n != start && ch != eof {
// we scanned all digits, put the last non digit char back, // we scanned all digits, put the last non digit char back,
// only if we read anything at all // only if we read anything at all
s.unread() s.unread()

View File

@ -593,14 +593,40 @@ func countNewlines(s string) int {
return n return n
} }
func TestScanHeredocRegexpCompile(t *testing.T) { func TestScanDigitsUnread(t *testing.T) {
cases := []string{ cases := []string{
"0\xe1\n<<ȸ\nhello\nworld\nȸ", "M=0\"\\00",
"M=\"\\00",
"\"\\00",
"M=[\"\\00",
"U{\"\\00",
"\"\n{}#\n\"\\00",
"M=[[\"\\00",
"U{d=0\"\\U00",
"#\n\"\\x00",
"m=[[[\"\\00",
}
for _, c := range cases {
s := New([]byte(c))
for {
tok := s.Scan()
if tok.Type == token.EOF {
break
}
t.Logf("s.Scan() = %s", tok)
}
}
}
func TestScanHeredocRegexpCompile(t *testing.T) {
cases := []string{
"0\xe1\n<<ȸ\nhello\nworld\nȸ",
} }
for _, c := range cases { for _, c := range cases {
s := New([]byte(c)) s := New([]byte(c))
fmt.Printf("START %q\n", c)
for { for {
tok := s.Scan() tok := s.Scan()