当前位置: 首页>>代码示例>>Golang>>正文


Golang Primary.Parent方法代码示例

本文整理汇总了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
}
开发者ID:rathinaganesh,项目名称:elvish,代码行数:29,代码来源:nodeutil.go

示例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
}
开发者ID:zhsj,项目名称:elvish,代码行数:15,代码来源:nodeutil.go

示例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
}
开发者ID:wanlanjian,项目名称:elvish,代码行数:43,代码来源:nodeutil.go


注:本文中的github.com/elves/elvish/parse.Primary.Parent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。