Ejemplo n.º 1
0
func parseEqual(expr *chain.Cell) (Condition, error) {
	cond := &Equals{}

	if expr == nil {
		return nil, errors.New("missing arguments in eq")
	}

	if field, ok := expr.Car().(atomiser.Symbol); !ok {
		return nil, fmt.Errorf("expected field name, got '%#v' instead", expr.Car())
	} else {
		cond.Field = string(field)
	}

	expr = expr.Cdr()
	if expr == nil {
		return nil, fmt.Errorf("missing value in (eq %s) expression", cond.Field)
	}

	cond.Value = fmt.Sprintf("%v", expr.Car())

	return cond, nil
}
Ejemplo n.º 2
0
func parseExpressionToCondition(expr *chain.Cell) (Condition, error) {
	sym, ok := expr.Car().(atomiser.Symbol)
	if !ok {
		return nil, fmt.Errorf("expected symbol, got '%v' instead", expr.Car())
	}

	sym = atomiser.Symbol(strings.ToLower(string(sym)))

	switch sym {
	case "and":
		return parseAnd(expr.Cdr())
	case "or":
		return parseOr(expr.Cdr())
	case "eq":
		return parseEqual(expr.Cdr())
	case "id":
		return parseId(expr.Cdr())
	}
	return nil, fmt.Errorf("unknown symbol '%s'", sym)
}