mirror of
https://github.com/vlang/v.git
synced 2025-09-13 01:16:02 -04:00
vet, parser, scanner: remove vetting for spaces after / before parens (#21437)
This commit is contained in:
parent
f8f7c99e2d
commit
ea1df0260e
@ -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
|
|
@ -1,4 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
_ = 1 + ( 1 + 2)
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
@ -1,4 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
_ = 1 + (1 + 2 )
|
|
||||||
}
|
|
||||||
|
|
@ -110,10 +110,8 @@ fn (mut vt Vet) vet_file(path string) {
|
|||||||
prefs.is_vsh = path.ends_with('.vsh')
|
prefs.is_vsh = path.ends_with('.vsh')
|
||||||
mut table := ast.new_table()
|
mut table := ast.new_table()
|
||||||
vt.vprintln("vetting file '${path}'...")
|
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)
|
vt.stmts(file.stmts)
|
||||||
// Transfer errors from scanner and parser
|
|
||||||
vt.errors << errors
|
|
||||||
source_lines := os.read_lines(vt.file) or { []string{} }
|
source_lines := os.read_lines(vt.file) or { []string{} }
|
||||||
for ln, line in source_lines {
|
for ln, line in source_lines {
|
||||||
vt.vet_line(source_lines, line, ln)
|
vt.vet_line(source_lines, line, ln)
|
||||||
|
@ -9,7 +9,6 @@ import v.ast
|
|||||||
import v.token
|
import v.token
|
||||||
import v.pref
|
import v.pref
|
||||||
import v.util
|
import v.util
|
||||||
import v.vet
|
|
||||||
import v.errors
|
import v.errors
|
||||||
import os
|
import os
|
||||||
import hash.fnv1a
|
import hash.fnv1a
|
||||||
@ -257,7 +256,7 @@ pub fn parse_file(path string, mut table ast.Table, comments_mode scanner.Commen
|
|||||||
return res
|
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 ? {
|
$if trace_parse_vet_file ? {
|
||||||
eprintln('> ${@MOD}.${@FN} path: ${path}')
|
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{}
|
warnings: []errors.Warning{}
|
||||||
}
|
}
|
||||||
p.set_path(path)
|
p.set_path(path)
|
||||||
vet_errors := p.scanner.vet_errors
|
|
||||||
file := p.parse()
|
file := p.parse()
|
||||||
unsafe { p.free_scanner() }
|
unsafe { p.free_scanner() }
|
||||||
return file, vet_errors
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut p Parser) parse() &ast.File {
|
pub fn (mut p Parser) parse() &ast.File {
|
||||||
|
@ -8,7 +8,6 @@ import strconv
|
|||||||
import v.token
|
import v.token
|
||||||
import v.pref
|
import v.pref
|
||||||
import v.util
|
import v.util
|
||||||
import v.vet
|
|
||||||
import v.errors
|
import v.errors
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.mathutil
|
import v.mathutil
|
||||||
@ -60,7 +59,6 @@ pub mut:
|
|||||||
errors []errors.Error
|
errors []errors.Error
|
||||||
warnings []errors.Warning
|
warnings []errors.Warning
|
||||||
notices []errors.Notice
|
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
|
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
|
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)
|
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)
|
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) {
|
fn (mut s Scanner) trace[T](fbase string, x &T) {
|
||||||
if s.file_base == fbase {
|
if s.file_base == fbase {
|
||||||
println('> s.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
|
println('> s.trace | ${fbase:-10s} | ${voidptr(x):16} | ${x}')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user