fmt: fixes for option syntax formatting

pull/3213/head
Delyan Angelov 2019-12-25 15:08:52 +02:00 committed by Alexander Medvednikov
parent 1d86f4b5d1
commit ae4c8af674
2 changed files with 6 additions and 0 deletions

View File

@ -99,8 +99,11 @@ fn (p mut Parser) gen_handle_option_or_else(_typ, name string, fn_call_ph int) s
typ = parse_pointer(typ[7..]) typ = parse_pointer(typ[7..])
p.genln(';') p.genln(';')
or_tok_idx := p.token_idx or_tok_idx := p.token_idx
p.fspace()
p.check(.key_orelse) p.check(.key_orelse)
p.fspace()
p.check(.lcbr) p.check(.lcbr)
p.fspace()
p.register_var(Var{ p.register_var(Var{
name: 'err' name: 'err'
typ: 'string' typ: 'string'

View File

@ -231,7 +231,9 @@ fn (p mut Parser) if_statement(is_expr bool, elif_depth int) string {
} }
p.open_scope() p.open_scope()
p.next() p.next()
p.fspace()
p.check(.decl_assign) p.check(.decl_assign)
p.fspace()
p.is_var_decl = true p.is_var_decl = true
option_type,expr := p.tmp_expr() // := p.bool_expression() option_type,expr := p.tmp_expr() // := p.bool_expression()
if !option_type.starts_with('Option_') { if !option_type.starts_with('Option_') {
@ -245,6 +247,7 @@ fn (p mut Parser) if_statement(is_expr bool, elif_depth int) string {
// [statements] // [statements]
// } // }
p.cgen.insert_before('$option_type $option_tmp = $expr; ') p.cgen.insert_before('$option_type $option_tmp = $expr; ')
p.fspace()
p.check(.lcbr) p.check(.lcbr)
p.genln(option_tmp + '.ok) {') p.genln(option_tmp + '.ok) {')
p.genln('$typ $var_name = *($typ*) $option_tmp . data;') p.genln('$typ $var_name = *($typ*) $option_tmp . data;')