parser: fix !

pull/5241/head
Alexander Medvednikov 2020-06-06 12:43:35 +02:00
parent 100b3986b8
commit 40bd1be85f
4 changed files with 14 additions and 13 deletions

View File

@ -245,6 +245,7 @@ pub:
pub mut:
name string
is_method bool
is_mut bool // !
args []CallArg
expected_arg_types []table.Type
language table.Language

View File

@ -799,6 +799,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
}
if method.args[0].is_mut {
c.fail_if_immutable(call_expr.left)
call_expr.is_mut = true
}
if method.return_type == table.void_type && method.ctdefine.len > 0 && method.ctdefine !in
c.pref.compile_defines {

View File

@ -470,7 +470,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
}
if field.has_default_expr {
f.write(' = ')
f.struct_field_expr( field.default_expr )
f.struct_field_expr(field.default_expr)
}
// f.write('// $field.pos.line_nr')
if field.comment.text != '' && field.comment.pos.line_nr == field.pos.line_nr {
@ -487,7 +487,6 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
f.writeln('}\n')
}
pub fn (mut f Fmt) struct_field_expr(fexpr ast.Expr) {
mut is_pe_amp_ce := false
mut ce := ast.CastExpr{}
@ -633,7 +632,6 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
ktyp = minfo.key_type
vtyp = minfo.value_type
}
f.write('map[')
f.write(f.type_to_str(ktyp))
f.write(']')
@ -912,6 +910,9 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
f.write('.' + node.name + '(')
f.call_args(node.args)
f.write(')')
if node.is_mut {
// f.write('!')
}
f.or_expr(node.or_block)
} else {
f.write_language_prefix(node.language)
@ -1033,12 +1034,8 @@ pub fn (mut f Fmt) mark_module_as_used(name string) {
fn (mut f Fmt) write_language_prefix(lang table.Language) {
match lang {
.c {
f.write('C.')
}
.js {
f.write('JS.')
}
.c { f.write('C.') }
.js { f.write('JS.') }
else {}
}
}

View File

@ -1000,6 +1000,10 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
// p.close_scope()
// }
}
// ! in mutable methods
if p.tok.kind == .not && p.peek_tok.kind == .lpar {
p.next()
}
// Method call
// TODO move to fn.v call_expr()
if p.tok.kind == .lpar {
@ -1030,14 +1034,12 @@ 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()?`
if p.tok.kind == .question {
p.next()
or_kind = .propagate
}
//
end_pos := p.tok.position()
pos := token.Position{
line_nr: name_pos.line_nr