From 3c3ebd88b4d73d220eea18a2a00fcd93782e8611 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 9 Aug 2020 18:38:50 +0900 Subject: [PATCH] feat: improve error message about invalid keys --- toml/parser.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 86c920b..93b96ce 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -879,7 +879,8 @@ inline result, 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(); @@ -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(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