示例#1
0
文件: parser_test.go 项目: rns/parser
func (s *S) TestByteFailure(c *C) {
	value, err := P.Parse(P.Byte(':'), srd("batman"))
	c.Assert(err, NotNil)
	c.Assert(value, Equals, nil)
}
示例#2
0
文件: parser_test.go 项目: rns/parser
func (s *S) TestByteSuccess(c *C) {
	value, err := P.Parse(P.Byte(':'), srd(":symbol"))
	c.Assert(err, IsNil)
	c.Assert(value, Equals, byte(':'))
}
示例#3
0
文件: parser_test.go 项目: rns/parser
}

func (s *S) TestByteFailure(c *C) {
	value, err := P.Parse(P.Byte(':'), srd("batman"))
	c.Assert(err, NotNil)
	c.Assert(value, Equals, nil)
}

func (s *S) TestByteSuccess(c *C) {
	value, err := P.Parse(P.Byte(':'), srd(":symbol"))
	c.Assert(err, IsNil)
	c.Assert(value, Equals, byte(':'))
}

var (
	lBrace = P.Byte('{')
	rBrace = P.Byte('}')
	colon  = P.Byte(':')
	quote  = `"`
)

func JsonObject(r *P.Reader) (result interface{}, rd *P.Reader, err error) {
	key := P.Between(quote, quote, P.String("key"))
	value := P.Between(quote, quote, P.String("value"))
	p := P.And(lBrace, key, colon, value, rBrace)

	result, rd, err = p(r)
	if err != nil {
		return
	}