Exemple #1
0
func check(t *testing.T, mp map[string]string) {
	for raw, slex := range mp {
		res := lex(lexer.Lex("test", raw))
		if res != slex {
			t.Errorf("fail in case: %q, err: %q", raw, res)
		}
	}
}
Exemple #2
0
// Syntactic parsing in two phases:
// 1. Parse the tokens into a set of tuples;
// 2. Parse the tuples into abstract syntactic tree (AST).
func ParseFromString(expr string) []ast.Node {
	parser := &Parser{lexer.Lex("gosp", expr)}
	tuples := make([]ast.Node, 0)
	parser.parse(&tuples, 0, -1)

	// For debugging.
	for _, node := range tuples {
		printType(node)
		fmt.Println()
	}

	return parseNodes(tuples)
}