toml: support checking and decoding quoted keys (#12552)
parent
0779b5fd8e
commit
1be6aed16e
|
@ -366,7 +366,7 @@ fn (c Checker) check_time(t ast.Time) ? {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check_quoted returns an error if `q` is not a valid quoted TOML string.
|
// check_quoted returns an error if `q` is not a valid quoted TOML string.
|
||||||
fn (c Checker) check_quoted(q ast.Quoted) ? {
|
pub fn (c Checker) check_quoted(q ast.Quoted) ? {
|
||||||
lit := q.text
|
lit := q.text
|
||||||
quote := q.quote.ascii_str()
|
quote := q.quote.ascii_str()
|
||||||
triple_quote := quote + quote + quote
|
triple_quote := quote + quote + quote
|
||||||
|
|
|
@ -1061,16 +1061,25 @@ pub fn (mut p Parser) key() ?ast.Key {
|
||||||
' key expected .bare, .underscore, .number, .quoted or .boolean but got "$p.tok.kind"')
|
' key expected .bare, .underscore, .number, .quoted or .boolean but got "$p.tok.kind"')
|
||||||
}
|
}
|
||||||
|
|
||||||
// A small exception that can't easily be done via `checker`
|
// A few small exceptions that can't easily be done via `checker` or `decoder` *after* the
|
||||||
// since the `is_multiline` information is lost when using the key.text as a
|
// main table has been build since information like `is_multiline` is lost when using the key.text as a
|
||||||
// V `map` key directly.
|
// V `map` key directly.
|
||||||
if p.config.run_checks {
|
if key is ast.Quoted {
|
||||||
if key is ast.Quoted {
|
if p.config.run_checks {
|
||||||
quoted := key as ast.Quoted
|
quoted := key as ast.Quoted
|
||||||
if quoted.is_multiline {
|
if quoted.is_multiline {
|
||||||
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
return error(@MOD + '.' + @STRUCT + '.' + @FN +
|
||||||
' multiline string as key is not allowed. (excerpt): "...${p.excerpt()}..."')
|
' multiline string as key is not allowed. (excerpt): "...${p.excerpt()}..."')
|
||||||
}
|
}
|
||||||
|
chckr := checker.Checker{
|
||||||
|
scanner: p.scanner
|
||||||
|
}
|
||||||
|
chckr.check_quoted(quoted) ?
|
||||||
|
}
|
||||||
|
if p.config.decode_values {
|
||||||
|
mut quoted := key as ast.Quoted
|
||||||
|
decoder.decode_quoted_escapes(mut quoted) ?
|
||||||
|
key = ast.Key(quoted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,6 @@ const (
|
||||||
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
|
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
|
||||||
// Date-time
|
// Date-time
|
||||||
'datetime/milliseconds.toml',
|
'datetime/milliseconds.toml',
|
||||||
// Key
|
|
||||||
'key/escapes.toml',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
jq = os.find_abs_path_of_executable('jq') or { '' }
|
jq = os.find_abs_path_of_executable('jq') or { '' }
|
||||||
|
|
Loading…
Reference in New Issue