1
0
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:
Alexander Medvednikov 2020-07-11 11:41:39 +02:00
parent a1073105e1
commit d4d552fb00
5 changed files with 32 additions and 19 deletions

View File

@ -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
@ -56,7 +57,7 @@ jobs:
alpine-docker-musl-gcc:
name: alpine-musl
runs-on: ubuntu-latest
container:
container:
image: thevlang/vlang:alpine-build
env:
V_CI_MUSL: 1
@ -66,13 +67,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build V
run: |
make CC=clang
- name: Test V fixed tests
run: |
v test-fixed
v test-fixed
macos:
runs-on: ${{ matrix.os }}
@ -201,10 +202,10 @@ jobs:
# Ubuntu docker pre-built container
ubuntu-musl:
ubuntu-musl:
name: ubuntu-musl
runs-on: ubuntu-latest
container:
container:
image: thevlang/vlang:ubuntu-build
env:
V_CI_MUSL: 1
@ -215,13 +216,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build V
run: |
echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
- name: Test V fixed tests
run: |
v test-fixed
v test-fixed
# ubuntu-musl:
# runs-on: ubuntu-18.04

View File

@ -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()
}

View File

@ -101,7 +101,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
pos := p.tok.position()
p.next() // sizeof
p.check(.lpar)
is_known_var := p.mark_var_as_used( p.tok.lit )
is_known_var := p.mark_var_as_used(p.tok.lit)
if is_known_var {
expr := p.parse_ident(table.Language.v)
node = ast.SizeOf{
@ -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

View File

@ -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)
}
`)` {

View File

@ -42,9 +42,9 @@ fn fn_name_mod_level_high_order(cb fn(int)) {
fn test_at_file() {
// Test @FILE
f := os.file_name( @FILE )
f := os.file_name(@FILE)
assert f == 'scanner_at_literals_test.v'
}
}
fn test_at_fn() {
// Test @FN