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

compiler: blank ident - consolidate duplicated code into single function

This commit is contained in:
joe-conigliaro
2019-10-20 20:24:12 +11:00
committed by Alexander Medvednikov
parent 8a31ee4b53
commit f7c00b8180
4 changed files with 20 additions and 25 deletions

View File

@ -39,20 +39,10 @@ fn (p mut Parser) gen_blank_identifier_assign() {
p.check_name()
p.check_space(.assign)
is_indexer := p.peek() == .lsbr
mut expr := p.lit
mut is_fn_call := p.peek() == .lpar
if !is_fn_call {
mut i := p.token_idx+1
for (p.tokens[i].tok == .dot || p.tokens[i].tok == .name) &&
p.tokens[i].lit != '_' {
expr += if p.tokens[i].tok == .dot { '.' } else { p.tokens[i].lit }
i++
}
is_fn_call = p.tokens[i].tok == .lpar
}
is_fn_call, next_expr := p.is_next_expr_fn_call()
p.bool_expression()
if !is_indexer && !is_fn_call {
p.error_with_token_index('assigning `$expr` to `_` is redundant', assign_error_tok_idx)
p.error_with_token_index('assigning `$next_expr` to `_` is redundant', assign_error_tok_idx)
}
or_else := p.tok == .key_orelse
//tmp := p.get_tmp()