本文整理匯總了Golang中robpike/io/ivy/parse.Parser.FlushToNewline方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.FlushToNewline方法的具體用法?Golang Parser.FlushToNewline怎麽用?Golang Parser.FlushToNewline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類robpike/io/ivy/parse.Parser
的用法示例。
在下文中一共展示了Parser.FlushToNewline方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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)
}
}
}
示例3: 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)
}
}
}