scanner: fix special case - 0 at the end

pull/3831/head
SleepyRoy 2020-02-25 01:01:51 +08:00 committed by GitHub
parent aae14f4eb4
commit 96da5b33c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -354,7 +354,7 @@ fn (s mut Scanner) scan() ScanRes {
} }
mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped
// for 0b, 0o, 0x the heading zero shouldn't be jumped // for 0b, 0o, 0x the heading zero shouldn't be jumped
if c == `0` && start_pos < s.text.len && !s.text[start_pos].is_digit() { if start_pos == s.text.len || (c == `0` && !s.text[start_pos].is_digit()) {
prefix_zero_num-- prefix_zero_num--
} }
s.pos += prefix_zero_num // jump these zeros s.pos += prefix_zero_num // jump these zeros

View File

@ -348,7 +348,7 @@ pub fn (s mut Scanner) scan() token.Token {
} }
mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped mut prefix_zero_num := start_pos - s.pos // how many prefix zeros should be jumped
// for 0b, 0o, 0x the heading zero shouldn't be jumped // for 0b, 0o, 0x the heading zero shouldn't be jumped
if c == `0` && start_pos < s.text.len && !s.text[start_pos].is_digit() { if start_pos == s.text.len || (c == `0` && !s.text[start_pos].is_digit()) {
prefix_zero_num-- prefix_zero_num--
} }
s.pos += prefix_zero_num // jump these zeros s.pos += prefix_zero_num // jump these zeros