Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -598,10 +598,16 @@ func (p *parser) readEscape() (rune, error) {
|
||||
return '\f', nil
|
||||
case 'r':
|
||||
return '\r', nil
|
||||
case 'e':
|
||||
// TOML 1.1: the escape character.
|
||||
return '\x1b', nil
|
||||
case '"':
|
||||
return '"', nil
|
||||
case '\\':
|
||||
return '\\', nil
|
||||
case 'x':
|
||||
// TOML 1.1: two hex digits, code points 0x00 through 0xFF.
|
||||
return p.readUnicode(2)
|
||||
case 'u':
|
||||
return p.readUnicode(4)
|
||||
case 'U':
|
||||
@@ -633,7 +639,7 @@ func (p *parser) parseArray() (any, error) {
|
||||
p.next() // '['
|
||||
arr := []any{}
|
||||
for {
|
||||
if err := p.skipArraySpace(); err != nil {
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.eof() {
|
||||
@@ -648,7 +654,7 @@ func (p *parser) parseArray() (any, error) {
|
||||
return nil, err
|
||||
}
|
||||
arr = append(arr, v)
|
||||
if err := p.skipArraySpace(); err != nil {
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.eof() {
|
||||
@@ -670,13 +676,20 @@ func (p *parser) parseInlineTable() (any, error) {
|
||||
p.next() // '{'
|
||||
tbl := map[string]any{}
|
||||
assigned := map[string]bool{}
|
||||
p.skipInline()
|
||||
// TOML 1.1 lets an inline table span lines: interior whitespace includes
|
||||
// newlines and comments, and a trailing comma is allowed before the
|
||||
// closing brace.
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !p.eof() && p.peek() == '}' {
|
||||
p.next()
|
||||
return tbl, nil
|
||||
}
|
||||
for {
|
||||
p.skipInline()
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
key, err := p.parseKeyPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -720,13 +733,22 @@ func (p *parser) parseInlineTable() (any, error) {
|
||||
dest[leaf] = val
|
||||
assigned[pathKey(path)] = true
|
||||
|
||||
p.skipInline()
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.eof() {
|
||||
return nil, p.errf("unterminated inline table")
|
||||
}
|
||||
switch p.peek() {
|
||||
case ',':
|
||||
p.next()
|
||||
if err := p.skipNestedSpace(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !p.eof() && p.peek() == '}' {
|
||||
p.next()
|
||||
return tbl, nil
|
||||
}
|
||||
case '}':
|
||||
p.next()
|
||||
return tbl, nil
|
||||
@@ -796,8 +818,9 @@ func (p *parser) skipInline() {
|
||||
}
|
||||
}
|
||||
|
||||
// skipArraySpace consumes whitespace, newlines, and comments inside arrays.
|
||||
func (p *parser) skipArraySpace() error {
|
||||
// skipNestedSpace consumes whitespace, newlines, and comments inside a value
|
||||
// container (an array, or an inline table under TOML 1.1).
|
||||
func (p *parser) skipNestedSpace() error {
|
||||
for !p.eof() {
|
||||
switch p.peek() {
|
||||
case ' ', '\t':
|
||||
|
||||
Reference in New Issue
Block a user