MCPcopy Index your code
hub / github.com/google/mangle / Loop

Method Loop

interpreter/interpreter.go:349–395  ·  view source on GitHub ↗

Loop reads lines from stdin and performs the commands.

()

Source from the content-addressed store, hash-verified

347
348// Loop reads lines from stdin and performs the commands.
349func (i *Interpreter) Loop() error {
350 i.ShowHelp()
351 for {
352 line, err := nextLine()
353 if err != nil {
354 return err
355 }
356 switch {
357 case line == "::help":
358 i.ShowHelp()
359
360 case strings.HasPrefix(line, "::load "):
361 if err := i.Load(strings.TrimPrefix(line, "::load ")); err != nil {
362 fmt.Fprintf(i.out, "load failed: %v\n", err)
363 }
364
365 case line == "::pop":
366 i.Pop()
367
368 case strings.HasPrefix(line, "::show "):
369 if err := i.Show(strings.TrimPrefix(line, "::show ")); err != nil {
370 fmt.Fprintf(i.out, "show failed: %v\n", err)
371 }
372
373 case strings.HasPrefix(line, "?"):
374 if err := i.QueryInteractive(strings.TrimPrefix(line, "?")); err != nil {
375 fmt.Fprintf(i.out, "error evaluating query: %v\n", err)
376 }
377
378 default:
379 savedBuffer := i.buffer
380 clauseText := line
381 for !strings.HasSuffix(clauseText, ".") && !strings.HasSuffix(clauseText, "!") {
382 nextLine, err := nextLineWithPrompt(continuedPrompt)
383 if err != nil {
384 return err
385 }
386 clauseText = clauseText + nextLine
387 }
388
389 if err := i.Define(clauseText); err != nil {
390 fmt.Fprintf(i.out, "definition failed: %v\n", err)
391 i.buffer = savedBuffer
392 }
393 }
394 }
395}
396
397// Preload evaluates decls and clauses before any interactive evaluation takes place.
398// This is used for customizing the interpreter.

Callers 1

mainFunction · 0.80

Calls 8

ShowHelpMethod · 0.95
LoadMethod · 0.95
PopMethod · 0.95
ShowMethod · 0.95
QueryInteractiveMethod · 0.95
DefineMethod · 0.95
nextLineFunction · 0.85
nextLineWithPromptFunction · 0.85

Tested by

no test coverage detected