Merge pull request #239 from octo/scanner
scanner: Don't call unread() after reading EOF.
This commit is contained in:
commit
061bf373e4
@ -552,7 +552,7 @@ func (s *Scanner) scanDigits(ch rune, base, n int) rune {
|
||||
s.err("illegal char escape")
|
||||
}
|
||||
|
||||
if n != start {
|
||||
if n != start && ch != eof {
|
||||
// we scanned all digits, put the last non digit char back,
|
||||
// only if we read anything at all
|
||||
s.unread()
|
||||
|
@ -593,14 +593,40 @@ func countNewlines(s string) int {
|
||||
return n
|
||||
}
|
||||
|
||||
func TestScanHeredocRegexpCompile(t *testing.T) {
|
||||
func TestScanDigitsUnread(t *testing.T) {
|
||||
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 {
|
||||
s := New([]byte(c))
|
||||
fmt.Printf("START %q\n", c)
|
||||
|
||||
for {
|
||||
tok := s.Scan()
|
||||
|
Loading…
Reference in New Issue
Block a user