mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
[a b;c d] desugars to [[a b] [c d]]
This commit is contained in:
parent
254d63d55b
commit
1638370417
|
@ -269,10 +269,7 @@ func (cp *compiler) primary(n *parse.Primary) ValuesOpFunc {
|
||||||
case parse.OutputCapture:
|
case parse.OutputCapture:
|
||||||
return cp.outputCapture(n)
|
return cp.outputCapture(n)
|
||||||
case parse.List:
|
case parse.List:
|
||||||
op := cp.arrayOp(n.List)
|
return cp.list(n.List)
|
||||||
return func(ec *EvalCtx) []Value {
|
|
||||||
return []Value{NewList(op.Exec(ec)...)}
|
|
||||||
}
|
|
||||||
case parse.Lambda:
|
case parse.Lambda:
|
||||||
return cp.lambda(n)
|
return cp.lambda(n)
|
||||||
case parse.Map:
|
case parse.Map:
|
||||||
|
@ -285,6 +282,33 @@ func (cp *compiler) primary(n *parse.Primary) ValuesOpFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cp *compiler) list(n *parse.Array) ValuesOpFunc {
|
||||||
|
if len(n.Semicolons) == 0 {
|
||||||
|
op := cp.arrayOp(n)
|
||||||
|
return func(ec *EvalCtx) []Value {
|
||||||
|
return []Value{NewList(op.Exec(ec)...)}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ns := len(n.Semicolons)
|
||||||
|
rowOps := make([]ValuesOpFunc, ns+1)
|
||||||
|
f := func(k, i, j int) {
|
||||||
|
rowOps[k] = catValuesOps(cp.compoundOps(n.Compounds[i:j]))
|
||||||
|
}
|
||||||
|
f(0, 0, n.Semicolons[0])
|
||||||
|
for i := 1; i < ns; i++ {
|
||||||
|
f(i, n.Semicolons[i-1], n.Semicolons[i])
|
||||||
|
}
|
||||||
|
f(ns, n.Semicolons[ns-1], len(n.Compounds))
|
||||||
|
return func(ec *EvalCtx) []Value {
|
||||||
|
rows := make([]Value, ns+1)
|
||||||
|
for i := 0; i <= ns; i++ {
|
||||||
|
rows[i] = NewList(rowOps[i](ec)...)
|
||||||
|
}
|
||||||
|
return []Value{List{&rows}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (cp *compiler) errorCapture(n *parse.Chunk) ValuesOpFunc {
|
func (cp *compiler) errorCapture(n *parse.Chunk) ValuesOpFunc {
|
||||||
op := cp.chunkOp(n)
|
op := cp.chunkOp(n)
|
||||||
return func(ec *EvalCtx) []Value {
|
return func(ec *EvalCtx) []Value {
|
||||||
|
|
|
@ -98,6 +98,7 @@ var evalTests = []struct {
|
||||||
{"println [a b c] [&key=value] | from-lines",
|
{"println [a b c] [&key=value] | from-lines",
|
||||||
strs("[a b c] [&key=value]"), nomore},
|
strs("[a b c] [&key=value]"), nomore},
|
||||||
{"put [a b c][2]", strs("c"), nomore},
|
{"put [a b c][2]", strs("c"), nomore},
|
||||||
|
{"put [;a;b c][2][0]", strs("b"), nomore},
|
||||||
{"put [&key=value][key]", strs("value"), nomore},
|
{"put [&key=value][key]", strs("value"), nomore},
|
||||||
|
|
||||||
// String literal
|
// String literal
|
||||||
|
|
Loading…
Reference in New Issue
Block a user