scanner: fix err pos related to num literals

pull/4978/head
Ruofan XU 2020-05-21 21:20:36 +08:00 committed by GitHub
parent 9888bacad5
commit aba09a7e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/bin_lit_without_digit_err.v:2:14: error: number part of this binary is not provided
1 | fn main() {
2 | println(0b)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0b)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/bin_lit_wrong_digit_err.v:2:18: error: this binary number has unsuitable digit `2`
1 | fn main() {
2 | println(0b1112)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0b1112)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/dec_lit_wrong_digit_err.v:2:18: error: this number has unsuitable digit `q`
1 | fn main() {
2 | println(12345q)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(12345q)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/float_lit_exp_not_integer_err.v:2:17: error: exponential part should be integer
1 | fn main() {
2 | println(45e2.5)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(45e2.5)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/float_lit_exp_without_digit_err.v:2:14: error: exponent has no digits
1 | fn main() {
2 | println(2E)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(2E)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/float_lit_too_many_points_err.v:2:19: error: too many decimal points in number
1 | fn main() {
2 | println(123.45.67)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(123.45.67)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/hex_lit_without_digit_err.v:2:14: error: number part of this hexadecimal is not provided
1 | fn main() {
2 | println(0x)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0x)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/hex_lit_wrong_digit_err.v:2:18: error: this hexadecimal number has unsuitable digit `g`
1 | fn main() {
2 | println(0x111g)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0x111g)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/oct_lit_without_digit_err.v:2:14: error: number part of this octal is not provided
1 | fn main() {
2 | println(0o)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0o)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/oct_lit_wrong_digit_err.v:2:18: error: this octal number has unsuitable digit `8`
1 | fn main() {
2 | println(0o1118)
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
println(0o1118)
}

View File

@ -174,9 +174,11 @@ fn (mut s Scanner) ident_bin_number() string {
s.pos++
}
if start_pos + 2 == s.pos {
s.pos-- // adjust error position
s.error('number part of this binary is not provided')
}
else if has_wrong_digit {
s.pos-- // adjust error position
s.error('this binary number has unsuitable digit `${first_wrong_digit.str()}`')
}
number := filter_num_sep(s.text.str, start_pos, s.pos)
@ -203,9 +205,11 @@ fn (mut s Scanner) ident_hex_number() string {
s.pos++
}
if start_pos + 2 == s.pos {
s.pos-- // adjust error position
s.error('number part of this hexadecimal is not provided')
}
else if has_wrong_digit {
s.pos-- // adjust error position
s.error('this hexadecimal number has unsuitable digit `${first_wrong_digit.str()}`')
}
number := filter_num_sep(s.text.str, start_pos, s.pos)
@ -232,9 +236,11 @@ fn (mut s Scanner) ident_oct_number() string {
s.pos++
}
if start_pos + 2 == s.pos {
s.pos-- // adjust error position
s.error('number part of this octal is not provided')
}
else if has_wrong_digit {
s.pos-- // adjust error position
s.error('this octal number has unsuitable digit `${first_wrong_digit.str()}`')
}
number := filter_num_sep(s.text.str, start_pos, s.pos)
@ -335,10 +341,12 @@ fn (mut s Scanner) ident_dec_number() string {
}
if has_wrong_digit {
// error check: wrong digit
s.pos-- // adjust error position
s.error('this number has unsuitable digit `${first_wrong_digit.str()}`')
}
else if s.text[s.pos - 1] in [`e`, `E`] {
// error check: 5e
s.pos-- // adjust error position
s.error('exponent has no digits')
}
else if s.pos < s.text.len && s.text[s.pos] == `.` && !is_range && !is_float_without_fraction && !call_method {