mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: parse filter()
This commit is contained in:
parent
3f6ccd3120
commit
c9f619dc72
15
cmd/v/v.v
15
cmd/v/v.v
@ -9,23 +9,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
simple_cmd = [
|
||||
'fmt',
|
||||
simple_cmd = ['fmt',
|
||||
'up',
|
||||
'create',
|
||||
'test', 'test-fmt', 'test-compiler',
|
||||
'bin2v',
|
||||
'repl',
|
||||
'build-tools', 'build-examples', 'build-vbinaries'
|
||||
]
|
||||
'build-tools', 'build-examples', 'build-vbinaries']
|
||||
)
|
||||
|
||||
fn main() {
|
||||
arg := join_flags_and_argument()
|
||||
command,option := get_basic_command_and_option(arg)
|
||||
|
||||
is_verbose := '-verbose' in arg || '--verbose' in arg
|
||||
|
||||
if '-v' in option || '--version' in option || command == 'version' {
|
||||
// Print the version and exit.
|
||||
version_hash := compiler.vhash()
|
||||
@ -35,29 +31,26 @@ fn main() {
|
||||
if '-h' in option || '--help' in option || command == 'help' {
|
||||
if is_verbose {
|
||||
println(verbose_help_text)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
println(help_text)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if is_verbose {
|
||||
eprintln('v args: $arg')
|
||||
eprintln('v command: $command')
|
||||
eprintln('v options: $option')
|
||||
}
|
||||
|
||||
if command in simple_cmd {
|
||||
// External tools
|
||||
launch_tool(is_verbose, 'v' + command, command)
|
||||
return
|
||||
}
|
||||
|
||||
if command == 'run' || command == 'build' || command.ends_with('.v') || os.exists(command) {
|
||||
compile(command, arg)
|
||||
return
|
||||
}
|
||||
|
||||
match command {
|
||||
'', '-' {
|
||||
if arg.len == 1 {
|
||||
|
@ -347,6 +347,12 @@ pub:
|
||||
name string
|
||||
}
|
||||
|
||||
// filter(), map()
|
||||
pub struct Lambda {
|
||||
pub:
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct AssignStmt {
|
||||
pub:
|
||||
left []Ident
|
||||
|
1
vlib/v/parser/comptime.v
Normal file
1
vlib/v/parser/comptime.v
Normal file
@ -0,0 +1 @@
|
||||
module parser
|
@ -665,9 +665,20 @@ fn (p mut Parser) index_expr(left ast.Expr) ast.Expr {
|
||||
// return node,typ
|
||||
}
|
||||
|
||||
fn (p mut Parser) filter(typ table.Type) {
|
||||
p.table.register_var(table.Var{
|
||||
name: 'it'
|
||||
typ: typ
|
||||
})
|
||||
}
|
||||
|
||||
fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) (ast.Expr,table.Type) {
|
||||
p.next()
|
||||
field_name := p.check_name()
|
||||
if field_name == 'filter' {
|
||||
p.table.open_scope()
|
||||
p.filter(left_type)
|
||||
}
|
||||
// Method call
|
||||
if p.tok.kind == .lpar {
|
||||
p.next()
|
||||
@ -697,6 +708,9 @@ fn (p mut Parser) dot_expr(left ast.Expr, left_type table.Type) (ast.Expr,table.
|
||||
typ := p.add_unresolved('${table.type_idx(left_type)}.$field_name', sel_expr)
|
||||
mut node := ast.Expr{}
|
||||
node = sel_expr
|
||||
if field_name == 'filter' {
|
||||
p.table.close_scope()
|
||||
}
|
||||
return node,typ
|
||||
}
|
||||
|
||||
@ -1069,7 +1083,8 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
||||
// this allows overiding the builtins type
|
||||
// with the real struct type info parsed from builtin
|
||||
ret = p.table.register_builtin_type_symbol(t)
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ret = p.table.register_type_symbol(t)
|
||||
}
|
||||
if ret == -1 {
|
||||
|
Loading…
Reference in New Issue
Block a user