func stop(st p.ParseState) (interface{}, error) { pos := st.Pos() defer st.SeekTo(pos) r, err := p.Choice( p.Try(p.Space), p.Try(p.NewLine), p.Try(p.OneOf(":.()[]{}?")), p.Try(p.Eof), )(st) if err != nil { return nil, err } return r, nil }
func IntParser(st p.ParseState) (interface{}, error) { i, err := p.Int(st) if err == nil { val, err := strconv.Atoi(i.(string)) if err == nil { return Int(val), nil } return nil, err } return nil, err } // 用于string var EscapeChars = p.Bind_(p.Rune('\\'), func(st p.ParseState) (interface{}, error) { r, err := p.OneOf("nrt\"\\")(st) if err == nil { ru := r.(rune) switch ru { case 'r': return '\r', nil case 'n': return '\n', nil case '"': return '"', nil case '\\': return '\\', nil case 't': return '\t', nil default: return nil, st.Trap("Unknown escape sequence \\%c", r)
"oneof": func(env Env, args ...interface{}) (Lisp, error) { if len(args) != 1 { return nil, ParsexSignErrorf("OneOf Arg Error:except args has 1 arg.") } param, err := Eval(env, args[0]) if err != nil { return nil, err } var ( data string ok bool ) if data, ok = param.(string); !ok { return nil, ParsexSignErrorf("OneOf Arg Error:except args has 1 string arg.") } return ParsecBox(p.OneOf(data)), nil }, "noneof": func(env Env, args ...interface{}) (Lisp, error) { if len(args) != 1 { return nil, ParsexSignErrorf("NoneOf Arg Error:except args has 1 arg.") } param, err := Eval(env, args[0]) if err != nil { return nil, err } var ( data string ok bool ) if data, ok = param.(string); !ok { return nil, ParsexSignErrorf("NoneOf Arg Error:except args has 1 string arg.")