Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/tools/vvet/tests/parens_space_a.out

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/tools/vvet/tests/parens_space_a.vv

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/tools/vvet/tests/parens_space_b.out

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/tools/vvet/tests/parens_space_b.vv

This file was deleted.

4 changes: 1 addition & 3 deletions cmd/tools/vvet/vvet.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
spytheman marked this conversation as resolved.
Show resolved Hide resolved
$if trace_parse_vet_file ? {
eprintln('> ${@MOD}.${@FN} path: ${path}')
}
Expand All @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions vlib/v/scanner/scanner.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
`[` {
Expand Down Expand Up @@ -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}')
Expand Down
Loading