Allow tailing comma

pull/268/head
Anton Medvedev 9 months ago
parent 7823372211
commit 6d63085b0d
No known key found for this signature in database

@ -213,6 +213,17 @@ func (p *jsonParser) parseObject() *node {
p.skipWhitespace()
if p.lastChar == ',' {
object.end.comma = true
p.next()
p.skipWhitespace()
if p.lastChar == '}' {
object.end.comma = false
} else {
continue
}
}
if p.lastChar == '}' {
closeBracket := &node{depth: p.depth}
closeBracket.value = []byte{'}'}
@ -223,13 +234,6 @@ func (p *jsonParser) parseObject() *node {
return object
}
if p.lastChar == ',' {
object.end.comma = true
p.next()
p.skipWhitespace()
continue
}
panic(fmt.Sprintf("Unexpected character %q in object", p.lastChar))
}
}
@ -237,21 +241,37 @@ func (p *jsonParser) parseObject() *node {
func (p *jsonParser) parseArray() *node {
arr := &node{depth: p.depth}
arr.value = []byte{'['}
p.next()
p.skipWhitespace()
if p.lastChar == ']' {
arr.value = append(arr.value, ']')
p.next()
return arr
}
for i := 0; ; i++ {
p.depth++
value := p.parseValue()
value.directParent = arr
value.index = i
p.depth--
arr.append(value)
p.skipWhitespace()
if p.lastChar == ',' {
arr.end.comma = true
p.next()
p.skipWhitespace()
if p.lastChar == ']' {
arr.end.comma = false
} else {
continue
}
}
if p.lastChar == ']' {
closeBracket := &node{depth: p.depth}
closeBracket.value = []byte{']'}
@ -260,14 +280,9 @@ func (p *jsonParser) parseArray() *node {
arr.append(closeBracket)
p.next()
return arr
} else if p.lastChar == ',' {
arr.end.comma = true
p.next()
p.skipWhitespace()
continue
} else {
panic(fmt.Sprintf("Invalid character %q in array", p.lastChar))
}
panic(fmt.Sprintf("Invalid character %q in array", p.lastChar))
}
}

@ -31,7 +31,10 @@ func init() {
if !ok {
themeId = "1"
}
currentTheme = themes[themeId]
currentTheme, ok = themes[themeId]
if !ok {
currentTheme = themes["1"]
}
if termenv.ColorProfile() == termenv.Ascii {
currentTheme = themes["0"]
}

Loading…
Cancel
Save