vet: prohibit spaces after `(`
parent
a1073105e1
commit
d4d552fb00
|
@ -45,6 +45,7 @@ jobs:
|
||||||
run: ./v build-tools
|
run: ./v build-tools
|
||||||
- name: v vet
|
- name: v vet
|
||||||
run: |
|
run: |
|
||||||
|
./v vet vlib/v/scanner
|
||||||
./v vet vlib/v/parser
|
./v vet vlib/v/parser
|
||||||
./v vet vlib/v/ast
|
./v vet vlib/v/ast
|
||||||
./v vet vlib/v/gen/cgen.v
|
./v vet vlib/v/gen/cgen.v
|
||||||
|
|
|
@ -60,11 +60,12 @@ mut:
|
||||||
|
|
||||||
// for tests
|
// for tests
|
||||||
pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
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{
|
mut p := Parser{
|
||||||
scanner: s
|
scanner: s
|
||||||
table: table
|
table: table
|
||||||
pref: &pref.Preferences{}
|
pref: pref
|
||||||
scope: scope
|
scope: scope
|
||||||
global_scope: &ast.Scope{
|
global_scope: &ast.Scope{
|
||||||
start_pos: 0
|
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 {
|
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{
|
mut p := Parser{
|
||||||
scanner: s
|
scanner: s
|
||||||
table: b_table
|
table: b_table
|
||||||
|
@ -100,7 +101,7 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
||||||
// panic(err)
|
// panic(err)
|
||||||
// }
|
// }
|
||||||
mut p := Parser{
|
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
|
comments_mode: comments_mode
|
||||||
table: b_table
|
table: b_table
|
||||||
file_name: path
|
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')
|
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
//if pref.is_vet && p.scanner.text.contains('( '\n ') {
|
||||||
|
//}
|
||||||
return p.parse()
|
return p.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,8 +224,9 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
}
|
}
|
||||||
} else if p.tok.kind.is_infix() {
|
} else if p.tok.kind.is_infix() {
|
||||||
// return early for deref assign `*x = 2` goes to prefix expr
|
// 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 ==
|
if p.tok.kind == .mul &&
|
||||||
.assign {
|
p.tok.line_nr != p.prev_tok.line_nr &&
|
||||||
|
p.peek_tok2.kind == .assign {
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
// continue on infix expr
|
// continue on infix expr
|
||||||
|
|
|
@ -48,6 +48,7 @@ pub mut:
|
||||||
all_tokens []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
|
all_tokens []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
|
||||||
tidx int
|
tidx int
|
||||||
eofs int
|
eofs int
|
||||||
|
pref &pref.Preferences
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -94,7 +95,8 @@ pub enum CommentsMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
// new scanner from file.
|
// 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) {
|
if !os.exists(file_path) {
|
||||||
verror("$file_path doesn't exist")
|
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)
|
verror(err)
|
||||||
return voidptr(0)
|
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.init_fmt()
|
||||||
s.file_path = file_path
|
s.file_path = file_path
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// new scanner from string.
|
// 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{
|
s := &Scanner{
|
||||||
|
pref: pref
|
||||||
text: text
|
text: text
|
||||||
is_print_line_on_error: true
|
is_print_line_on_error: true
|
||||||
is_print_colored_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
|
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)
|
return s.new_token(.lpar, '', 1)
|
||||||
}
|
}
|
||||||
`)` {
|
`)` {
|
||||||
|
|
Loading…
Reference in New Issue