예제 #1
0
파일: string.go 프로젝트: katydid/katydid
//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()))
}
예제 #2
0
파일: builtin.go 프로젝트: katydid/katydid
//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
}