Document side effects
This commit is contained in:
parent
3dffc49ea7
commit
e33501d6a5
|
@ -70,12 +70,15 @@ func (p *Parser) parseValue(item lexer.Item) {
|
||||||
// Is called after '[' and ',' tokens
|
// Is called after '[' and ',' tokens
|
||||||
// Expects a value followed by ']' or ',' tokens
|
// Expects a value followed by ']' or ',' tokens
|
||||||
func (p *Parser) parseArray(i int64) {
|
func (p *Parser) parseArray(i int64) {
|
||||||
p.ctx.setIndex(i)
|
|
||||||
item := p.next()
|
item := p.next()
|
||||||
if item.Token == lexer.BracketClose {
|
if item.Token == lexer.BracketClose {
|
||||||
|
// Neither a bug nor a feature
|
||||||
|
// This allows an array to have a trailing comma
|
||||||
|
// [1, 2, 3, ]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.ctx.setIndex(i)
|
||||||
p.parseValue(item)
|
p.parseValue(item)
|
||||||
|
|
||||||
switch item := p.next(); item.Token {
|
switch item := p.next(); item.Token {
|
||||||
|
@ -90,6 +93,9 @@ func (p *Parser) parseObject() {
|
||||||
item := p.next()
|
item := p.next()
|
||||||
switch item.Token {
|
switch item.Token {
|
||||||
case lexer.BraceClose:
|
case lexer.BraceClose:
|
||||||
|
// Neither a bug nor a feature
|
||||||
|
// This allows an object to have a trailing comma
|
||||||
|
// {"foo": 1, "bar": 2, }
|
||||||
return
|
return
|
||||||
case lexer.String:
|
case lexer.String:
|
||||||
p.ctx.setKey(item.Val)
|
p.ctx.setKey(item.Val)
|
||||||
|
|
6
run.go
6
run.go
|
@ -12,7 +12,11 @@ func main() {
|
||||||
f, _ := os.Open("test.json")
|
f, _ := os.Open("test.json")
|
||||||
b, _ := ioutil.ReadAll(f)
|
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()
|
res := p.Parse()
|
||||||
pretty.Println(res)
|
pretty.Println(res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue