mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-22 20:30:11 +00:00
fix: diagnose key after [table.key] pattern
the following is not a valid toml format. ``` [table] key = "value" ``` this commit enables to diagnose that pattern.
This commit is contained in:
parent
5a92932019
commit
0c9806e99f
@ -1289,6 +1289,20 @@ parse_table_key(location<Container>& loc)
|
||||
throw internal_error(format_underline("[error] "
|
||||
"toml::parse_table_key: no `]`", inner_loc, "should be `]`"));
|
||||
}
|
||||
|
||||
// after [table.key], newline or EOF(empty table) requried.
|
||||
if(loc.iter() != loc.end())
|
||||
{
|
||||
using lex_newline_after_table_key =
|
||||
sequence<maybe<lex_ws>, maybe<lex_comment>, lex_newline>;
|
||||
const auto nl = lex_newline_after_table_key::invoke(loc);
|
||||
if(!nl)
|
||||
{
|
||||
throw syntax_error(format_underline("[error] "
|
||||
"toml::parse_table_key: newline required after [table.key]",
|
||||
loc, "expected newline"));
|
||||
}
|
||||
}
|
||||
return ok(std::make_pair(keys.unwrap().first, token.unwrap()));
|
||||
}
|
||||
else
|
||||
@ -1327,6 +1341,20 @@ parse_array_table_key(location<Container>& loc)
|
||||
throw internal_error(format_underline("[error] "
|
||||
"toml::parse_table_key: no `]]`", inner_loc, "should be `]]`"));
|
||||
}
|
||||
|
||||
// after [[table.key]], newline or EOF(empty table) requried.
|
||||
if(loc.iter() != loc.end())
|
||||
{
|
||||
using lex_newline_after_table_key =
|
||||
sequence<maybe<lex_ws>, maybe<lex_comment>, lex_newline>;
|
||||
const auto nl = lex_newline_after_table_key::invoke(loc);
|
||||
if(!nl)
|
||||
{
|
||||
throw syntax_error(format_underline("[error] "
|
||||
"toml::parse_array_table_key: newline required after "
|
||||
"[[table.key]]", loc, "expected newline"));
|
||||
}
|
||||
}
|
||||
return ok(std::make_pair(keys.unwrap().first, token.unwrap()));
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user