Skip to content

Commit d4d552f

Browse files
committed
vet: prohibit spaces after (
1 parent a107310 commit d4d552f

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
run: ./v build-tools
4646
- name: v vet
4747
run: |
48+
./v vet vlib/v/scanner
4849
./v vet vlib/v/parser
4950
./v vet vlib/v/ast
5051
./v vet vlib/v/gen/cgen.v
@@ -56,7 +57,7 @@ jobs:
5657
alpine-docker-musl-gcc:
5758
name: alpine-musl
5859
runs-on: ubuntu-latest
59-
container:
60+
container:
6061
image: thevlang/vlang:alpine-build
6162
env:
6263
V_CI_MUSL: 1
@@ -66,13 +67,13 @@ jobs:
6667
steps:
6768
- name: Checkout
6869
uses: actions/checkout@v2
69-
70+
7071
- name: Build V
7172
run: |
7273
make CC=clang
7374
- name: Test V fixed tests
7475
run: |
75-
v test-fixed
76+
v test-fixed
7677
7778
macos:
7879
runs-on: ${{ matrix.os }}
@@ -201,10 +202,10 @@ jobs:
201202

202203

203204
# Ubuntu docker pre-built container
204-
ubuntu-musl:
205+
ubuntu-musl:
205206
name: ubuntu-musl
206207
runs-on: ubuntu-latest
207-
container:
208+
container:
208209
image: thevlang/vlang:ubuntu-build
209210
env:
210211
V_CI_MUSL: 1
@@ -215,13 +216,13 @@ jobs:
215216
steps:
216217
- name: Checkout
217218
uses: actions/checkout@v2
218-
219+
219220
- name: Build V
220221
run: |
221222
echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
222223
- name: Test V fixed tests
223224
run: |
224-
v test-fixed
225+
v test-fixed
225226
226227
# ubuntu-musl:
227228
# runs-on: ubuntu-18.04

vlib/v/parser/parser.v

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ mut:
6060

6161
// for tests
6262
pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
63-
s := scanner.new_scanner(text, .skip_comments, false)
63+
pref:= &pref.Preferences{}
64+
s := scanner.new_scanner(text, .skip_comments, pref)
6465
mut p := Parser{
6566
scanner: s
6667
table: table
67-
pref: &pref.Preferences{}
68+
pref: pref
6869
scope: scope
6970
global_scope: &ast.Scope{
7071
start_pos: 0
@@ -77,7 +78,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
7778
}
7879

7980
pub fn parse_text(text string, b_table &table.Table, pref &pref.Preferences, scope, global_scope &ast.Scope) ast.File {
80-
s := scanner.new_scanner(text, .skip_comments, pref.is_fmt)
81+
s := scanner.new_scanner(text, .skip_comments, pref)
8182
mut p := Parser{
8283
scanner: s
8384
table: b_table
@@ -100,7 +101,7 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
100101
// panic(err)
101102
// }
102103
mut p := Parser{
103-
scanner: scanner.new_scanner_file(path, comments_mode, pref.is_fmt)
104+
scanner: scanner.new_scanner_file(path, comments_mode, pref)
104105
comments_mode: comments_mode
105106
table: b_table
106107
file_name: path
@@ -126,6 +127,8 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
126127
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
127128
exit(1)
128129
}
130+
//if pref.is_vet && p.scanner.text.contains('( '\n ') {
131+
//}
129132
return p.parse()
130133
}
131134

vlib/v/parser/pratt.v

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
101101
pos := p.tok.position()
102102
p.next() // sizeof
103103
p.check(.lpar)
104-
is_known_var := p.mark_var_as_used( p.tok.lit )
104+
is_known_var := p.mark_var_as_used(p.tok.lit)
105105
if is_known_var {
106106
expr := p.parse_ident(table.Language.v)
107107
node = ast.SizeOf{
@@ -224,8 +224,9 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
224224
}
225225
} else if p.tok.kind.is_infix() {
226226
// return early for deref assign `*x = 2` goes to prefix expr
227-
if p.tok.kind == .mul && p.tok.line_nr != p.prev_tok.line_nr && p.peek_tok2.kind ==
228-
.assign {
227+
if p.tok.kind == .mul &&
228+
p.tok.line_nr != p.prev_tok.line_nr &&
229+
p.peek_tok2.kind == .assign {
229230
return node
230231
}
231232
// continue on infix expr

vlib/v/scanner/scanner.v

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub mut:
4848
all_tokens []token.Token // *only* used in comments_mode: .toplevel_comments, contains all tokens
4949
tidx int
5050
eofs int
51+
pref &pref.Preferences
5152
}
5253

5354
/*
@@ -94,23 +95,26 @@ pub enum CommentsMode {
9495
}
9596

9697
// new scanner from file.
97-
pub fn new_scanner_file(file_path string, comments_mode CommentsMode, is_fmt bool) &Scanner {
98+
pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
99+
// is_fmt := pref.is_fmt
98100
if !os.exists(file_path) {
99101
verror("$file_path doesn't exist")
100102
}
101103
raw_text := util.read_file(file_path) or {
102104
verror(err)
103105
return voidptr(0)
104106
}
105-
mut s := new_scanner(raw_text, comments_mode, is_fmt) // .skip_comments)
107+
mut s := new_scanner(raw_text, comments_mode, pref) // .skip_comments)
106108
// s.init_fmt()
107109
s.file_path = file_path
108110
return s
109111
}
110112

111113
// new scanner from string.
112-
pub fn new_scanner(text string, comments_mode CommentsMode, is_fmt bool) &Scanner {
114+
pub fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
115+
is_fmt := pref.is_fmt
113116
s := &Scanner{
117+
pref: pref
114118
text: text
115119
is_print_line_on_error: true
116120
is_print_colored_error: true
@@ -768,6 +772,10 @@ fn (mut s Scanner) text_scan() token.Token {
768772
return s.new_token(.chartoken, ident_char, ident_char.len + 2) // + two quotes
769773
}
770774
`(` {
775+
// TODO `$if vet {` for performance
776+
if s.pref.is_vet && s.text[s.pos + 1] == ` ` {
777+
println('$s.file_path:$s.line_nr: Looks like you are adding a space after `(`')
778+
}
771779
return s.new_token(.lpar, '', 1)
772780
}
773781
`)` {

vlib/v/scanner/scanner_at_literals_test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ fn fn_name_mod_level_high_order(cb fn(int)) {
4242

4343
fn test_at_file() {
4444
// Test @FILE
45-
f := os.file_name( @FILE )
45+
f := os.file_name(@FILE)
4646
assert f == 'scanner_at_literals_test.v'
47-
}
47+
}
4848

4949
fn test_at_fn() {
5050
// Test @FN

0 commit comments

Comments
 (0)