本文整理匯總了Golang中github.com/elves/elvish/parse.Node類的典型用法代碼示例。如果您正苦於以下問題:Golang Node類的具體用法?Golang Node怎麽用?Golang Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Node類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: complVariable
func complVariable(n parse.Node, ed *Editor) (int, int, []*candidate) {
begin, end := n.Begin(), n.End()
primary, ok := n.(*parse.Primary)
if !ok || primary.Type != parse.Variable {
return -1, -1, nil
}
splice, ns, head := eval.ParseVariable(primary.Value)
// Collect matching variables.
var varnames []string
iterateVariables(ed.evaler, ns, func(varname string) {
if strings.HasPrefix(varname, head) {
varnames = append(varnames, varname)
}
})
sort.Strings(varnames)
cands := make([]*candidate, len(varnames))
// Build candidates.
for i, varname := range varnames {
cands[i] = &candidate{text: "$" + eval.MakeVariableName(splice, ns, varname)}
}
return begin, end, cands
}
示例2: style
func (s *Stylist) style(n parse.Node) {
if fn, ok := n.(*parse.Form); ok {
for _, an := range fn.Assignments {
if an.Dst != nil && an.Dst.Head != nil {
v := an.Dst.Head
s.add(styleForType[Variable].String(), v.Begin(), v.End())
}
}
if fn.Head != nil {
s.formHead(fn.Head)
}
}
if cn, ok := n.(*parse.Control); ok {
switch cn.Kind {
case parse.ForControl:
if cn.Iterator != nil {
v := cn.Iterator.Head
s.add(styleForType[Variable].String(), v.Begin(), v.End())
}
case parse.TryControl:
if cn.ExceptVar != nil {
v := cn.ExceptVar.Head
s.add(styleForType[Variable].String(), v.Begin(), v.End())
}
}
}
for _, child := range n.Children() {
s.style(child)
}
}
示例3: complNewForm
func complNewForm(n parse.Node, ed *Editor) []*candidate {
if _, ok := n.(*parse.Chunk); ok {
return complFormHeadInner("", ed)
}
if _, ok := n.Parent().(*parse.Chunk); ok {
return complFormHeadInner("", ed)
}
return nil
}
示例4: produceTokens
func produceTokens(n parse.Node, tokenCh chan<- Token) {
if len(n.Children()) == 0 {
tokenType := ParserError
moreStyle := ""
switch n := n.(type) {
case *parse.Primary:
switch n.Type {
case parse.Bareword:
tokenType = Bareword
case parse.SingleQuoted:
tokenType = SingleQuoted
case parse.DoubleQuoted:
tokenType = DoubleQuoted
case parse.Variable:
tokenType = Variable
case parse.Wildcard:
tokenType = Wildcard
case parse.Tilde:
tokenType = Tilde
}
case *parse.Sep:
tokenType = Sep
moreStyle = styleForSep[n.SourceText()]
}
tokenCh <- Token{tokenType, n.SourceText(), n, moreStyle}
}
for _, child := range n.Children() {
produceTokens(child, tokenCh)
}
}
示例5: findArgContext
func findArgContext(n parse.Node) (int, int, string, parse.PrimaryType, *parse.Form) {
if sep, ok := n.(*parse.Sep); ok {
if form, ok := sep.Parent().(*parse.Form); ok {
return n.End(), n.End(), "", parse.Bareword, form
}
}
if primary, ok := n.(*parse.Primary); ok {
if compound, head := primaryInSimpleCompound(primary); compound != nil {
if form, ok := compound.Parent().(*parse.Form); ok {
if form.Head != compound {
return compound.Begin(), compound.End(), head, primary.Type, form
}
}
}
}
return -1, -1, "", 0, nil
}
示例6: findFormHeadContext
func findFormHeadContext(n parse.Node) (int, int, string, parse.PrimaryType) {
_, isChunk := n.(*parse.Chunk)
_, isPipeline := n.(*parse.Pipeline)
if isChunk || isPipeline {
return n.Begin(), n.End(), "", parse.Bareword
}
if primary, ok := n.(*parse.Primary); ok {
if compound, head := primaryInSimpleCompound(primary); compound != nil {
if form, ok := compound.Parent().(*parse.Form); ok {
if form.Head == compound {
return compound.Begin(), compound.End(), head, primary.Type
}
}
}
}
return -1, -1, "", 0
}
示例7: complVariable
func complVariable(n parse.Node, ed *Editor) (int, int, []*candidate) {
begin, end := n.Begin(), n.End()
primary, ok := n.(*parse.Primary)
if !ok || primary.Type != parse.Variable {
return -1, -1, nil
}
// XXX Repeats eval.ParseVariable.
explode, qname := eval.ParseVariableSplice(primary.Value)
nsPart, nameHead := eval.ParseVariableQName(qname)
ns := nsPart
if len(ns) > 0 {
ns = ns[:len(ns)-1]
}
// Collect matching variables.
var varnames []string
iterateVariables(ed.evaler, ns, func(varname string) {
if strings.HasPrefix(varname, nameHead) {
varnames = append(varnames, nsPart+varname)
}
})
// Collect namespace prefixes.
// TODO Support non-module namespaces.
for ns := range ed.evaler.Modules {
if hasProperPrefix(ns+":", qname) {
varnames = append(varnames, ns+":")
}
}
sort.Strings(varnames)
cands := make([]*candidate, len(varnames))
// Build candidates.
for i, varname := range varnames {
cands[i] = &candidate{text: "$" + explode + varname}
}
return begin, end, cands
}
示例8: produceTokens
func produceTokens(n parse.Node, tokenCh chan<- Token) {
if n.Begin() == n.End() {
// Ignore empty node. This happens e.g. with an empty source code, where
// the parsed node is an empty Chunk.
return
}
if len(n.Children()) == 0 {
tokenType := ParserError
moreStyle := ""
switch n := n.(type) {
case *parse.Primary:
switch n.Type {
case parse.Bareword:
tokenType = Bareword
case parse.SingleQuoted:
tokenType = SingleQuoted
case parse.DoubleQuoted:
tokenType = DoubleQuoted
case parse.Variable:
tokenType = Variable
case parse.Wildcard:
tokenType = Wildcard
case parse.Tilde:
tokenType = Tilde
}
case *parse.Sep:
tokenType = Sep
septext := n.SourceText()
if strings.HasPrefix(septext, "#") {
moreStyle = styleForSep["#"]
} else {
moreStyle = styleForSep[septext]
}
default:
Logger.Printf("bad leaf type %T", n)
}
tokenCh <- Token{tokenType, n.SourceText(), n, moreStyle}
}
for _, child := range n.Children() {
produceTokens(child, tokenCh)
}
}
示例9: compiling
func (cp *compiler) compiling(n parse.Node) {
cp.begin, cp.end = n.Begin(), n.End()
}