示例#1
0
文件: parsec.go 项目: damonchen/pjson
// key,value通过逗号进行分隔,类似list处理
func objectBodyParser(st p.State) (interface{}, error) {
	value, err := p.SepBy(objectKeyValueParser(), Skip.Then(Comma).Then(Skip))(st)
	if err != nil {
		return nil, err
	}

	o := Object{}
	if vlist, ok := value.([]interface{}); ok {
		for _, p := range vlist {
			if pair, ok := p.(Pair); ok {
				o[pair.Key] = pair.Value
			}
		}
	}

	return o, nil
}
示例#2
0
文件: parses.go 项目: kooksee/gisp2
func bodyParser(st p.State) (interface{}, error) {
	value, err := p.SepBy(ValueParser(), Skip)(st)
	return value, err
}
示例#3
0
文件: parsec.go 项目: kooksee/gisp2
		},
		"sepby1": func(env Env, args ...interface{}) (Lisp, error) {
			ptype := reflect.TypeOf((*Parsecer)(nil)).Elem()
			params, err := GetArgs(env, p.UnionAll(TypeAs(ptype), TypeAs(ptype), p.EOF), args)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.SepBy1(params[0].(Parsecer).Parser, params[1].(Parsecer).Parser)), nil
		},
		"sepby": func(env Env, args ...interface{}) (Lisp, error) {
			ptype := reflect.TypeOf((*Parsecer)(nil)).Elem()
			params, err := GetArgs(env, p.UnionAll(TypeAs(ptype), TypeAs(ptype), p.EOF), args)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.SepBy(params[0].(Parsecer).Parser, params[1].(Parsecer).Parser)), nil
		},
		"manytill": func(env Env, args ...interface{}) (Lisp, error) {
			ptype := reflect.TypeOf((*Parsecer)(nil)).Elem()
			params, err := GetArgs(env, p.UnionAll(TypeAs(ptype), TypeAs(ptype), p.EOF), args)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.ManyTill(params[0].(Parsecer).Parser, params[1].(Parsecer).Parser)), nil
		},
		"maybe": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 1 {
				return nil, fmt.Errorf("Parsex Parser Maybe Error: only accept one parsex parser as arg but %v", args)
			}
			param, err := Eval(env, args[0])
			if err != nil {
示例#4
0
文件: parsec.go 项目: damonchen/pjson
func listBodyParser(st p.State) (interface{}, error) {
	value, err := p.SepBy(ValueParser(), Skip.Then(Comma).Then(Skip))(st)
	return value, err
}