mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
fix: disallow trailing comma in an inline table
This commit is contained in:
@@ -1497,17 +1497,18 @@ parse_inline_table(location& loc)
|
|||||||
{{source_location(loc), "the next token is not an inline table"}}));
|
{{source_location(loc), "the next token is not an inline table"}}));
|
||||||
}
|
}
|
||||||
loc.advance();
|
loc.advance();
|
||||||
// it starts from "{". it should be formatted as inline-table
|
|
||||||
while(loc.iter() != loc.end())
|
// check if the inline table is an empty table = { }
|
||||||
{
|
|
||||||
maybe<lex_ws>::invoke(loc);
|
maybe<lex_ws>::invoke(loc);
|
||||||
if(loc.iter() != loc.end() && *loc.iter() == '}')
|
if(loc.iter() != loc.end() && *loc.iter() == '}')
|
||||||
{
|
{
|
||||||
loc.advance(); // skip `}`
|
loc.advance(); // skip `}`
|
||||||
return ok(std::make_pair(retval,
|
return ok(std::make_pair(retval, region(loc, first, loc.iter())));
|
||||||
region(loc, first, loc.iter())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// it starts from "{". it should be formatted as inline-table
|
||||||
|
while(loc.iter() != loc.end())
|
||||||
|
{
|
||||||
const auto kv_r = parse_key_value_pair<value_type>(loc);
|
const auto kv_r = parse_key_value_pair<value_type>(loc);
|
||||||
if(!kv_r)
|
if(!kv_r)
|
||||||
{
|
{
|
||||||
@@ -1563,6 +1564,18 @@ parse_inline_table(location& loc)
|
|||||||
source_location(loc));
|
source_location(loc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else // `,` is found
|
||||||
|
{
|
||||||
|
maybe<lex_ws>::invoke(loc);
|
||||||
|
if(loc.iter() != loc.end() && *loc.iter() == '}')
|
||||||
|
{
|
||||||
|
throw syntax_error(format_underline(
|
||||||
|
"toml::parse_inline_table: trailing comma is not allowed in"
|
||||||
|
" an inline table",
|
||||||
|
{{source_location(loc), "should be `}`"}}),
|
||||||
|
source_location(loc));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loc.reset(first);
|
loc.reset(first);
|
||||||
throw syntax_error(format_underline("toml::parse_inline_table: "
|
throw syntax_error(format_underline("toml::parse_inline_table: "
|
||||||
|
Reference in New Issue
Block a user