Пример #1
0
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
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
}

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
	}