Skip to content

Commit

Permalink
feat: improve error message about invalid keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ToruNiina committed Aug 9, 2020
1 parent 08f7ea9 commit 3c3ebd8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions toml/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ inline result<std::pair<std::vector<key>, region>, std::string>
parse_key(location& loc)
{
const auto first = loc.iter();
// dotted key -> foo.bar.baz whitespaces are allowed
// dotted key -> `foo.bar.baz` where several single keys are chained by
// dots. Whitespaces between keys and dots are allowed.
if(const auto token = lex_dotted_key::invoke(loc))
{
const auto reg = token.unwrap();
Expand Down Expand Up @@ -922,14 +923,18 @@ parse_key(location& loc)
}
loc.reset(first);

// simple key -> foo
// simple_key: a single (basic_string|literal_string|bare key)
if(const auto smpl = parse_simple_key(loc))
{
return ok(std::make_pair(std::vector<key>(1, smpl.unwrap().first),
smpl.unwrap().second));
}
return err(format_underline("toml::parse_key: ",
{{source_location(loc), "is not a valid key"}}));
return err(format_underline("toml::parse_key: an invalid key appeaed.",
{{source_location(loc), "is not a valid key"}}, {
"bare keys : non-empty strings composed only of [A-Za-z0-9_-].",
"quoted keys: same as \"basic strings\" or 'literal strings'.",
"dotted keys: sequence of bare or quoted keys joined with a dot."
}));
}

// forward-decl to implement parse_array and parse_table
Expand Down

0 comments on commit 3c3ebd8

Please sign in to comment.