mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08: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:
@@ -1289,6 +1289,20 @@ parse_table_key(location<Container>& loc)
|
|||||||
throw internal_error(format_underline("[error] "
|
throw internal_error(format_underline("[error] "
|
||||||
"toml::parse_table_key: no `]`", inner_loc, "should be `]`"));
|
"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()));
|
return ok(std::make_pair(keys.unwrap().first, token.unwrap()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1327,6 +1341,20 @@ parse_array_table_key(location<Container>& loc)
|
|||||||
throw internal_error(format_underline("[error] "
|
throw internal_error(format_underline("[error] "
|
||||||
"toml::parse_table_key: no `]]`", inner_loc, "should be `]]`"));
|
"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()));
|
return ok(std::make_pair(keys.unwrap().first, token.unwrap()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user