Parse call expressions and gets rid of the TODOs in parse let and return.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
985cf24fbc
commit
44f936affb
4 changed files with 165 additions and 46 deletions
31
pkg/ast/call.go
Normal file
31
pkg/ast/call.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package ast
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"code.jmug.me/jmug/interpreter-in-go/pkg/token"
|
||||
)
|
||||
|
||||
type CallExpression struct {
|
||||
Token token.Token // The ( token
|
||||
Function Expression
|
||||
Arguments []Expression
|
||||
}
|
||||
|
||||
func (ce *CallExpression) expressionNode() {}
|
||||
func (ce *CallExpression) TokenLiteral() string {
|
||||
return ce.Token.Literal
|
||||
}
|
||||
func (ce *CallExpression) String() string {
|
||||
var out bytes.Buffer
|
||||
out.WriteString(ce.Function.String())
|
||||
out.WriteString("(")
|
||||
args := []string{}
|
||||
for _, arg := range ce.Arguments {
|
||||
args = append(args, arg.String())
|
||||
}
|
||||
out.WriteString(strings.Join(args, ", "))
|
||||
out.WriteString(")")
|
||||
return out.String()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue