示例#1
0
func runFile(filepath string, fileScope *scope) {
	codeByte, err := ioutil.ReadFile(filepath)
	if err != nil {
		panic(err)
	}

	p := parser.NewParser()
	p.Filename(filepath)
	for _, c := range codeByte {
		p.Read(rune(c))
	}
	p.Complete()
	ast := toSequence(p.ToArray())

	for _, line := range ast {
		fileScope.getValue(line)
	}
}
示例#2
0
func runRepl(fileScope *scope) {
	reader := bufio.NewReader(os.Stdin)
	for {
		fmt.Print("cirru> ")
		text, _ := reader.ReadString('\n')
		if len(text) == 0 {
			os.Exit(2)
		}
		p := parser.NewParser()
		p.Filename("repl")
		for _, c := range []byte(text) {
			p.Read(rune(c))
		}
		p.Complete()
		ast := toSequence(p.ToArray())

		for _, line := range ast {
			ret := fileScope.getValue(line)
			fmt.Println(stringifyUnitype(ret))
		}
	}
}