fix: disallow trailing comma in an inline table

This commit is contained in:
ToruNiina 2021-06-27 18:54:28 +09:00
parent cf9e86a84f
commit 0dc51f95d9

View File

@ -1497,17 +1497,18 @@ parse_inline_table(location& loc)
{{source_location(loc), "the next token is not an inline table"}}));
}
loc.advance();
// check if the inline table is an empty table = { }
maybe<lex_ws>::invoke(loc);
if(loc.iter() != loc.end() && *loc.iter() == '}')
{
loc.advance(); // skip `}`
return ok(std::make_pair(retval, region(loc, first, loc.iter())));
}
// it starts from "{". it should be formatted as inline-table
while(loc.iter() != loc.end())
{
maybe<lex_ws>::invoke(loc);
if(loc.iter() != loc.end() && *loc.iter() == '}')
{
loc.advance(); // skip `}`
return ok(std::make_pair(retval,
region(loc, first, loc.iter())));
}
const auto kv_r = parse_key_value_pair<value_type>(loc);
if(!kv_r)
{
@ -1563,6 +1564,18 @@ parse_inline_table(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);
throw syntax_error(format_underline("toml::parse_inline_table: "