Ejemplo n.º 1
0
// AskExpr takes an expression and an Asker. It then parses the expression
// calling the Asker's Ask on expressions AskNodes and returns if the
// expression is true or not for the given asker.
func AskExpr(expr string, asker Asker) (bool, error) {
	q, err := parse.Parse(expr)
	if err != nil {
		return false, err
	}
	return walk(q.Root, asker)
}
Ejemplo n.º 2
0
// Parse parses an expression and returns the parsed expression.
// It can be used wtih AskParsedExpr
func Parse(text string) (*Tree, error) {
	tree := &Tree{}
	if text == "" {
		tree.Tree = &parse.Tree{}
		return tree, nil
	}
	var err error
	tree.Tree, err = parse.Parse(text)
	return tree, err
}