Compare commits

..

4 Commits

Author SHA1 Message Date
ToruNiina
6185dfee14 chore: fix typo in README 2019-04-23 23:31:37 +09:00
Toru Niina
a74ad23514 Merge pull request #58 from ToruNiina/improve-err-msg-literal
Improve error message from toml literal
2019-04-22 20:50:11 +09:00
ToruNiina
2d9b4992ec fix: restrict length of underline by size of line
in some cases, `region` contains several lines and `region::size`
returns the whole size that is a sum of lengthes of all the lines.
To avoid too long underlines, restrict the length of underline by
the length of the line that is shown in the message.
2019-04-21 16:38:08 +09:00
ToruNiina
82e8c1e68b fix: skip first ws/newlines in toml literal
when ""_toml literal is used with C++11 raw-string literal,
it normally starts with newline like the following.
```cpp
const auto v = u8R"(
    [table]
    key = "value"
    )"_toml;
```
With this, the error message shows the first empty line that starts just
after `u8R"(` and thus the error message shows nothing. To avoid this,
skip the first empty lines and whitespaces in literal.
2019-04-21 16:31:24 +09:00
3 changed files with 6 additions and 2 deletions

View File

@@ -618,7 +618,7 @@ add a comma after the first element (like `[1,]`).
"[[table]]"_toml; // This is a table that has an array of tables inside. "[[table]]"_toml; // This is a table that has an array of tables inside.
"[[1]]"_toml; // This literal is ambiguous. "[[1]]"_toml; // This literal is ambiguous.
// Currently, it becomes a table taht has array of table "1". // Currently, it becomes a table that has array of table "1".
"1 = [{}]"_toml; // This is a table that has an array of table named 1. "1 = [{}]"_toml; // This is a table that has an array of table named 1.
"[[1,]]"_toml; // This is an array of arrays. "[[1,]]"_toml; // This is an array of arrays.
"[[1],]"_toml; // ditto. "[[1],]"_toml; // ditto.

View File

@@ -73,6 +73,9 @@ inline ::toml::value operator""_toml(const char* str, std::size_t len)
if(auto data = ::toml::detail::parse_toml_file(loc)) if(auto data = ::toml::detail::parse_toml_file(loc))
{ {
loc.reset(loc.begin()); // rollback to the top of the literal loc.reset(loc.begin()); // rollback to the top of the literal
// skip needless characters for error message
skip_line::invoke(loc); // skip the first several needless lines
skip_ws::invoke(loc); // skip the first several needless whitespaces
return ::toml::value(std::move(data.unwrap()), return ::toml::value(std::move(data.unwrap()),
::toml::detail::region<std::vector<char>>(std::move(loc))); ::toml::detail::region<std::vector<char>>(std::move(loc)));
} }

View File

@@ -343,7 +343,8 @@ inline std::string format_underline(const std::string& message,
{ {
// invalid // invalid
// ~~~~~~~ // ~~~~~~~
retval << make_string(reg->size(), '~'); const auto underline_len = std::min(reg->size(), reg->line().size());
retval << make_string(underline_len, '~');
} }
retval << ' '; retval << ' ';