aboutsummaryrefslogtreecommitdiff
path: root/ast.go
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-04 13:47:14 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-04 13:47:14 +0900
commit7825b659b0c3d096cb69b25ca269d54525bbf140 (patch)
treea4622bb621844f0a45fe6b5a282775255242efc2 /ast.go
parent584bb06a6efdbd12883114f25af2d0b331f9fbd9 (diff)
downloadkati-7825b659b0c3d096cb69b25ca269d54525bbf140.tar.gz
Use Value in AssignAST
Diffstat (limited to 'ast.go')
-rw-r--r--ast.go31
1 files changed, 7 insertions, 24 deletions
diff --git a/ast.go b/ast.go
index c947463..04ab74f 100644
--- a/ast.go
+++ b/ast.go
@@ -20,9 +20,8 @@ type ASTBase struct {
type AssignAST struct {
ASTBase
- // TODO(ukai): use Value.
- lhs string
- rhs string
+ lhs Value
+ rhs Value
op string
opt string // "override", "export"
}
@@ -42,39 +41,23 @@ func (ast *AssignAST) evalRHS(ev *Evaluator, lhs string) Var {
// TODO(ukai): handle ast.opt == "export"
switch ast.op {
case ":=":
- rexpr, _, err := parseExpr([]byte(ast.rhs), nil)
- if err != nil {
- panic(fmt.Errorf("parse assign rhs %s:%d %v", ast.filename, ast.lineno, err))
- }
var buf bytes.Buffer
- rexpr.Eval(&buf, ev)
+ ast.rhs.Eval(&buf, ev)
return SimpleVar{value: buf.Bytes(), origin: origin}
case "=":
- v, _, err := parseExpr([]byte(ast.rhs), nil)
- if err != nil {
- panic(err)
- }
- return RecursiveVar{expr: v, origin: origin}
+ return RecursiveVar{expr: ast.rhs, origin: origin}
case "+=":
prev := ev.LookupVarInCurrentScope(lhs)
if !prev.IsDefined() {
- v, _, err := parseExpr([]byte(ast.rhs), nil)
- if err != nil {
- panic(err)
- }
- return RecursiveVar{expr: v, origin: origin}
+ return RecursiveVar{expr: ast.rhs, origin: origin}
}
- return prev.Append(ev, ast.rhs)
+ return prev.AppendVar(ev, ast.rhs)
case "?=":
prev := ev.LookupVarInCurrentScope(lhs)
if prev.IsDefined() {
return prev
}
- v, _, err := parseExpr([]byte(ast.rhs), nil)
- if err != nil {
- panic(err)
- }
- return RecursiveVar{expr: v, origin: origin}
+ return RecursiveVar{expr: ast.rhs, origin: origin}
default:
panic(fmt.Sprintf("unknown assign op: %q", ast.op))
}