mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vet: prohibit spaces after (
This commit is contained in:
parent
a1073105e1
commit
d4d552fb00
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -45,6 +45,7 @@ jobs:
|
||||
run: ./v build-tools
|
||||
- name: v vet
|
||||
run: |
|
||||
./v vet vlib/v/scanner
|
||||
./v vet vlib/v/parser
|
||||
./v vet vlib/v/ast
|
||||
./v vet vlib/v/gen/cgen.v
|
||||
|
@ -60,11 +60,12 @@ mut:
|
||||
|
||||
// for tests
|
||||
pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||
s := scanner.new_scanner(text, .skip_comments, false)
|
||||
pref:= &pref.Preferences{}
|
||||
s := scanner.new_scanner(text, .skip_comments, pref)
|
||||
mut p := Parser{
|
||||
scanner: s
|
||||
table: table
|
||||
pref: &pref.Preferences{}
|
||||
pref: pref
|
||||
scope: scope
|
||||
global_scope: &ast.Scope{
|
||||
start_pos: 0
|
||||
@ -77,7 +78,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||
}
|
||||
|
||||
pub fn parse_text(text string, b_table &table.Table, pref &pref.Preferences, scope, global_scope &ast.Scope) ast.File {
|
||||
s := scanner.new_scanner(text, .skip_comments, pref.is_fmt)
|
||||
s := scanner.new_scanner(text, .skip_comments, pref)
|
||||
mut p := Parser{
|
||||
scanner: s
|
||||
table: b_table
|
||||
@ -100,7 +101,7 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
||||
// panic(err)
|
||||
// }
|
||||
mut p := Parser{
|
||||
scanner: scanner.new_scanner_file(path, comments_mode, pref.is_fmt)
|
||||
scanner: scanner.new_scanner_file(path, comments_mode, pref)
|
||||
comments_mode: comments_mode
|
||||
table: b_table
|
||||
file_name: path
|
||||
@ -126,6 +127,8 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
||||
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
|
||||
exit(1)
|
||||
}
|
||||
//if pref.is_vet && p.scanner.text.contains('( '\n ') {
|
||||
//}
|
||||
return p.parse()
|
||||
}
|
||||
|
||||
|
@ -224,8 +224,9 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
}
|
||||
} else if p.tok.kind.is_infix() {
|
||||
// return early for deref assign `*x = 2` goes to prefix expr
|
||||
if p.tok.kind == .mul && p.tok.line_nr != p.prev_tok.line_nr && p.peek_tok2.kind ==
|
||||
.assign {
|
||||
if p.tok.kind == .mul &&
|
||||
p.tok.line_nr != p.prev_tok.line_nr &&
|
||||
p.peek_tok2.kind == .assign {
|
||||
return node
|
||||
}
|
||||
// continue on infix expr
|
||||
|
@ -48,6 +48,7 @@ pub mut:
|
||||
all_tokens []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
|
||||
tidx int
|
||||
eofs int
|
||||
pref &pref.Preferences
|
||||
}
|
||||
|
||||
/*
|
||||
@ -94,7 +95,8 @@ pub enum CommentsMode {
|
||||
}
|
||||
|
||||
// new scanner from file.
|
||||
pub fn new_scanner_file(file_path string, comments_mode CommentsMode, is_fmt bool) &Scanner {
|
||||
pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
|
||||
// is_fmt := pref.is_fmt
|
||||
if !os.exists(file_path) {
|
||||
verror("$file_path doesn't exist")
|
||||
}
|
||||
@ -102,15 +104,17 @@ pub fn new_scanner_file(file_path string, comments_mode CommentsMode, is_fmt boo
|
||||
verror(err)
|
||||
return voidptr(0)
|
||||
}
|
||||
mut s := new_scanner(raw_text, comments_mode, is_fmt) // .skip_comments)
|
||||
mut s := new_scanner(raw_text, comments_mode, pref) // .skip_comments)
|
||||
// s.init_fmt()
|
||||
s.file_path = file_path
|
||||
return s
|
||||
}
|
||||
|
||||
// new scanner from string.
|
||||
pub fn new_scanner(text string, comments_mode CommentsMode, is_fmt bool) &Scanner {
|
||||
pub fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
|
||||
is_fmt := pref.is_fmt
|
||||
s := &Scanner{
|
||||
pref: pref
|
||||
text: text
|
||||
is_print_line_on_error: true
|
||||
is_print_colored_error: true
|
||||
@ -768,6 +772,10 @@ 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] == ` ` {
|
||||
println('$s.file_path:$s.line_nr: Looks like you are adding a space after `(`')
|
||||
}
|
||||
return s.new_token(.lpar, '', 1)
|
||||
}
|
||||
`)` {
|
||||
|
Loading…
Reference in New Issue
Block a user