eval: VariablesOp -> LValueOp

This commit is contained in:
Qi Xiao 2016-02-25 15:53:55 +01:00
parent 35f5798bcd
commit cee81d5298
3 changed files with 15 additions and 16 deletions

View File

@ -182,24 +182,24 @@ func (cp *compiler) bracedOps(ns []*parse.Primary) []ValuesOp {
return ops
}
func (cp *compiler) multiVariableOp(n *parse.Indexing) VariablesOp {
return VariablesOp{cp.multiVariable(n), n.Begin(), n.End()}
func (cp *compiler) multiVariableOp(n *parse.Indexing) LValuesOp {
return LValuesOp{cp.multiVariable(n), n.Begin(), n.End()}
}
func (cp *compiler) multiVariableOps(ns []*parse.Indexing) []VariablesOp {
ops := make([]VariablesOp, len(ns))
func (cp *compiler) multiVariableOps(ns []*parse.Indexing) []LValuesOp {
ops := make([]LValuesOp, len(ns))
for i, n := range ns {
ops[i] = cp.multiVariableOp(n)
}
return ops
}
func (cp *compiler) singleVariableOp(n *parse.Indexing, msg string) VariablesOp {
return VariablesOp{cp.singleVariable(n, msg), n.Begin(), n.End()}
func (cp *compiler) singleVariableOp(n *parse.Indexing, msg string) LValuesOp {
return LValuesOp{cp.singleVariable(n, msg), n.Begin(), n.End()}
}
func (cp *compiler) singleVariableOps(ns []*parse.Indexing, msg string) []VariablesOp {
ops := make([]VariablesOp, len(ns))
func (cp *compiler) singleVariableOps(ns []*parse.Indexing, msg string) []LValuesOp {
ops := make([]LValuesOp, len(ns))
for i, n := range ns {
ops[i] = cp.singleVariableOp(n, msg)
}

View File

@ -29,7 +29,7 @@ def main():
print >>out, '''package eval
import "github.com/elves/elvish/parse"'''
for fname in 'compileOp.go', 'compileValuesOp.go', 'compileVariablesOp.go':
for fname in 'compileOp.go', 'compileValuesOp.go', 'compileLValuesOp.go':
for line in file(fname):
m = re.match(r'^func \(cp \*compiler\) (\w+)\(\w+ ([^,]+)(.*)\) (\w*OpFunc) {$', line)
if m:

View File

@ -7,19 +7,19 @@ import (
)
// VariablesOp is an operation on an EvalCtx that produce Variable's.
type VariablesOp struct {
Func VariablesOpFunc
type LValuesOp struct {
Func LValuesOpFunc
Begin, End int
}
type VariablesOpFunc func(*EvalCtx) []Variable
type LValuesOpFunc func(*EvalCtx) []Variable
func (op VariablesOp) Exec(ec *EvalCtx) []Variable {
func (op LValuesOp) Exec(ec *EvalCtx) []Variable {
ec.begin, ec.end = op.Begin, op.End
return op.Func(ec)
}
func (cp *compiler) multiVariable(n *parse.Indexing) VariablesOpFunc {
func (cp *compiler) multiVariable(n *parse.Indexing) LValuesOpFunc {
if n.Head.Type == parse.Braced {
// XXX ignore n.Indicies.
compounds := n.Head.Braced
@ -43,8 +43,7 @@ func (cp *compiler) multiVariable(n *parse.Indexing) VariablesOpFunc {
return cp.singleVariable(n, "must be a variable spec or a braced list of those")
}
func (cp *compiler) singleVariable(n *parse.Indexing, msg string) VariablesOpFunc {
// XXX will we be using this for purposes other than setting?
func (cp *compiler) singleVariable(n *parse.Indexing, msg string) LValuesOpFunc {
varname := cp.literal(n.Head, msg)
if len(n.Indicies) == 0 {