mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix import's position
This commit is contained in:
parent
de7fed45dc
commit
4470252913
|
@ -1744,7 +1744,6 @@ fn (p mut Parser) var_decl() {
|
||||||
mut var_token_idxs := [p.cur_tok_index()]
|
mut var_token_idxs := [p.cur_tok_index()]
|
||||||
mut var_mut := [is_mut] // add first var mut
|
mut var_mut := [is_mut] // add first var mut
|
||||||
mut var_names := [p.check_name()] // add first variable
|
mut var_names := [p.check_name()] // add first variable
|
||||||
p.scanner.validate_var_name(var_names[0])
|
|
||||||
mut new_vars := 0
|
mut new_vars := 0
|
||||||
if var_names[0] != '_' && !p.known_var(var_names[0]) {
|
if var_names[0] != '_' && !p.known_var(var_names[0]) {
|
||||||
new_vars++
|
new_vars++
|
||||||
|
@ -1762,7 +1761,6 @@ fn (p mut Parser) var_decl() {
|
||||||
}
|
}
|
||||||
var_token_idxs << p.cur_tok_index()
|
var_token_idxs << p.cur_tok_index()
|
||||||
var_name := p.check_name()
|
var_name := p.check_name()
|
||||||
p.scanner.validate_var_name(var_name)
|
|
||||||
if var_name != '_' && !p.known_var(var_name) {
|
if var_name != '_' && !p.known_var(var_name) {
|
||||||
new_vars++
|
new_vars++
|
||||||
}
|
}
|
||||||
|
|
|
@ -999,12 +999,3 @@ fn good_type_name(s string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// registration_date good
|
|
||||||
// registrationdate bad
|
|
||||||
fn (s &Scanner) validate_var_name(name string) {
|
|
||||||
/*
|
|
||||||
if name.len > 15 && !name.contains('_') {
|
|
||||||
s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ')
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
|
@ -1282,6 +1282,7 @@ fn (p mut Parser) module_decl() ast.Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) parse_import() ast.Import {
|
fn (p mut Parser) parse_import() ast.Import {
|
||||||
|
pos := p.tok.position()
|
||||||
mut mod_name := p.check_name()
|
mut mod_name := p.check_name()
|
||||||
mut mod_alias := mod_name
|
mut mod_alias := mod_name
|
||||||
for p.tok.kind == .dot {
|
for p.tok.kind == .dot {
|
||||||
|
@ -1299,7 +1300,7 @@ fn (p mut Parser) parse_import() ast.Import {
|
||||||
return ast.Import{
|
return ast.Import{
|
||||||
mod: mod_name
|
mod: mod_name
|
||||||
alias: mod_alias
|
alias: mod_alias
|
||||||
pos: p.tok.position()
|
pos: pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1011,14 +1011,6 @@ fn good_type_name(s string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// registration_date good
|
|
||||||
// registrationdate bad
|
|
||||||
fn (s &Scanner) validate_var_name(name string) {
|
|
||||||
if name.len > 15 && !name.contains('_') {
|
|
||||||
s.error('bad variable name `$name`\n' + 'looks like you have a multi-word name without separating them with `_`' + '\nfor example, use `registration_date` instead of `registrationdate` ')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (s &Scanner) error(msg string) {
|
pub fn (s &Scanner) error(msg string) {
|
||||||
println('$s.line_nr : $msg')
|
println('$s.line_nr : $msg')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user