mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
edit: move utils for evaluation of nodes into nodeutil.go
This commit is contained in:
parent
52d3565af1
commit
ea2b7e8b92
|
@ -43,53 +43,6 @@ func init() {
|
|||
builtins = append(builtins, eval.BuiltinSpecialNames...)
|
||||
}
|
||||
|
||||
func formHead(n parse.Node) (parse.Node, string) {
|
||||
if _, ok := n.(*parse.Chunk); ok {
|
||||
return n, ""
|
||||
}
|
||||
|
||||
if primary, ok := n.(*parse.Primary); ok {
|
||||
compound, head := simpleCompound(primary)
|
||||
if form, ok := compound.Parent().(*parse.Form); ok {
|
||||
if form.Head == compound {
|
||||
return compound, head
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
|
||||
thisIndexed, ok := pn.Parent().(*parse.Indexed)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
thisCompound, ok := thisIndexed.Parent().(*parse.Compound)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
head := ""
|
||||
for _, in := range thisCompound.Indexeds {
|
||||
if len(in.Indicies) > 0 {
|
||||
return nil, ""
|
||||
}
|
||||
typ := in.Head.Type
|
||||
if typ != parse.Bareword &&
|
||||
typ != parse.SingleQuoted &&
|
||||
typ != parse.DoubleQuoted {
|
||||
return nil, ""
|
||||
}
|
||||
head += in.Head.Value
|
||||
if in == thisIndexed {
|
||||
break
|
||||
}
|
||||
}
|
||||
return thisCompound, head
|
||||
}
|
||||
|
||||
func complArg(n parse.Node, ed *Editor) ([]*candidate, int) {
|
||||
pn, ok := n.(*parse.Primary)
|
||||
if !ok {
|
||||
|
|
50
edit/nodeutil.go
Normal file
50
edit/nodeutil.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package edit
|
||||
|
||||
import "github.com/elves/elvish/parse"
|
||||
|
||||
func formHead(n parse.Node) (parse.Node, string) {
|
||||
if _, ok := n.(*parse.Chunk); ok {
|
||||
return n, ""
|
||||
}
|
||||
|
||||
if primary, ok := n.(*parse.Primary); ok {
|
||||
compound, head := simpleCompound(primary)
|
||||
if form, ok := compound.Parent().(*parse.Form); ok {
|
||||
if form.Head == compound {
|
||||
return compound, head
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
|
||||
thisIndexed, ok := pn.Parent().(*parse.Indexed)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
thisCompound, ok := thisIndexed.Parent().(*parse.Compound)
|
||||
if !ok {
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
head := ""
|
||||
for _, in := range thisCompound.Indexeds {
|
||||
if len(in.Indicies) > 0 {
|
||||
return nil, ""
|
||||
}
|
||||
typ := in.Head.Type
|
||||
if typ != parse.Bareword &&
|
||||
typ != parse.SingleQuoted &&
|
||||
typ != parse.DoubleQuoted {
|
||||
return nil, ""
|
||||
}
|
||||
head += in.Head.Value
|
||||
if in == thisIndexed {
|
||||
break
|
||||
}
|
||||
}
|
||||
return thisCompound, head
|
||||
}
|
Loading…
Reference in New Issue
Block a user