parser: handle ! after CallExpr
parent
34af7ccba9
commit
100b3986b8
|
@ -96,6 +96,7 @@ string _STR_TMP(const char *fmt, ...) {
|
|||
va_start(argptr, fmt);
|
||||
vsprintf((char *)g_str_buf, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
#ifdef DEBUG_ALLOC
|
||||
//puts('_STR_TMP:');
|
||||
//puts(g_str_buf);
|
||||
|
@ -103,6 +104,7 @@ string _STR_TMP(const char *fmt, ...) {
|
|||
string res = tos(g_str_buf, len);
|
||||
res.is_lit = true;
|
||||
return res;
|
||||
|
||||
} // endof _STR_TMP
|
||||
|
||||
")
|
||||
|
|
|
@ -42,6 +42,10 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp
|
|||
args := p.call_args()
|
||||
last_pos := p.tok.position()
|
||||
p.check(.rpar)
|
||||
// ! in mutable methods
|
||||
if p.tok.kind == .not {
|
||||
p.next()
|
||||
}
|
||||
pos := token.Position{
|
||||
line_nr: first_pos.line_nr
|
||||
pos: first_pos.pos
|
||||
|
@ -347,7 +351,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
|
|||
}
|
||||
}
|
||||
|
||||
// fn decl
|
||||
// part of fn declaration
|
||||
fn (mut p Parser) fn_args() ([]table.Arg, bool) {
|
||||
p.check(.lpar)
|
||||
mut args := []table.Arg{}
|
||||
|
@ -463,7 +467,8 @@ fn (mut p Parser) check_fn_mutable_arguments(typ table.Type, pos token.Position)
|
|||
sym := p.table.get_type_symbol(typ)
|
||||
if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() {
|
||||
p.error_with_pos('mutable arguments are only allowed for arrays, maps, and structs\n' +
|
||||
'return values instead: `fn foo(mut n $sym.name) {` => `fn foo(n $sym.name) $sym.name {`', pos)
|
||||
'return values instead: `fn foo(mut n $sym.name) {` => `fn foo(n $sym.name) $sym.name {`',
|
||||
pos)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -891,7 +891,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||
} else if p.peek_tok.kind == .lcbr && !p.inside_match && !p.inside_match_case && !p.inside_if &&
|
||||
!p.inside_for {
|
||||
return p.struct_init(false) // short_syntax: false
|
||||
} else if p.peek_tok.kind == .dot && (p.tok.lit[0].is_capital() && !known_var && language == .v) {
|
||||
} else if p.peek_tok.kind == .dot && (p.tok.lit[0].is_capital() && !known_var && language ==
|
||||
.v) {
|
||||
// `Color.green`
|
||||
mut enum_name := p.check_name()
|
||||
if mod != '' {
|
||||
|
@ -1000,6 +1001,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
|
|||
// }
|
||||
}
|
||||
// Method call
|
||||
// TODO move to fn.v call_expr()
|
||||
if p.tok.kind == .lpar {
|
||||
p.next()
|
||||
args := p.call_args()
|
||||
|
@ -1028,6 +1030,9 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
|
|||
or_stmts = p.parse_block_no_scope()
|
||||
p.close_scope()
|
||||
}
|
||||
if p.tok.kind == .not {
|
||||
p.next()
|
||||
}
|
||||
if p.tok.kind == .question {
|
||||
// `foo()?`
|
||||
p.next()
|
||||
|
|
Loading…
Reference in New Issue