mirror of
https://github.com/vlang/v.git
synced 2025-09-16 07:52:32 +03:00
V shell scripts
This commit is contained in:
parent
96152510e5
commit
5cd38ec91b
6 changed files with 66 additions and 23 deletions
|
@ -148,7 +148,11 @@ fn (v mut V) new_parser(scanner &Scanner, id string) Parser {
|
|||
vroot: v.vroot
|
||||
local_vars: [Var{}].repeat(MaxLocalVars)
|
||||
import_table: v.table.get_file_import_table(id)
|
||||
v_script: id.ends_with('.vsh')
|
||||
}
|
||||
if p.v_script {
|
||||
println('new_parser: V script')
|
||||
}
|
||||
$if js {
|
||||
p.is_js = true
|
||||
}
|
||||
|
@ -742,7 +746,7 @@ fn (p mut Parser) struct_decl() {
|
|||
}
|
||||
if p.tok == .key_mut {
|
||||
if is_mut {
|
||||
p.error('structs can only have one `mut:`, all private key_mut fields have to be grouped')
|
||||
p.error('structs can only have one `mut:`, all private mutable fields have to be grouped')
|
||||
}
|
||||
is_mut = true
|
||||
p.fmt_dec()
|
||||
|
@ -1928,23 +1932,17 @@ fn (p mut Parser) name_expr() string {
|
|||
}
|
||||
return typ
|
||||
}
|
||||
// Function (not method btw, methods are handled in dot())
|
||||
mut f := p.table.find_fn(name) or {
|
||||
// We are in the second pass, that means this function was not defined, throw an error.
|
||||
// Function (not method btw, methods are handled in `dot()`)
|
||||
mut f := p.table.find_fn_is_script(name, p.v_script) or {
|
||||
// We are in the second pass, that means this function was not defined,
|
||||
// throw an error.
|
||||
if !p.first_pass() {
|
||||
// V script? Try os module.
|
||||
// TODO
|
||||
if p.v_script {
|
||||
//name = name.replace('main__', 'os__')
|
||||
//f = p.table.find_fn(name)
|
||||
}
|
||||
// check for misspelled function / variable / module
|
||||
suggested := p.identify_typo(name, p.import_table)
|
||||
if suggested != '' {
|
||||
p.error('undefined: `$name`. did you mean:$suggested')
|
||||
}
|
||||
// If orig_name is a mod, then printing undefined: `mod` tells us nothing
|
||||
// if p.table.known_mod(orig_name) {
|
||||
if p.table.known_mod(orig_name) || p.import_table.known_alias(orig_name) {
|
||||
name = name.replace('__', '.')
|
||||
p.error('undefined: `$name`')
|
||||
|
@ -1955,6 +1953,8 @@ fn (p mut Parser) name_expr() string {
|
|||
} else {
|
||||
p.next()
|
||||
// First pass, the function can be defined later.
|
||||
// Only in const definitions? (since fn bodies are skipped
|
||||
// in the first pass).
|
||||
return 'void'
|
||||
}
|
||||
return 'void'
|
||||
|
@ -3560,6 +3560,8 @@ fn (p mut Parser) for_st() {
|
|||
typ: var_type
|
||||
ptr: typ.contains('*')
|
||||
is_changed: true
|
||||
is_mut: false
|
||||
is_for_var: true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue