diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8341fdbf6f..b5737b05c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: ../vprod -x64 -o 1m 1m.v echo "Running it..." ls - ./1m +# ./1m #run: echo "TODO" #cd examples/x64 && ../../v -x64 hello_world.v && ./hello_world diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index ddbd5a0613..4803055bab 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -9,7 +9,7 @@ import ( ) pub type Expr = BinaryExpr | UnaryExpr | IfExpr | StringLiteral | IntegerLiteral | -FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr | AssignExpr | PrefixExpr +FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr | AssignExpr | PrefixExpr | MethodCallExpr pub type Stmt = VarDecl | FnDecl | Return | Module | Import | ExprStmt | ForStmt | StructDecl | ForCStmt | ForInStmt @@ -103,6 +103,16 @@ pub: pub struct CallExpr { pub: +// func Expr + name string + args []Expr + is_unknown bool + tok token.Token +} + +pub struct MethodCallExpr { +pub: + expr Expr name string args []Expr is_unknown bool diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 6e492d5a67..b7cb7da7b8 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -59,6 +59,19 @@ pub fn (p mut Parser) call_expr() (ast.CallExpr,types.TypeIdent) { return node,return_ti } +pub fn (p mut Parser) call_args() []ast.Expr { + mut args := []ast.Expr + for p.tok.kind != .rpar { + e,_ := p.expr(0) + args << e + if p.tok.kind != .rpar { + p.check(.comma) + } + } + p.check(.rpar) + return args // ,types.void_ti +} + fn (p mut Parser) fn_decl() ast.FnDecl { is_pub := p.tok.kind == .key_pub if is_pub { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index f00887751d..9936ec87ce 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -314,7 +314,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,types.TypeIdent) { node,ti = p.name_expr() } .str { - node,ti = p.parse_string_literal() + node,ti = p.string_expr() } // -1, -a etc .minus { @@ -332,7 +332,6 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,types.TypeIdent) { } .lpar { p.check(.lpar) - p.next() node,ti = p.expr(0) p.check(.rpar) } @@ -387,6 +386,19 @@ fn (p mut Parser) prefix_expr() (ast.Expr,types.TypeIdent) { fn (p mut Parser) dot_expr(left ast.Expr) (ast.Expr,types.TypeIdent) { p.next() field_name := p.check_name() + // Method call + if p.tok.kind == .lpar { + p.next() + args := p.call_args() + println('method call $field_name') + mut node := ast.Expr{} + node = ast.MethodCallExpr{ + expr: left + name: field_name + args: args + } + return node,types.int_ti + } /* // p.next() field := p.check_name() @@ -555,12 +567,24 @@ fn (p mut Parser) if_expr() (ast.Expr,types.TypeIdent) { return node,ti } -fn (p mut Parser) parse_string_literal() (ast.Expr,types.TypeIdent) { +fn (p mut Parser) string_expr() (ast.Expr,types.TypeIdent) { mut node := ast.Expr{} node = ast.StringLiteral{ val: p.tok.lit } - p.next() + if p.peek_tok.kind != .str_dollar { + p.next() + return node,types.string_ti + } + // Handle $ interpolation + for p.tok.kind == .str { + p.next() + if p.tok.kind != .str_dollar { + continue + } + p.check(.str_dollar) + p.expr(0) + } return node,types.string_ti } @@ -677,7 +701,7 @@ fn (p mut Parser) return_stmt() ast.Return { p.next() expr,t := p.expr(0) if !types.check(p.return_ti, t) { - p.error('cannot use `$t.name` as type `$p.return_ti.name` in return argument') + p.warn('cannot use `$t.name` as type `$p.return_ti.name` in return argument') } return ast.Return{ expr: expr