本文整理汇总了Golang中robpike/io/ivy/value.Context.Assign方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Assign方法的具体用法?Golang Context.Assign怎么用?Golang Context.Assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类robpike/io/ivy/value.Context
的用法示例。
在下文中一共展示了Context.Assign方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
// run runs until EOF or error. The return value says whether we completed without error.
func run(p *parse.Parser, writer io.Writer, context value.Context, interactive bool) (success bool) {
defer func() {
if conf.Debug("panic") {
return
}
err := recover()
if err == nil {
return
}
p.FlushToNewline()
if err, ok := err.(value.Error); ok {
fmt.Fprintf(os.Stderr, "%s: %s\n", p.Loc(), err)
if interactive {
fmt.Fprintln(writer)
}
success = false
return
}
panic(err)
}()
for {
if interactive {
fmt.Fprint(writer, conf.Prompt())
}
exprs, ok := p.Line()
var values []value.Value
if exprs != nil {
values = context.Eval(exprs)
}
if values != nil {
if conf.Debug("types") {
for i, v := range values {
if i > 0 {
fmt.Fprint(writer, ",")
}
fmt.Fprintf(writer, "%T", v)
}
fmt.Fprintln(writer)
}
for i, v := range values {
s := v.String()
if i > 0 && len(s) > 0 && s[len(s)-1] != '\n' {
fmt.Fprint(writer, " ")
}
fmt.Fprint(writer, v)
}
fmt.Fprintln(writer)
context.Assign("_", values[len(values)-1])
}
if !ok {
return true
}
if interactive {
fmt.Fprintln(writer)
}
}
}
示例2: Eval
func (b *binary) Eval(context value.Context) value.Value {
rhs := b.right.Eval(context)
if b.op == "=" {
// Special handling as we cannot evaluate the left.
// We know the left is a variableExpr.
lhs := b.left.(variableExpr)
context.Assign(lhs.name, rhs)
return Assignment{Value: rhs}
}
lhs := b.left.Eval(context)
return context.EvalBinary(lhs, b.op, rhs)
}
示例3: Run
// Run runs the parser/evaluator until EOF or error.
// The return value says whether we completed without error. If the return
// value is true, it means we ran out of data (EOF) and the run was successful.
// Typical execution is therefore to loop calling Run until it succeeds.
// Error details are reported to the configured error output stream.
func Run(p *parse.Parser, context value.Context, interactive bool) (success bool) {
conf := context.Config()
writer := conf.Output()
defer func() {
if conf.Debug("panic") {
return
}
err := recover()
if err == nil {
return
}
p.FlushToNewline()
if err, ok := err.(value.Error); ok {
fmt.Fprintf(conf.ErrOutput(), "%s%s\n", p.Loc(), err)
if interactive {
fmt.Fprintln(writer)
}
success = false
return
}
panic(err)
}()
for {
if interactive {
fmt.Fprint(writer, conf.Prompt())
}
exprs, ok := p.Line()
var values []value.Value
if exprs != nil {
if interactive {
start := time.Now()
values = context.Eval(exprs)
conf.SetCPUTime(time.Now().Sub(start))
} else {
values = context.Eval(exprs)
}
}
if printValues(conf, writer, values) {
context.Assign("_", values[len(values)-1])
}
if !ok {
return true
}
if interactive {
if exprs != nil && conf.Debug("cpu") && conf.CPUTime() != 0 {
fmt.Printf("(%s)\n", conf.PrintCPUTime())
}
fmt.Fprintln(writer)
}
}
}
示例4: run
// run runs until EOF or error. The return value says whether we completed without error.
func run(p *parse.Parser, context value.Context, interactive bool) (success bool) {
writer := conf.Output()
defer func() {
if conf.Debug("panic") {
return
}
err := recover()
if err == nil {
return
}
p.FlushToNewline()
if err, ok := err.(value.Error); ok {
fmt.Fprintf(os.Stderr, "%s%s\n", p.Loc(), err)
if interactive {
fmt.Fprintln(writer)
}
success = false
return
}
panic(err)
}()
for {
if interactive {
fmt.Fprint(writer, conf.Prompt())
}
exprs, ok := p.Line()
var values []value.Value
if exprs != nil {
values = context.Eval(exprs)
}
if values != nil {
printValues(writer, values)
context.Assign("_", values[len(values)-1])
}
if !ok {
return true
}
if interactive {
fmt.Fprintln(writer)
}
}
}
示例5: Eval
func (a *assignment) Eval(context value.Context) value.Value {
context.Assign(a.variable.name, a.expr.Eval(context))
return nil
}