예제 #1
0
//*
func main() {
	if len(os.Args) != 2 {
		fmt.Println("add some text")
		return
	}
	tree, err := sproc.Parse("test", os.Args[1])
	fmt.Println("parsed", err)

	if tree == nil {
		fmt.Println("tree is nil!")
		return
	}

	if tree.Root == nil {
		fmt.Println("tree.Root is nil!")
		return
	}

	fmt.Println("tree:")
	fmt.Println(tree.Root.Repr(""))
	fmt.Println("funcs:")
	for _, def := range tree.Defs {
		fmt.Println(def.Repr(""))
	}

	fmt.Println("---")
	fmt.Println("executing:")

	interp := sproc.NewInterpretator()
	interp.Run(tree)

	time.Sleep(2 * time.Second)
}
예제 #2
0
파일: main.go 프로젝트: mechmind/sproc-go
//*
func main() {
	if len(os.Args) != 2 {
		fmt.Println("provide some commands")
		return
	}

	tree, err := sproc.Parse(os.Args[1])
	fmt.Println("parsed", err)

	if tree == nil {
		fmt.Println("tree is nil!")
		return
	}

	if tree.Root == nil {
		fmt.Println("tree.Root is nil!")
		return
	}

	fmt.Println("tree:")
	fmt.Println(tree.Root.Repr(""))
	fmt.Println("funcs:")
	for _, def := range tree.Defs {
		fmt.Println(def.Repr(""))
	}

	fmt.Println("---")
	fmt.Println("executing:")

	done := make(chan struct{})
	cb := func(result *sproc.Value) {
		fmt.Println(result)
		close(done)
	}

	interp := sproc.NewInterpretator()
	interp.Run(tree, cb)

	<-done
	time.Sleep(100 * time.Millisecond)
}