1
0
Fork 0

Document side effects

This commit is contained in:
Gregory Eremin 2015-02-17 23:00:09 +07:00
parent 3dffc49ea7
commit e33501d6a5
2 changed files with 12 additions and 2 deletions

View File

@ -70,12 +70,15 @@ func (p *Parser) parseValue(item lexer.Item) {
// Is called after '[' and ',' tokens
// Expects a value followed by ']' or ',' tokens
func (p *Parser) parseArray(i int64) {
p.ctx.setIndex(i)
item := p.next()
if item.Token == lexer.BracketClose {
// Neither a bug nor a feature
// This allows an array to have a trailing comma
// [1, 2, 3, ]
return
}
p.ctx.setIndex(i)
p.parseValue(item)
switch item := p.next(); item.Token {
@ -90,6 +93,9 @@ func (p *Parser) parseObject() {
item := p.next()
switch item.Token {
case lexer.BraceClose:
// Neither a bug nor a feature
// This allows an object to have a trailing comma
// {"foo": 1, "bar": 2, }
return
case lexer.String:
p.ctx.setKey(item.Val)

6
run.go
View File

@ -12,7 +12,11 @@ func main() {
f, _ := os.Open("test.json")
b, _ := ioutil.ReadAll(f)
p := parser.New(b, []string{"/bananas/[*]/weight"})
p := parser.New(b, []string{
"/prices/pomelo",
"/prices/peach",
"/bananas/[*]/weight",
})
res := p.Parse()
pretty.Println(res)
}