예제 #1
0
파일: gosick.go 프로젝트: k0kubun/gosick
func invokeInteractiveShell(options *Options) {
	mainInterpreter := scheme.NewInterpreter("")

	for {
		indentLevel := 0
		expression := ""

		for {
			currentLine, err := linenoise.Line(shellPrompt(indentLevel))
			if err != nil {
				log.Fatal(err)
				return
			}
			if currentLine == "exit" {
				return
			}
			linenoise.AddHistory(currentLine)
			expression += " "
			expression += currentLine

			interpreter := scheme.NewInterpreter(expression)
			indentLevel = interpreter.IndentLevel()
			if indentLevel == 0 {
				mainInterpreter.ReloadSourceCode(expression)
				mainInterpreter.PrintResults(options.DumpAST)
				break
			} else if indentLevel < 0 {
				fmt.Println("*** ERROR: extra close parentheses")
				expression = ""
				indentLevel = 0
			}
		}
	}
}
예제 #2
0
파일: gosick.go 프로젝트: k0kubun/gosick
func executeExpression(expression string, dumpAST bool) {
	interpreter := scheme.NewInterpreter(expression)
	interpreter.PrintErrors(dumpAST)
}