本文整理匯總了Golang中github.com/elves/elvish/parse.Primary類的典型用法代碼示例。如果您正苦於以下問題:Golang Primary類的具體用法?Golang Primary怎麽用?Golang Primary使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Primary類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: literal
func (cp *compiler) literal(n *parse.Primary, msg string) string {
switch n.Type {
case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
return n.Value
default:
cp.errorf(n.Begin(), msg)
return "" // not reached
}
}
示例3: 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
}
示例4: 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
}
示例5: primary
func (cp *compiler) primary(n *parse.Primary) ValuesOpFunc {
switch n.Type {
case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
return literalStr(n.Value)
case parse.Variable:
qname := n.Value
if !cp.registerVariableGet(qname) {
cp.errorf("variable $%s not found", n.Value)
}
return variable(qname)
case parse.Wildcard:
vs := []Value{GlobPattern{[]glob.Segment{
wildcardToSegment(n.SourceText())}, ""}}
return func(ec *EvalCtx) []Value {
return vs
}
case parse.Tilde:
cp.errorf("compiler bug: Tilde not handled in .compound")
return literalStr("~")
case parse.PredCapture:
return cp.predCapture(n.Chunk)
case parse.OutputCapture:
return cp.outputCapture(n)
case parse.List:
return cp.list(n.List)
case parse.Lambda:
return cp.lambda(n)
case parse.Map:
return cp.map_(n)
case parse.Braced:
return cp.braced(n)
default:
cp.errorf("bad PrimaryType; parser bug")
return literalStr(n.SourceText())
}
}
示例6: primary
func (cp *compiler) primary(n *parse.Primary) valuesOp {
switch n.Type {
case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
return literalStr(n.Value)
case parse.Variable:
qname := n.Value[1:]
if !cp.registerVariableGet(qname) {
cp.errorf(n.Begin(), "variable %s not found", n.Value)
}
return variable(qname, n.Begin())
// case parse.Wildcard:
case parse.ErrorCapture:
op := cp.chunk(n.Chunk)
return func(ec *evalCtx) []Value {
return []Value{Error{ec.peval(op)}}
}
case parse.OutputCapture:
return cp.outputCapture(n)
case parse.List:
op := cp.array(n.List)
return func(ec *evalCtx) []Value {
return []Value{NewList(op(ec)...)}
}
case parse.Lambda:
return cp.lambda(n)
case parse.Map:
return cp.map_(n)
case parse.Braced:
return cp.braced(n)
default:
// XXX: Primary types not yet implemented are just treated as
// barewords. Should report parser bug of bad PrimaryType after they
// have been implemented.
return literalStr(n.SourceText())
// panic("bad PrimaryType; parser bug")
}
}
示例7: bracedOp
func (cp *compiler) bracedOp(n *parse.Primary) ValuesOp {
return ValuesOp{cp.braced(n), n.Begin(), n.End()}
}
示例8: map_Op
func (cp *compiler) map_Op(n *parse.Primary) ValuesOp {
return ValuesOp{cp.map_(n), n.Begin(), n.End()}
}
示例9: lambdaOp
func (cp *compiler) lambdaOp(n *parse.Primary) ValuesOp {
return ValuesOp{cp.lambda(n), n.Begin(), n.End()}
}
示例10: outputCaptureOp
func (cp *compiler) outputCaptureOp(n *parse.Primary) ValuesOp {
return ValuesOp{cp.outputCapture(n), n.Begin(), n.End()}
}
示例11: primaryOp
func (cp *compiler) primaryOp(n *parse.Primary) ValuesOp {
return ValuesOp{cp.primary(n), n.Begin(), n.End()}
}
示例12: primary
func (cp *compiler) primary(n *parse.Primary) ValuesOp {
switch n.Type {
case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
return literalStr(n.Value)
case parse.Variable:
qname := n.Value
if !cp.registerVariableGet(qname) {
cp.errorf(n.Begin(), "variable %s not found", n.Value)
}
return variable(qname, n.Begin())
case parse.Wildcard:
vs := []Value{GlobPattern{[]glob.Segment{
wildcardToSegment(n.SourceText())}}}
return func(ec *EvalCtx) []Value {
return vs
}
case parse.Tilde:
cp.errorf(n.Begin(), "compiler bug: Tilde not handled in .compound")
return literalStr("~")
case parse.ErrorCapture:
op := cp.chunk(n.Chunk)
return func(ec *EvalCtx) []Value {
return []Value{Error{ec.PEval(op)}}
}
case parse.OutputCapture:
return cp.outputCapture(n)
case parse.List:
op := cp.array(n.List)
return func(ec *EvalCtx) []Value {
return []Value{NewList(op(ec)...)}
}
case parse.Lambda:
return cp.lambda(n)
case parse.Map:
return cp.map_(n)
case parse.Braced:
return cp.braced(n)
default:
cp.errorf(n.Begin(), "bad PrimaryType; parser bug")
return literalStr(n.SourceText())
}
}