示例#1
0
文件: atom.go 项目: kooksee/gisp2
func atomNameParser() p.P {
	return p.Do(func(state p.State) interface{} {
		ret := p.Many1(p.RuneNone("'[]() \t\r\n\".:")).Bind(p.ReturnString).Exec(state)
		test := p.BasicStateFromText(ret.(string))
		_, err := p.Many1(p.Digit).Then(p.EOF).Parse(&test)
		if err == nil {
			p.Fail("atom name can't be a int like %s", ret)
		}
		return ret
	})
}
示例#2
0
文件: parsec.go 项目: kooksee/gisp2
			}
		},
		"failed": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 1 {
				return nil, fmt.Errorf("Parsex Parser Failed Error: only accept one string as arg but %v", args)
			}
			param, err := Eval(env, args[0])
			if err != nil {
				return nil, err
			}
			var str string
			var ok bool
			if str, ok = param.(string); !ok {
				return nil, fmt.Errorf("Failed Arg Error:expect 1 string arg.")
			}
			return ParsecBox(p.Fail(str)), nil
		},
		"oneof": func(env Env, args ...interface{}) (Lisp, error) {
			params, err := Evals(env, args...)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.OneOf(params...)), nil
		},
		"noneof": func(env Env, args ...interface{}) (Lisp, error) {
			params, err := Evals(env, args...)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.NoneOf(params)), nil
		},