func xEof(x interface{}) px.Parser { return px.Bind_(px.Eof, px.Return(x)) }
var Axiom = Toolkit{ Meta: map[string]interface{}{ "name": "axiom", "category": "package", }, Content: map[string]interface{}{ "quote": LispExpr(func(env Env, args ...interface{}) (Lisp, error) { if len(args) != 1 { return nil, fmt.Errorf("Quote Args Error: except only one arg but %v", args) } return Q(Q(args[0])), nil }), "var": LispExpr(func(env Env, args ...interface{}) (Lisp, error) { st := px.NewStateInMemory(args) _, err := px.Binds_(TypeAs(ATOM), px.Either(px.Try(px.Eof), px.Bind_(px.AnyOne, px.Eof)))(st) if err != nil { return nil, err } first := args[0].(Atom) slot := VarSlot(first.Type) if len(args) == 1 { err := env.Defvar(first.Name, slot) return Q(nil), err } val, err := Eval(env, args[1]) slot.Set(val) err = env.Defvar(first.Name, slot) return Q(val), err }), "set": LispExpr(func(env Env, args ...interface{}) (Lisp, error) {
// Time 包引入了go的time包功能 var Time = Toolkit{ Meta: map[string]interface{}{ "category": "toolkit", "name": "time", }, Content: map[string]interface{}{ "now": SimpleBox{ ParsexSignChecker(px.Eof), func(args ...interface{}) Tasker { return func(env Env) (interface{}, error) { return tm.Now(), nil } }}, "parseDuration": SimpleBox{ ParsexSignChecker(px.Bind_(StringValue, px.Eof)), func(args ...interface{}) Tasker { return func(env Env) (interface{}, error) { return tm.ParseDuration(args[0].(string)) } }}, "parseTime": SimpleBox{ ParsexSignChecker(px.Binds_(StringValue, StringValue, px.Eof)), func(args ...interface{}) Tasker { return func(env Env) (interface{}, error) { return tm.Parse(args[0].(string), args[1].(string)) } }}, }, }
return func(st px.ParsexState) (interface{}, error) { return nil, ParsexSignErrorf("excpet got a parser but %v", pr) } } })), nil default: return nil, ParsexSignErrorf("excpet got a parser but %v", prs) } }, "bind_": func(env Env, args ...interface{}) (Lisp, error) { ptype := reflect.TypeOf((*Parsecer)(nil)).Elem() params, err := GetArgs(env, px.UnionAll(TypeAs(ptype), TypeAs(ptype), px.Eof), args) if err != nil { return nil, err } return ParsexBox(px.Bind_(params[0].(Parsexer).Parser, params[1].(Parsexer).Parser)), nil }, "sepby1": func(env Env, args ...interface{}) (Lisp, error) { ptype := reflect.TypeOf((*Parsexer)(nil)).Elem() params, err := GetArgs(env, px.UnionAll(TypeAs(ptype), TypeAs(ptype), px.Eof), args) if err != nil { return nil, err } return ParsexBox(px.SepBy1(params[0].(Parsexer).Parser, params[1].(Parsexer).Parser)), nil }, "sepby": func(env Env, args ...interface{}) (Lisp, error) { ptype := reflect.TypeOf((*Parsexer)(nil)).Elem() params, err := GetArgs(env, px.UnionAll(TypeAs(ptype), TypeAs(ptype), px.Eof), args) if err != nil { return nil, err }