1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vrepl: fix array_filter (#9104)

This commit is contained in:
yuyi 2021-03-04 18:24:14 +08:00 committed by GitHub
parent 2b9ffbda42
commit 2870a5a63a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -29,6 +29,7 @@ mut:
const is_stdin_a_pipe = (is_atty(0) == 0)
const vexe = os.getenv('VEXE')
const vstartup = os.getenv('VSTARTUP')
fn new_repl() Repl {
@ -118,7 +119,11 @@ fn run_repl(workdir string, vrepl_prefix string) {
}
if vstartup != '' {
result := repl_run_vfile(vstartup) or { os.Result{output: '$vstartup file not found'} }
result := repl_run_vfile(vstartup) or {
os.Result{
output: '$vstartup file not found'
}
}
print('\n')
print_output(result)
}
@ -214,7 +219,6 @@ fn run_repl(workdir string, vrepl_prefix string) {
filter_line := r.line.replace(r.line.find_between("'", "'"), '').replace(r.line.find_between('"',
'"'), '')
possible_statement_patterns := [
'=',
'++',
'--',
'<<',
@ -229,7 +233,6 @@ fn run_repl(workdir string, vrepl_prefix string) {
'interface ',
'import ',
'#include ',
':=',
'for ',
'or ',
'insert',
@ -240,12 +243,16 @@ fn run_repl(workdir string, vrepl_prefix string) {
'trim',
]
mut is_statement := false
if filter_line.count('=') % 2 == 1 {
is_statement = true
} else {
for pattern in possible_statement_patterns {
if filter_line.contains(pattern) {
is_statement = true
break
}
}
}
// NB: starting a line with 2 spaces escapes the println heuristic
if oline.starts_with(' ') {
is_statement = true

View File

@ -0,0 +1,3 @@
[1, 2, 3, 4].filter(it%2 == 0).map(it * 2)
===output===
[4, 8]