mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
Merge branch 'master' into string-view
This commit is contained in:
12
README.md
12
README.md
@@ -609,9 +609,11 @@ toml::value operator""_toml(const char* str, std::size_t len);
|
||||
Access to the operator can be gained with `using namespace toml::literals;`,
|
||||
`using namespace toml::toml_literals`, and `using namespace toml::literals::toml_literals`.
|
||||
|
||||
Note that since it allows a bare value without a key, it is difficult to distinguish
|
||||
arrays and table definitions.
|
||||
Currently, it parses `[1]` as a table definition if there are no commas.
|
||||
Note that a key that is composed only of digits is allowed in TOML.
|
||||
And, unlike the file parser, toml-literal allows a bare value without a key.
|
||||
Thus it is difficult to distinguish arrays having integers and definitions of
|
||||
tables that are named as digits.
|
||||
Currently, literal `[1]` becomes a table named "1".
|
||||
To ensure a literal to be considered as an array with one element, you need to
|
||||
add a comma after the first element (like `[1,]`).
|
||||
|
||||
@@ -621,8 +623,8 @@ add a comma after the first element (like `[1,]`).
|
||||
"[[1,2,3]]"_toml; // This is an array of arrays
|
||||
"[[table]]"_toml; // This is a table that has an array of tables inside.
|
||||
|
||||
"[[1]]"_toml; // This is ambiguous.
|
||||
// Currently, it becomes a table taht has array of table "1".
|
||||
"[[1]]"_toml; // This literal is ambiguous.
|
||||
// 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 an array of arrays.
|
||||
"[[1],]"_toml; // ditto.
|
||||
|
@@ -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))
|
||||
{
|
||||
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()),
|
||||
::toml::detail::region<std::vector<char>>(std::move(loc)));
|
||||
}
|
||||
|
@@ -1406,10 +1406,16 @@ parse_inline_table(location<Container>& loc)
|
||||
return ok(std::make_pair(
|
||||
retval, region<Container>(loc, first, loc.iter())));
|
||||
}
|
||||
else if(*loc.iter() == '#' || *loc.iter() == '\r' || *loc.iter() == '\n')
|
||||
{
|
||||
throw syntax_error(format_underline("[error] "
|
||||
"toml::parse_inline_table: missing curly brace `}`",
|
||||
{{std::addressof(loc), "should be `}`"}}));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw syntax_error(format_underline("[error] "
|
||||
"toml:::parse_inline_table: missing table separator `,` ",
|
||||
"toml::parse_inline_table: missing table separator `,` ",
|
||||
{{std::addressof(loc), "should be `,`"}}));
|
||||
}
|
||||
}
|
||||
|
@@ -343,7 +343,8 @@ inline std::string format_underline(const std::string& message,
|
||||
{
|
||||
// invalid
|
||||
// ~~~~~~~
|
||||
retval << make_string(reg->size(), '~');
|
||||
const auto underline_len = std::min(reg->size(), reg->line().size());
|
||||
retval << make_string(underline_len, '~');
|
||||
}
|
||||
|
||||
retval << ' ';
|
||||
|
Reference in New Issue
Block a user