mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
indexed -> indexing
This commit is contained in:
parent
9551123779
commit
6a5f6bf244
|
@ -28,18 +28,18 @@ func formHead(n parse.Node) (parse.Node, string) {
|
|||
}
|
||||
|
||||
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
|
||||
thisIndexed, ok := pn.Parent().(*parse.Indexed)
|
||||
thisIndexing, ok := pn.Parent().(*parse.Indexing)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
thisCompound, ok := thisIndexed.Parent().(*parse.Compound)
|
||||
thisCompound, ok := thisIndexing.Parent().(*parse.Compound)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
head := ""
|
||||
for _, in := range thisCompound.Indexeds {
|
||||
for _, in := range thisCompound.Indexings {
|
||||
if len(in.Indicies) > 0 {
|
||||
return nil, ""
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
|
|||
return nil, ""
|
||||
}
|
||||
head += in.Head.Value
|
||||
if in == thisIndexed {
|
||||
if in == thisIndexing {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,10 @@ func (cp *compiler) assignments(ns []*parse.Assignment) []op {
|
|||
return ops
|
||||
}
|
||||
|
||||
func (cp *compiler) indexedVars(ns []*parse.Indexed, msg string) []variableOp {
|
||||
func (cp *compiler) indexingVars(ns []*parse.Indexing, msg string) []variableOp {
|
||||
ops := make([]variableOp, len(ns))
|
||||
for i, n := range ns {
|
||||
ops[i] = cp.indexedVar(n, msg)
|
||||
ops[i] = cp.indexingVar(n, msg)
|
||||
}
|
||||
return ops
|
||||
}
|
||||
|
@ -66,10 +66,10 @@ func (cp *compiler) arrays(ns []*parse.Array) []valuesOp {
|
|||
return ops
|
||||
}
|
||||
|
||||
func (cp *compiler) indexeds(ns []*parse.Indexed) []valuesOp {
|
||||
func (cp *compiler) indexings(ns []*parse.Indexing) []valuesOp {
|
||||
ops := make([]valuesOp, len(ns))
|
||||
for i, n := range ns {
|
||||
ops[i] = cp.indexed(n)
|
||||
ops[i] = cp.indexing(n)
|
||||
}
|
||||
return ops
|
||||
}
|
||||
|
|
|
@ -186,16 +186,16 @@ func (cp *compiler) assignment(n *parse.Assignment) op {
|
|||
var variableOps []variableOp
|
||||
if n.Dst.Head.Type == parse.Braced {
|
||||
compounds := n.Dst.Head.Braced
|
||||
indexeds := make([]*parse.Indexed, len(compounds))
|
||||
indexings := make([]*parse.Indexing, len(compounds))
|
||||
for i, cn := range compounds {
|
||||
if len(cn.Indexeds) != 1 {
|
||||
if len(cn.Indexings) != 1 {
|
||||
cp.errorf(cn.Begin(), "must be a variable spec")
|
||||
}
|
||||
indexeds[i] = cn.Indexeds[0]
|
||||
indexings[i] = cn.Indexings[0]
|
||||
}
|
||||
variableOps = cp.indexedVars(indexeds, "must be a variable spc")
|
||||
variableOps = cp.indexingVars(indexings, "must be a variable spc")
|
||||
} else {
|
||||
variableOps = []variableOp{cp.indexedVar(n.Dst, "must be a variable spec or a braced list of those")}
|
||||
variableOps = []variableOp{cp.indexingVar(n.Dst, "must be a variable spec or a braced list of those")}
|
||||
}
|
||||
|
||||
valuesOp := cp.compound(n.Src)
|
||||
|
@ -209,8 +209,8 @@ func (cp *compiler) assignment(n *parse.Assignment) op {
|
|||
}
|
||||
}
|
||||
|
||||
func (cp *compiler) indexedVar(n *parse.Indexed, msg string) variableOp {
|
||||
// XXX will we be using indexedVar for purposes other than setting?
|
||||
func (cp *compiler) indexingVar(n *parse.Indexing, msg string) variableOp {
|
||||
// XXX will we be using indexingVar for purposes other than setting?
|
||||
varname := cp.literal(n.Head, msg)
|
||||
p := n.Begin()
|
||||
|
||||
|
@ -247,7 +247,7 @@ func (cp *compiler) indexedVar(n *parse.Indexed, msg string) variableOp {
|
|||
for i, op := range indexOps {
|
||||
indexer, ok := variable.Get().(IndexVarer)
|
||||
if !ok {
|
||||
ec.errorf( /* from p to */ indexBegins[i], "cannot be indexed for setting (type %T)", variable.Get())
|
||||
ec.errorf( /* from p to */ indexBegins[i], "cannot be indexing for setting (type %T)", variable.Get())
|
||||
}
|
||||
values := op(ec)
|
||||
if len(values) != 1 {
|
||||
|
@ -340,11 +340,11 @@ func (cp *compiler) redir(n *parse.Redir) op {
|
|||
}
|
||||
|
||||
func (cp *compiler) compound(n *parse.Compound) valuesOp {
|
||||
if len(n.Indexeds) == 1 {
|
||||
return cp.indexed(n.Indexeds[0])
|
||||
if len(n.Indexings) == 1 {
|
||||
return cp.indexing(n.Indexings[0])
|
||||
}
|
||||
|
||||
ops := cp.indexeds(n.Indexeds)
|
||||
ops := cp.indexings(n.Indexings)
|
||||
|
||||
return func(ec *evalCtx) []Value {
|
||||
// start with a single "", do Cartesian products one by one
|
||||
|
@ -392,7 +392,7 @@ func (cp *compiler) array(n *parse.Array) valuesOp {
|
|||
return catOps(cp.compounds(n.Compounds))
|
||||
}
|
||||
|
||||
func (cp *compiler) indexed(n *parse.Indexed) valuesOp {
|
||||
func (cp *compiler) indexing(n *parse.Indexing) valuesOp {
|
||||
if len(n.Indicies) == 0 {
|
||||
return cp.primary(n.Head)
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ func (cp *compiler) indexed(n *parse.Indexed) valuesOp {
|
|||
}
|
||||
|
||||
return func(ec *evalCtx) []Value {
|
||||
v := ec.must(headOp(ec), "the indexed value", p).mustOne()
|
||||
v := ec.must(headOp(ec), "the indexing value", p).mustOne()
|
||||
for i, indexOp := range indexOps {
|
||||
index := ec.must(indexOp(ec), "the index", p).mustOne()
|
||||
v = evalIndex(ec, v, index, p, indexPoses[i])
|
||||
|
|
|
@ -75,8 +75,8 @@ func (m *muster) mustOneNonNegativeInt() int {
|
|||
}
|
||||
|
||||
func onePrimary(cn *parse.Compound) *parse.Primary {
|
||||
if len(cn.Indexeds) == 1 && len(cn.Indexeds[0].Indicies) == 0 {
|
||||
return cn.Indexeds[0].Head
|
||||
if len(cn.Indexings) == 1 && len(cn.Indexings[0].Indicies) == 0 {
|
||||
return cn.Indexings[0].Head
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ type Stringer interface {
|
|||
String() string
|
||||
}
|
||||
|
||||
// Indexer represents a Value that may be indexed.
|
||||
// Indexer represents a Value that may be indexing.
|
||||
type Indexer interface {
|
||||
Index(idx Value) Value
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ func (r Rat) String() string {
|
|||
func evalIndex(ec *evalCtx, l, r Value, lp, rp int) Value {
|
||||
left, ok := l.(Indexer)
|
||||
if !ok {
|
||||
ec.errorf(lp, "%s value cannot be indexed", l.Type())
|
||||
ec.errorf(lp, "%s value cannot be indexing", l.Type())
|
||||
}
|
||||
|
||||
right, ok := r.(String)
|
||||
|
|
|
@ -46,26 +46,26 @@ func parsePrimary(ps *parser, cut runePred) *Primary {
|
|||
return n
|
||||
}
|
||||
|
||||
func (n *Indexed) setHead(ch *Primary) {
|
||||
func (n *Indexing) setHead(ch *Primary) {
|
||||
n.Head = ch
|
||||
addChild(n, ch)
|
||||
}
|
||||
|
||||
func (n *Indexed) addToIndicies(ch *Array) {
|
||||
func (n *Indexing) addToIndicies(ch *Array) {
|
||||
n.Indicies = append(n.Indicies, ch)
|
||||
addChild(n, ch)
|
||||
}
|
||||
|
||||
func parseIndexed(ps *parser, cut runePred) *Indexed {
|
||||
n := &Indexed{node: node{begin: ps.pos}}
|
||||
func parseIndexing(ps *parser, cut runePred) *Indexing {
|
||||
n := &Indexing{node: node{begin: ps.pos}}
|
||||
n.parse(ps, cut)
|
||||
n.end = ps.pos
|
||||
n.sourceText = ps.src[n.begin:n.end]
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *Compound) addToIndexeds(ch *Indexed) {
|
||||
n.Indexeds = append(n.Indexeds, ch)
|
||||
func (n *Compound) addToIndexings(ch *Indexing) {
|
||||
n.Indexings = append(n.Indexings, ch)
|
||||
addChild(n, ch)
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ func parseForm(ps *parser, cut runePred) *Form {
|
|||
return n
|
||||
}
|
||||
|
||||
func (n *Assignment) setDst(ch *Indexed) {
|
||||
func (n *Assignment) setDst(ch *Indexing) {
|
||||
n.Dst = ch
|
||||
addChild(n, ch)
|
||||
}
|
||||
|
|
|
@ -590,14 +590,14 @@ func (pn *Primary) parse(ps *parser, cut runePred) {
|
|||
}
|
||||
}
|
||||
|
||||
// Indexed = Primary { '[' Array ']' }
|
||||
type Indexed struct {
|
||||
// Indexing = Primary { '[' Array ']' }
|
||||
type Indexing struct {
|
||||
node
|
||||
Head *Primary
|
||||
Indicies []*Array
|
||||
}
|
||||
|
||||
func startsIndexed(r rune, cut runePred) bool {
|
||||
func startsIndexing(r rune, cut runePred) bool {
|
||||
return startsPrimary(r, cut)
|
||||
}
|
||||
|
||||
|
@ -605,7 +605,7 @@ var (
|
|||
shouldBeArray = newError("", "spaced")
|
||||
)
|
||||
|
||||
func (in *Indexed) parse(ps *parser, cut runePred) {
|
||||
func (in *Indexing) parse(ps *parser, cut runePred) {
|
||||
in.setHead(parsePrimary(ps, cut))
|
||||
for parseSep(in, ps, '[') {
|
||||
if !startsArray(ps.peek()) {
|
||||
|
@ -619,19 +619,19 @@ func (in *Indexed) parse(ps *parser, cut runePred) {
|
|||
}
|
||||
}
|
||||
|
||||
// Compound = { Indexed }
|
||||
// Compound = { Indexing }
|
||||
type Compound struct {
|
||||
node
|
||||
Indexeds []*Indexed
|
||||
Indexings []*Indexing
|
||||
}
|
||||
|
||||
func startsCompound(r rune, cut runePred) bool {
|
||||
return startsIndexed(r, cut)
|
||||
return startsIndexing(r, cut)
|
||||
}
|
||||
|
||||
func (cn *Compound) parse(ps *parser, cut runePred) {
|
||||
for startsIndexed(ps.peek(), cut) {
|
||||
cn.addToIndexeds(parseIndexed(ps, cut))
|
||||
for startsIndexing(ps.peek(), cut) {
|
||||
cn.addToIndexings(parseIndexing(ps, cut))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,7 +646,7 @@ func isSpace(r rune) bool {
|
|||
}
|
||||
|
||||
func startsArray(r rune) bool {
|
||||
return isSpace(r) || startsIndexed(r, nil)
|
||||
return isSpace(r) || startsIndexing(r, nil)
|
||||
}
|
||||
|
||||
func (sn *Array) parse(ps *parser) {
|
||||
|
@ -826,7 +826,7 @@ loop:
|
|||
// Assignment = Primary '=' Compound
|
||||
type Assignment struct {
|
||||
node
|
||||
Dst *Indexed
|
||||
Dst *Indexing
|
||||
Src *Compound
|
||||
}
|
||||
|
||||
|
@ -836,7 +836,7 @@ func (an *Assignment) parse(ps *parser, cut runePred) {
|
|||
cutWithEqual := runePred(func(r rune) bool {
|
||||
return cut.matches(r) || r == '='
|
||||
})
|
||||
an.setDst(parseIndexed(ps, cutWithEqual))
|
||||
an.setDst(parseIndexing(ps, cutWithEqual))
|
||||
if !parseSep(an, ps, '=') {
|
||||
ps.error = shouldBeEqual
|
||||
return
|
||||
|
|
|
@ -61,56 +61,56 @@ var goodCases = []struct {
|
|||
|
||||
// Compound
|
||||
{`a b"foo"$c'xyz'`, a(ast{"Compound", fs{
|
||||
"Indexeds": []string{"b", `"foo"`, "$c", "'xyz'"}}})},
|
||||
"Indexings": []string{"b", `"foo"`, "$c", "'xyz'"}}})},
|
||||
|
||||
// Indexed
|
||||
{"a $b[c][d][e]", a(ast{"Compound/Indexed", fs{
|
||||
// Indexing
|
||||
{"a $b[c][d][e]", a(ast{"Compound/Indexing", fs{
|
||||
"Head": "$b", "Indicies": []string{"c", "d", "e"},
|
||||
}})},
|
||||
|
||||
// Primary
|
||||
//
|
||||
// Single quote
|
||||
{"a 'b'", a(ast{"Compound/Indexed/Primary", fs{
|
||||
{"a 'b'", a(ast{"Compound/Indexing/Primary", fs{
|
||||
"text": "'b'", "Type": SingleQuoted,
|
||||
}})},
|
||||
// Double quote
|
||||
{`a "b"`, a(ast{"Compound/Indexed/Primary", fs{
|
||||
{`a "b"`, a(ast{"Compound/Indexing/Primary", fs{
|
||||
"text": `"b"`, "Type": DoubleQuoted,
|
||||
}})},
|
||||
// List
|
||||
{"a [] [ ] [1] [ 2] [3 ] [ 4 5 6 7 ]", a(
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": List}},
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": List}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": List}},
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": List}},
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": List,
|
||||
"List": ast{"Array", fs{"Compounds": []string{"1"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": List,
|
||||
"List": ast{"Array", fs{"Compounds": []string{"2"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": List,
|
||||
"List": ast{"Array", fs{"Compounds": []string{"3"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": List,
|
||||
"List": ast{"Array", fs{
|
||||
"Compounds": []string{"4", "5", "6", "7"}}}}},
|
||||
)},
|
||||
// Map
|
||||
{"a [&k v] [ &k v] [&k v ] [ &k v ] [&a b &c d &e f]", a(
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Map,
|
||||
"MapPairs": []ast{ast{"MapPair", fs{"Key": "k", "Value": "v"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Map,
|
||||
"MapPairs": []ast{ast{"MapPair", fs{"Key": "k", "Value": "v"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Map,
|
||||
"MapPairs": []ast{ast{"MapPair", fs{"Key": "k", "Value": "v"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Map,
|
||||
"MapPairs": []ast{ast{"MapPair", fs{"Key": "k", "Value": "v"}}}}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Map,
|
||||
"MapPairs": []ast{
|
||||
ast{"MapPair", fs{"Key": "a", "Value": "b"}},
|
||||
|
@ -120,24 +120,24 @@ var goodCases = []struct {
|
|||
)},
|
||||
// Empty map
|
||||
{"a [&] [ &] [& ] [ & ]", a(
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": Map, "text": "[&]"}},
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": Map, "text": "[ &]"}},
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": Map, "text": "[& ]"}},
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": Map, "text": "[ & ]"}},
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": Map, "text": "[&]"}},
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": Map, "text": "[ &]"}},
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": Map, "text": "[& ]"}},
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": Map, "text": "[ & ]"}},
|
||||
)},
|
||||
// Lambda
|
||||
{"a []{} [ ]{ } []{ echo 233 } [ $x $y ]{puts $x $y}", a(
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Lambda,
|
||||
}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Lambda,
|
||||
}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Lambda,
|
||||
"Chunk": " echo 233 ",
|
||||
}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Lambda,
|
||||
"List": "$x $y ",
|
||||
"Chunk": "puts $x $y",
|
||||
|
@ -145,8 +145,8 @@ var goodCases = []struct {
|
|||
)},
|
||||
// Output capture
|
||||
{"a () (b;c)", a(
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": OutputCapture}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": OutputCapture}},
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": OutputCapture, "Chunk": "b;c",
|
||||
}})},
|
||||
// Output capture with backquotes
|
||||
|
@ -155,13 +155,13 @@ var goodCases = []struct {
|
|||
{"a `a (b `c`)` `d [`e`]`", a("`a (b `c`)`", "`d [`e`]`")},
|
||||
// Exitus capture
|
||||
{"a ?() ?(b;c)", a(
|
||||
ast{"Compound/Indexed/Primary", fs{"Type": ErrorCapture}},
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{"Type": ErrorCapture}},
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": ErrorCapture, "Chunk": "b;c",
|
||||
}})},
|
||||
// Braced
|
||||
{"a {a,c-f}", a(
|
||||
ast{"Compound/Indexed/Primary", fs{
|
||||
ast{"Compound/Indexing/Primary", fs{
|
||||
"Type": Braced,
|
||||
"Braced": []string{"a", "c", "f"},
|
||||
"IsRange": []bool{false, true}}})},
|
||||
|
|
Loading…
Reference in New Issue
Block a user