scanner: remove pos 0 hack which is no longer needed (#10935)

pull/10950/head
Daniel Däschle 2021-07-25 00:13:07 +02:00 committed by GitHub
parent f691a80145
commit a09324faa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 10 deletions

View File

@ -98,8 +98,8 @@ pub fn (mut b Builder) writeln(s string) {
b << byte(`\n`) b << byte(`\n`)
} }
// buf == 'hello world'
// last_n(5) returns 'world' // last_n(5) returns 'world'
// buf == 'hello world'
pub fn (b &Builder) last_n(n int) string { pub fn (b &Builder) last_n(n int) string {
if n > b.len { if n > b.len {
return '' return ''
@ -108,8 +108,8 @@ pub fn (b &Builder) last_n(n int) string {
return x.bytestr() return x.bytestr()
} }
// buf == 'hello world'
// after(6) returns 'world' // after(6) returns 'world'
// buf == 'hello world'
pub fn (b &Builder) after(n int) string { pub fn (b &Builder) after(n int) string {
if n >= b.len { if n >= b.len {
return '' return ''
@ -133,7 +133,7 @@ pub fn (mut b Builder) str() string {
return s return s
} }
// free - manually free the contents of the buffer // free is for manually freeing the contents of the buffer
[unsafe] [unsafe]
pub fn (mut b Builder) free() { pub fn (mut b Builder) free() {
unsafe { free(b.data) } unsafe { free(b.data) }

View File

@ -688,11 +688,6 @@ fn (mut s Scanner) text_scan() token.Token {
s.is_inter_end = true s.is_inter_end = true
s.is_inter_start = false s.is_inter_start = false
} }
if s.pos == 0 && next_char == ` ` {
// If a single letter name at the start of the file, increment
// Otherwise the scanner would be stuck at s.pos = 0
s.pos++
}
return s.new_token(.name, name, name.len) return s.new_token(.name, name, name.len)
} else if c.is_digit() || (c == `.` && nextc.is_digit()) { } else if c.is_digit() || (c == `.` && nextc.is_digit()) {
// `123`, `.123` // `123`, `.123`

View File

@ -0,0 +1,5 @@
vlib/v/scanner/tests/position_0_err.vv:1:1: error: unused variable: `i`
1 | i := 'hello'
| ^
2 | x := 3
3 | y := 2

View File

@ -0,0 +1,4 @@
i := 'hello'
x := 3
y := 2
println(x + y)

View File

@ -1,5 +1,4 @@
// TODO: @medvednikov: autofree on script mode does not work when first variable is on position 0 due to the code in `cgen.v:1115`
v := 't' v := 't'
s := '${v}.tmp' s := '${v}.tmp'
println(s) println(s)