func prep(expr *ast.Expr, expType types.Type) (uniq string, err error) { if expr.Function != nil { fnc := expr.GetFunction() uniq, err = WhichFunc(fnc) if err != nil { return "", err } typ, err := funcs.Out(uniq) if err != nil { return "", err } if typ != expType { return "", &errExpected{expType.String(), expr.String()} } return uniq, err } if expr.List != nil { if !types.IsList(expType) { return "", &errExpected{expType.String(), expr.String()} } } typ, err := Which(expr) if err != nil { return "", err } if typ != expType { return "", &errExpected{expType.String(), expr.String()} } return "", nil }
//String returns the relapse string representation of the Variable instance. func (this *Variable) String() string { typ := this.GetType() if types.IsList(typ) { types.ListToSingle(typ) } switch typ { case types.SINGLE_DOUBLE: return "$double" case types.SINGLE_INT: return "$int" case types.SINGLE_UINT: return "$uint" case types.SINGLE_BOOL: return "$bool" case types.SINGLE_STRING: return "$string" case types.SINGLE_BYTES: return "$[]byte" } panic(fmt.Errorf("unknown type %s", this.GetType())) }
//ConvertBuiltInIntoFunction converts a BuiltIn Expr into a Function Expr. func ConvertBuiltInIntoFunction(e *ast.Expr) (*ast.Expr, error) { if e.BuiltIn == nil { return e, nil } s := e.GetBuiltIn().GetSymbol().GetValue() right := e.GetBuiltIn().GetExpr().Clone() typ, err := Which(right) if err != nil { return nil, err } if types.IsList(typ) { typ = types.ListToSingle(typ) } left := ast.NewVar(typ) funcName := ast.BuiltInFunctionName(s) e2 := ast.NewNestedFunction(funcName, left, right) if funcName == "regex" { e2 = ast.NewNestedFunction(funcName, right, ast.NewVar(types.SINGLE_STRING)) } else if funcName == "type" { e2 = ast.NewNestedFunction(funcName, right) } return e2, nil }