vet, parser, scanner: remove vetting for spaces after / before parens (#21437)

This commit is contained in:
Turiiya 2024-05-06 10:14:36 +02:00 committed by GitHub
parent f8f7c99e2d
commit ea1df0260e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 3 additions and 41 deletions

View file

@ -1,2 +0,0 @@
cmd/tools/vvet/tests/parens_space_a.vv:1: error: Looks like you are adding a space after `(`
Note: You can run `v fmt -w file.v` to fix these errors automatically

View file

@ -1,4 +0,0 @@
fn main() {
_ = 1 + ( 1 + 2)
}

View file

@ -1,2 +0,0 @@
cmd/tools/vvet/tests/parens_space_b.vv:1: error: Looks like you are adding a space before `)`
Note: You can run `v fmt -w file.v` to fix these errors automatically

View file

@ -1,4 +0,0 @@
fn main() {
_ = 1 + (1 + 2 )
}

View file

@ -110,10 +110,8 @@ fn (mut vt Vet) vet_file(path string) {
prefs.is_vsh = path.ends_with('.vsh')
mut table := ast.new_table()
vt.vprintln("vetting file '${path}'...")
file, errors := parser.parse_vet_file(path, mut table, prefs)
file := parser.parse_vet_file(path, mut table, prefs)
vt.stmts(file.stmts)
// Transfer errors from scanner and parser
vt.errors << errors
source_lines := os.read_lines(vt.file) or { []string{} }
for ln, line in source_lines {
vt.vet_line(source_lines, line, ln)

View file

@ -9,7 +9,6 @@ import v.ast
import v.token
import v.pref
import v.util
import v.vet
import v.errors
import os
import hash.fnv1a
@ -257,7 +256,7 @@ pub fn parse_file(path string, mut table ast.Table, comments_mode scanner.Commen
return res
}
pub fn parse_vet_file(path string, mut table_ ast.Table, pref_ &pref.Preferences) (&ast.File, []vet.Error) {
pub fn parse_vet_file(path string, mut table_ ast.Table, pref_ &pref.Preferences) &ast.File {
$if trace_parse_vet_file ? {
eprintln('> ${@MOD}.${@FN} path: ${path}')
}
@ -276,10 +275,9 @@ pub fn parse_vet_file(path string, mut table_ ast.Table, pref_ &pref.Preferences
warnings: []errors.Warning{}
}
p.set_path(path)
vet_errors := p.scanner.vet_errors
file := p.parse()
unsafe { p.free_scanner() }
return file, vet_errors
return file
}
pub fn (mut p Parser) parse() &ast.File {

View file

@ -8,7 +8,6 @@ import strconv
import v.token
import v.pref
import v.util
import v.vet
import v.errors
import v.ast
import v.mathutil
@ -60,7 +59,6 @@ pub mut:
errors []errors.Error
warnings []errors.Warning
notices []errors.Notice
vet_errors []vet.Error
should_abort bool // when too many errors/warnings/notices are accumulated, should_abort becomes true, and the scanner should stop
}
@ -810,17 +808,9 @@ pub fn (mut s Scanner) text_scan() token.Token {
return s.new_token(.chartoken, ident_char, ident_char.len + 2) // + two quotes
}
`(` {
// TODO: `$if vet {` for performance
if s.pref.is_vet && s.text[s.pos + 1] == ` ` {
s.vet_error('Looks like you are adding a space after `(`', .vfmt)
}
return s.new_token(.lpar, '', 1)
}
`)` {
// TODO: `$if vet {` for performance
if s.pref.is_vet && s.text[s.pos - 1] == ` ` {
s.vet_error('Looks like you are adding a space before `)`', .vfmt)
}
return s.new_token(.rpar, '', 1)
}
`[` {
@ -1813,18 +1803,6 @@ pub fn (mut s Scanner) error_with_pos(msg string, pos token.Pos) {
}
}
fn (mut s Scanner) vet_error(msg string, fix vet.FixKind) {
ve := vet.Error{
message: msg
file_path: s.file_path
pos: s.current_pos()
kind: .error
fix: fix
typ: .default
}
s.vet_errors << ve
}
fn (mut s Scanner) trace[T](fbase string, x &T) {
if s.file_base == fbase {
println('> s.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')