本文整理汇总了Golang中github.com/elves/elvish/parse.Primary.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang Primary.Parent方法的具体用法?Golang Primary.Parent怎么用?Golang Primary.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/elves/elvish/parse.Primary
的用法示例。
在下文中一共展示了Primary.Parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: simpleCompound
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
thisIndexing, ok := pn.Parent().(*parse.Indexing)
if !ok {
return nil, ""
}
thisCompound, ok := thisIndexing.Parent().(*parse.Compound)
if !ok {
return nil, ""
}
head := ""
for _, in := range thisCompound.Indexings {
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 == thisIndexing {
break
}
}
return thisCompound, head
}
示例2: primaryInSimpleCompound
func primaryInSimpleCompound(pn *parse.Primary) (*parse.Compound, string) {
thisIndexing, ok := pn.Parent().(*parse.Indexing)
if !ok {
return nil, ""
}
thisCompound, ok := thisIndexing.Parent().(*parse.Compound)
if !ok {
return nil, ""
}
ok, head, _ := simpleCompound(thisCompound, thisIndexing)
if !ok {
return nil, ""
}
return thisCompound, head
}
示例3: simpleCompound
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
thisIndexing, ok := pn.Parent().(*parse.Indexing)
if !ok {
return nil, ""
}
thisCompound, ok := thisIndexing.Parent().(*parse.Compound)
if !ok {
return nil, ""
}
tilde := false
head := ""
for _, in := range thisCompound.Indexings {
if len(in.Indicies) > 0 {
return nil, ""
}
switch in.Head.Type {
case parse.Tilde:
tilde = true
case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
head += in.Head.Value
}
if in == thisIndexing {
break
}
}
if tilde {
i := strings.Index(head, "/")
if i == -1 {
return nil, ""
}
uname := head[:i]
home, err := osutil.GetHome(uname)
if err != nil {
// TODO report error
return nil, ""
}
head = home + head[i:]
}
return thisCompound, head
}