Esempio n. 1
0
File: atom.go Progetto: gale320/gisp
func atomNameParser(st p.ParseState) (interface{}, error) {
	ret, err := p.Bind(p.Many1(p.NoneOf("'[]() \t\r\n\".:")),
		p.ReturnString)(st)
	if err != nil {
		return nil, err
	}
	test := p.MemoryParseState(ret.(string))
	_, err = p.Bind_(p.Many1(p.Digit), p.Eof)(test)
	if err == nil {
		return nil, fmt.Errorf("atom name can't be a int like %s", ret.(string))
	}
	return ret, nil
}
Esempio n. 2
0
			return '\'', nil
		case '\\':
			return '\\', nil
		case 't':
			return '\t', nil
		default:
			return nil, st.Trap("Unknown escape sequence \\%c", r)
		}
	} else {
		return nil, err
	}
})

var RuneParser = p.Bind(
	p.Between(p.Rune('\''), p.Rune('\''),
		p.Either(p.Try(EscapeCharr), p.NoneOf("'"))),
	func(x interface{}) p.Parser {
		return p.Return(Rune(x.(rune)))
	},
)

var StringParser = p.Bind(
	p.Between(p.Rune('"'), p.Rune('"'),
		p.Many(p.Either(p.Try(EscapeChars), p.NoneOf("\"")))),
	p.ReturnString)

func bodyParser(st p.ParseState) (interface{}, error) {
	value, err := p.SepBy(ValueParser, p.Many1(Space))(st)
	return value, err
}
Esempio n. 3
0
		"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.")
			}
			return ParsecBox(p.NoneOf(data)), nil
		},
		"between": func(env Env, args ...interface{}) (Lisp, error) {
			ptype := reflect.TypeOf((*Parsecer)(nil)).Elem()
			params, err := GetArgs(env, px.UnionAll(TypeAs(ptype), TypeAs(ptype), TypeAs(ptype), px.Eof), args)
			if err != nil {
				return nil, err
			}
			return ParsecBox(p.Between(params[0].(Parsecer).Parser, params[1].(Parsecer).Parser, params[2].(Parsecer).Parser)), nil
		},
		"bind": func(env Env, args ...interface{}) (Lisp, error) {
			if len(args) != 2 {
				return nil, ParsexSignErrorf("Bind Args Error:except 2 args.")
			}
			prs, err := Eval(env, args[0])
			if err != nil {