refactor: generate error message in parser

This commit is contained in:
ToruNiina
2019-04-18 15:09:58 +09:00
parent 0f48852730
commit 637c99d637

View File

@@ -326,7 +326,7 @@ result<std::string, std::string> parse_escape_sequence(location<Container>& loc)
{ {
return err(format_underline("[error] parse_escape_sequence: " return err(format_underline("[error] parse_escape_sequence: "
"invalid token found in UTF-8 codepoint uXXXX.", "invalid token found in UTF-8 codepoint uXXXX.",
{{std::addressof(loc), token.unwrap_err()}})); {{std::addressof(loc), "here"}}));
} }
} }
case 'U': case 'U':
@@ -339,7 +339,7 @@ result<std::string, std::string> parse_escape_sequence(location<Container>& loc)
{ {
return err(format_underline("[error] parse_escape_sequence: " return err(format_underline("[error] parse_escape_sequence: "
"invalid token found in UTF-8 codepoint Uxxxxxxxx", "invalid token found in UTF-8 codepoint Uxxxxxxxx",
{{std::addressof(loc), token.unwrap_err()}})); {{std::addressof(loc), "here"}}));
} }
} }
} }
@@ -406,7 +406,9 @@ parse_ml_basic_string(location<Container>& loc)
else else
{ {
loc.reset(first); loc.reset(first);
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_ml_basic_string: "
"the next token is not a multiline string",
{{std::addressof(loc), "here"}}));
} }
} }
@@ -455,7 +457,9 @@ parse_basic_string(location<Container>& loc)
else else
{ {
loc.reset(first); // rollback loc.reset(first); // rollback
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_basic_string: "
"the next token is not a string",
{{std::addressof(loc), "here"}}));
} }
} }
@@ -494,7 +498,9 @@ parse_ml_literal_string(location<Container>& loc)
else else
{ {
loc.reset(first); // rollback loc.reset(first); // rollback
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_ml_literal_string: "
"the next token is not a multiline literal string",
{{std::addressof(loc), "here"}}));
} }
} }
@@ -531,7 +537,9 @@ parse_literal_string(location<Container>& loc)
else else
{ {
loc.reset(first); // rollback loc.reset(first); // rollback
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_literal_string: "
"the next token is not a literal string",
{{std::addressof(loc), "here"}}));
} }
} }
@@ -1537,7 +1545,8 @@ parse_table_key(location<Container>& loc)
} }
else else
{ {
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_table_key: "
"not a valid table key", {{std::addressof(loc), "here"}}));
} }
} }
@@ -1545,7 +1554,7 @@ template<typename Container>
result<std::pair<std::vector<key>, region<Container>>, std::string> result<std::pair<std::vector<key>, region<Container>>, std::string>
parse_array_table_key(location<Container>& loc) parse_array_table_key(location<Container>& loc)
{ {
if(auto token = lex_array_table::invoke(loc)) if(auto token = lex_array_table::invoke(loc, true))
{ {
location<std::string> inner_loc(loc.name(), token.unwrap().str()); location<std::string> inner_loc(loc.name(), token.unwrap().str());
@@ -1590,7 +1599,8 @@ parse_array_table_key(location<Container>& loc)
} }
else else
{ {
return err(token.unwrap_err()); return err(format_underline("[error] toml::parse_array_table_key: "
"not a valid table key", {{std::addressof(loc), "here"}}));
} }
} }