Commit Graph

566 Commits

Author SHA1 Message Date
ToruNiina
407d9223f6 feat: 💥 is_float -> is_floating 2019-06-03 22:01:47 +09:00
ToruNiina
d7c5606dcf fix: update as_float -> floating 2019-06-03 21:46:48 +09:00
ToruNiina
ae2bafa907 fix: correct SFINAE conditions and types 2019-06-03 21:44:11 +09:00
ToruNiina
f19b3822bb feat: 💥 change as_float -> as_floating 2019-06-03 21:43:35 +09:00
ToruNiina
a19b94511b fix: add space between operator"" and _toml
In C++11, it is required.
2019-06-03 20:58:35 +09:00
ToruNiina
fe8a909213 fix: correctly put references 2019-06-02 22:09:26 +09:00
ToruNiina
5fe166e375 fix: update value_t::* names in serializer
Although currently serializer does not support basic_value, it compiles.
2019-06-02 21:51:37 +09:00
ToruNiina
319365f86b feat: update types in format_error 2019-06-02 21:50:27 +09:00
ToruNiina
89f0ace6ee fix: initialize comment container correctly 2019-06-02 21:50:01 +09:00
ToruNiina
2e34035e7a feat: 💥 update types and retval of parser
- change return value from toml::table to toml::value
- enable to change container types and comment policy by template
2019-06-02 21:47:57 +09:00
ToruNiina
e094d6e85a refactor: move type alias from get to trait 2019-06-02 20:43:08 +09:00
ToruNiina
4664f91517 feat: remove unused meta-function alias 2019-06-02 20:40:44 +09:00
ToruNiina
c0b6ca762a feat: 💥 drop from_toml support 2019-06-02 19:27:03 +09:00
ToruNiina
5ef9890d0c feat: update find_or for basic_value 2019-06-02 19:22:17 +09:00
ToruNiina
bda337b51f feat: support conversion between basic_values 2019-06-02 19:09:56 +09:00
ToruNiina
6569c26e1b feat: make SFINAE condition strict 2019-06-02 19:04:32 +09:00
ToruNiina
6d17d5f60f feat: update expect for basic_value 2019-06-02 19:02:25 +09:00
ToruNiina
c00eeb18ef feat: add meta function that detects toml::basic_value 2019-06-02 19:02:01 +09:00
ToruNiina
3ce1aa31f3 feat: update get_or for basic_value 2019-06-02 18:55:02 +09:00
ToruNiina
cf28c3fb95 feat: update toml::find for basic_value 2019-06-02 18:36:49 +09:00
ToruNiina
6de494598a fix: remove unused argument to suppress warnings 2019-06-02 18:32:47 +09:00
ToruNiina
b06ae03deb feat: update toml::get<T> for basic_value 2019-06-02 17:53:08 +09:00
ToruNiina
725d915ba9 feat(WIP): update toml::get 2019-06-02 17:31:49 +09:00
ToruNiina
e1556183d1 refactor: remove unused include files 2019-06-02 17:12:01 +09:00
ToruNiina
9676499ab5 refactor: move file inclusion to correct position 2019-06-02 15:29:34 +09:00
ToruNiina
5792411d5e feat: add default template argument to basic_value 2019-06-02 15:15:43 +09:00
ToruNiina
44184026f9 feat: enable to convert different basic_values 2019-06-02 00:13:12 +09:00
ToruNiina
898423166f feat: enable to convert preserve/discard comments 2019-06-02 00:02:31 +09:00
ToruNiina
f9b5166c09 refactor: move default value types to value.hpp 2019-06-01 23:58:17 +09:00
ToruNiina
5c5d8b686a feat: introduce basic_value
it is capable to change comment policy, backend container of an array
and a table.
2019-06-01 20:18:57 +09:00
ToruNiina
5c3c1bd0e7 feat: add missing default array/table type 2019-06-01 20:18:15 +09:00
ToruNiina
696e5bb66f feat: extend has_from_toml_method to be generic 2019-06-01 20:16:59 +09:00
ToruNiina
65540fbb5c fix: typos 2019-06-01 19:47:10 +09:00
ToruNiina
351320491d fix: fix has_from_toml using basic_value 2019-06-01 19:46:20 +09:00
ToruNiina
d30700517d fix: add missing include file 2019-06-01 19:43:35 +09:00
ToruNiina
14ad8d0556 fix: fix typos and invalid names 2019-06-01 19:43:15 +09:00
ToruNiina
f04c97b587 refactor: simplify format_underline a bit 2019-06-01 19:06:08 +09:00
ToruNiina
b8d3038d38 feat: add meta function to detect conversions 2019-06-01 16:03:26 +09:00
ToruNiina
eaa3604dce refactor: introduce value_t_constant
as an alias for integral_constant
2019-06-01 16:01:48 +09:00
ToruNiina
8acc348106 feat: 💥 change interface around types
- change value_t::typename from CamelCase to snake_case.
- drop CamelCase typename supports.
The changes are introduced to make the interfaces uniform. For some
(historical) reasons, toml11 has both CamelCase names and snake_case
names for types. Additionally, since `float` is a keyword, snake_case
names uses `floating` to avoid collision and CamelCase name uses `Float`
because toml official calls it `Float`. This is too confusing.
Since it is a major upgrade, I think it is a big chance to make them
uniform.
2019-06-01 13:33:57 +09:00
ToruNiina
2567f2a787 feat: add source_location for error message generation. 2019-06-01 13:25:02 +09:00
ToruNiina
84b5749c6b feat: implement comment containers 2019-06-01 13:24:54 +09:00
ToruNiina
70d0049511 refactor: move some meta-funcs to traits.hpp 2019-06-01 12:35:40 +09:00
ToruNiina
717f5929c2 feat: use detail::none_t instead of char
Although the error value from combinators currently does not have any
information, it can have an information because it is a char value. It
is better to use no-information-type explicitly to make it clear that
it does not have any information. So I added none_t in toml::detai and
use it in combinators and parsers as an error value from combinators.
2019-05-31 17:07:52 +09:00
ToruNiina
81abb6c9d7 perf: remove err-msg from combinator
Generate error message in `parse_something()`, not in `lex_something`.
Since the error message generated by `lex_something` is too difficult to
read for humans, I've disabled the error message generation for the sake
of efficiency (it takes time to generate error message that will never
be read). I think now the error message generation itself safely can be
removed from combinators. At this stage, `lex_something` does not need
to return `result<T, E>` because all the error type would be discarded.
Now it is turned out that returing `optional<T>` from lex_* is enough.
Maybe later I would change the return type itself, but currently I
changed the error type from std::string to char because implementing
optional takes time and effort. It makes the parsing process a bit
faster.
2019-05-30 20:08:37 +09:00
ToruNiina
8bba3c8a14 refactor: use literal instead of empty string
so far, the error value of the lexer is just ignored because they are
not readable (results from all the nested combinator are concatenated,
so they are too redundant). those ones are replaced by a simple literal.
2019-05-30 19:33:25 +09:00
ToruNiina
b13e727b90 refactor: remove unused func, combinator::pattern
because it is not human-readable (too long and redundant)
2019-05-30 18:05:47 +09:00
ToruNiina
d352c9e66f perf: suppress unused error message generation 2019-05-30 17:47:06 +09:00
ToruNiina
1633268d57 refactor: use snake_case typename only 2019-05-30 14:39:15 +09:00
ToruNiina
4dbd2cb9fe refactor: use as_* to avoid needless checking 2019-05-29 21:22:32 +09:00
ToruNiina
65124a8d2e refactor: use is_something instead of is(...)
to reduce the code size a bit
2019-05-29 21:20:22 +09:00
ToruNiina
1b78f161f5 refactor: use is_something/as_something in parser
this reduces the size of the code. And also it skips needless
double-checking, so we can expect it makes parsing a bit faster.
2019-05-29 21:18:17 +09:00
ToruNiina
0ce259ada0 refactor: split throw_bad_cast from value::cast 2019-05-29 21:06:25 +09:00
ToruNiina
74da49f87f refactor: move switch_cast from inside of value
use as_something() instead of it. To realize this, the implementation of
as_something() is also changed. Now as_something does not depends on
`cast`. This reduces complexity around casting toml::value to other types.
2019-05-29 20:18:15 +09:00
Ivan Shynkarenka
db6f3d5d11 Fix Visual Studio 2019 warnings in pedantic compilation mode (/W4 /WX) 2019-05-10 14:58:22 +03:00
ToruNiina
87be890e07 feat: remove deprecated functions 2019-04-28 15:59:09 +09:00
ToruNiina
4cbbcd8f62 Merge branch 'master' into as-something 2019-04-27 19:04:44 +09:00
Toru Niina
a2631ecacb
Merge pull request #60 from ToruNiina/string-view
support std::string_view
2019-04-27 18:33:59 +09:00
ToruNiina
4bcc5e8375 Merge branch 'master' into as-something 2019-04-27 17:42:12 +09:00
ToruNiina
aa7b9a3965 refactor: rename as_floating -> as_float
Actually, since `floating` is used for toml::types, `as_floating`
seems to be clearer. But currently `is_*` functions uses `float`,
not `floating`, so `as_float` is chosen for the consistency.
In a future release, possibly v3, those names may need to be
re-considered for clarity.
2019-04-27 16:45:25 +09:00
ToruNiina
0d623856a7 feat: add value::as_something() for convenience 2019-04-27 16:22:23 +09:00
ToruNiina
01aa2ef5b2 feat: add ctor to value to init with string_view 2019-04-26 16:33:09 +09:00
ToruNiina
e460826084 feat: enable to get a comment related to a value
- comment_before(): get comments just before a value.
- comment_inline(): get a comment in the same line as a value.
- comment(): get comment_before() + comment_inline().
2019-04-25 22:32:39 +09:00
ToruNiina
aa3445f38c feat: add functions to get comments around region 2019-04-25 22:32:18 +09:00
ToruNiina
408b7bf35e Merge branch 'master' into string-view 2019-04-23 23:32:08 +09:00
ToruNiina
d061c33a16 feat: enable toml::get with std::string_view 2019-04-23 23:24:23 +09:00
ToruNiina
0c7d2d07d4 feat: do not consider string_view as a container
it is a kind of string.
2019-04-23 23:23:57 +09:00
ToruNiina
62cf4373bd feat: conversion toml::string <-> string_view 2019-04-22 23:18:05 +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
ToruNiina
46be054ce9 fix: improve err msg for multiline inline table
show "missing curly brace" instead of "missing table key-value separator"
2019-04-19 13:22:13 +09:00
ToruNiina
637c99d637 refactor: generate error message in parser 2019-04-18 15:09:58 +09:00
ToruNiina
0f48852730 perf: check value type before parsing
to avoid needless error message generation
2019-04-18 14:26:27 +09:00
ToruNiina
0499b2907d Merge branch 'master' into optimization 2019-04-18 14:10:08 +09:00
ToruNiina
61e69c9251 fix: count line number from 1, not 0 2019-04-18 13:56:19 +09:00
ToruNiina
4a560ea1e5 fix: show correct error message 2019-04-18 00:04:33 +09:00
ToruNiina
c5b6ee6f81 feat: add yet another constructor to value
to make implementation of parse_value easier
2019-04-17 23:43:42 +09:00
ToruNiina
1a7bf63622 Merge branch 'master' into optimization 2019-04-17 14:58:28 +09:00
ToruNiina
c82e76a111 perf: check string type before parsing it
to avoid unncessary error message generation, check the first some
characters before parsing it. It makes parsing process faster and
is also helpful to generate more accurate error messages.
2019-04-16 21:47:24 +09:00
ToruNiina
4db486d76d perf: check integer prefix before trying to parse
all the parsers generate error messages and error message generation is
not a lightweight task. It concatenates a lot of strings, it formats
many values, etc. To avoid useless error-message generation, first check
which prefix is used and then parse special integers. Additionally, by
checking that, the quality of the error message can be improved (later).
2019-04-16 21:37:12 +09:00
ToruNiina
91966a6917 perf: do not use concat_string if it is not needed
At the earlier stage of the development, I thought that it is useful if
lexer-combinators generate error messages, because by doing this,
parser would not need to generate an error message. But now it turned
out that to show an appropriate error message, parser need to generate
according to the context. And almost all the messages from lexer are
discarded. So I added another parameter to lexer-combinator to suppress
error message generation. In the future, we may want to remove messages
completely from lexers, but currently I will keep it. Removing those
unused message generation makes the parsing process faster.
2019-04-16 21:09:59 +09:00
ToruNiina
b3917aaadf refactor: use snprintf to show char in hex
instead of std::ostringstream.
2019-04-16 20:54:29 +09:00
Petr Benes
ba307003c4 fix /W4 warnings on MSVC 2019-04-16 13:25:45 +02:00
ToruNiina
6c2a536fa5 fix: check literal has a table or an array first
The literal like this `"[[table]]"_toml` caused a syntax error. It is
because the literal parser first check that it might be a bare value
without a key, and parse_array directory throws syntax_error. This
change makes the parser first check a literal is a name of table, and
then parse the content.
2019-04-14 19:48:43 +09:00
ToruNiina
6f950c9ec8 perf: cache current line number in location
`location::line_num()` function used to be implemented by using
`std::count`, so each time the parser encounters a type mismatch,
`std::count` was called with almost whole file. It decelerates the
parsing process too much, so I decided to add `line_number_` member
variable to `location` and add `advance/retrace/reset` to `location`
in order to modify the position that is pointed.
2019-04-12 18:32:46 +09:00
ToruNiina
ea13e40889 feat: add static_assert for location/range
to check the container is randomly-accessible
2019-04-12 18:00:53 +09:00
ToruNiina
595fb1aef3 refactor: remove unused function parameter names 2019-04-06 19:39:13 +09:00
ToruNiina
5aebd6b562 fix: restore the back compat of format_error
the following code was okay in the last release
```
toml::format_error("[test]", v, "test", {"hint1", "hint2"})
```
but was not okay in the current master. This commit fixes this.

cons: By this, the number of values to show is limited upto 3.
2019-03-20 20:46:22 +09:00
ToruNiina
4c13085b35 fix: add stream operator for toml::table 2019-03-20 19:30:08 +09:00
Toru Niina
65b10b6537
Merge pull request #46 from ToruNiina/toml-literal
feat: add ""_toml literal
2019-03-20 10:12:56 +09:00
ToruNiina
20ba57e389 fix: add missing const specifier to some of get()s 2019-03-20 00:37:13 +09:00
ToruNiina
40ccf1d912 feat: add argument to control top-level inlinization 2019-03-19 23:25:26 +09:00
ToruNiina
982ae36428 feat: add ""_toml literal 2019-03-19 21:34:57 +09:00
ToruNiina
d6714ec450 feat: detect value type and format as a file
in toml::format
2019-03-19 21:24:51 +09:00
ToruNiina
7a0ecf977d feat: add find_or(table, key, fallback)
get_or(value, fallback) is still ok, but get_or(table, key, fallback)
is now deprecated.
2019-03-18 17:44:03 +09:00
ToruNiina
aade704411 refactor: remove needless overload of get_or 2019-03-18 17:10:18 +09:00
ToruNiina
ca3f6102ef fix: correctly resolve overloads of get_or 2019-03-18 16:44:36 +09:00
ToruNiina
4a58b629ce feat: add a way to check arg is "string literal" 2019-03-18 16:31:12 +09:00
ToruNiina
3adba237b8 feat: enable to show message for deprecated() 2019-03-18 16:28:27 +09:00
ToruNiina
f40fd12e25 refactor: add and rewrite comments 2019-03-18 11:09:12 +09:00
ToruNiina
65c2c3c238 fix: correctly deduce return value of visitor 2019-03-18 10:53:04 +09:00
ToruNiina
891a61a5e3 fix: do not move array element without checking 2019-03-18 02:05:55 +09:00
ToruNiina
243f43fafd Merge branch 'master' into hotfix 2019-03-17 21:16:37 +09:00
ToruNiina
66e27a94b6 fix: simplify and correct the format of timezone 2019-03-17 21:14:17 +09:00
Toru Niina
f3e3000d45
Merge pull request #40 from ToruNiina/remove-to-toml
refactor: remove to_toml and related tests
2019-03-17 13:12:30 +09:00
Toru Niina
f7380c6e32
Merge pull request #39 from ToruNiina/throw-incorrect-unicode
Throw syntax_error when parser encounter an incorrect utf-8 codepoint
2019-03-17 13:12:16 +09:00
Toru Niina
d86870e038
Merge pull request #38 from ToruNiina/get-any-type
extended conversions
2019-03-17 13:11:59 +09:00
Toru Niina
0908806915
Merge pull request #33 from ToruNiina/is-something
add `is_boolean` and other stuffs like that
2019-03-16 23:55:01 +09:00
ToruNiina
d17c192681 refactor: remove to_toml and related tests 2019-03-16 17:05:58 +09:00
ToruNiina
43014c6619 fix: remove redefined default template argument 2019-03-16 16:24:10 +09:00
ToruNiina
04bfeba3f2 merge branch master into get-any-type 2019-03-16 15:58:18 +09:00
ToruNiina
190636b791 fix: support getting a container of external types 2019-03-16 15:52:22 +09:00
ToruNiina
b1b72a94a8 feat: support conversion with external types 2019-03-16 14:44:04 +09:00
ToruNiina
6929bcdf78 feat: add from<T> and into<T> 2019-03-16 14:27:05 +09:00
ToruNiina
fd063af7ce refactor: make include guard style uniform 2019-03-16 14:19:47 +09:00
ToruNiina
df6dcbc4ed feat: check a class has from/into_toml member fn
to support better serialization
2019-03-16 14:16:31 +09:00
ToruNiina
9b8db6a225 fix: remove extraneous null character after float
the bug was introduced by snprintf
2019-03-15 19:30:36 +09:00
ToruNiina
76863cb27f refactor: simplify branches about utf8 codepoint 2019-03-15 17:48:47 +09:00
ToruNiina
514df99e40 feat: consider invalid UTF-8 as syntax_error
the following codepoints are considered to be a syntax_error
- [0xD800, 0xDFFF]
- larger than 0x10FFFF
2019-03-15 17:39:31 +09:00
ToruNiina
055353a460 chore: merge branch 'master' into is-something 2019-03-15 17:25:17 +09:00
ToruNiina
a04544637b feat: mark to_toml as deprecated
because the constructor of `toml::value()` supports all the stuff that
are supported by `to_toml`.
2019-03-15 14:29:32 +09:00
ToruNiina
61dfa4a2dc feat: format any number of values into an err msg
```cpp
toml::format_error("[error] message", v1, "v1", v2, "v2", ...);
```
2019-03-15 12:38:37 +09:00
ToruNiina
0babe8d589 fix: use format_underline for N regions everywhere 2019-03-14 00:59:10 +09:00
ToruNiina
5b2ce26721 refactor: remove redundant function
since N region format_underline() has been implemented, overloads for 1
and 2 region(s) are not needed.
2019-03-14 00:56:35 +09:00
ToruNiina
74ceceef73 fix: suppress warning about sign-unsign comparison
The solution is not ideal, but it's okay at the line
2019-03-13 14:03:04 +09:00
ToruNiina
46b35870c5 style: remove needless type casting 2019-03-13 01:17:27 +09:00
ToruNiina
dddcecb034 fix: use snprintf instead of stringstream
to avoid the effect of locale
2019-03-12 23:37:46 +09:00
ToruNiina
dc112bd6c1 feat: add is_[boolean|integer|...]() member func
it is an alias to is<toml::value_t::[Boolean|Integer|...]>
2019-03-12 20:43:07 +09:00
ToruNiina
d90ffb63c6 Merge branch 'master' into allow-deeper-table-before 2019-03-05 23:27:11 +09:00
ToruNiina
b0ed122214 fix: allow deeper table appeared before
allow the following toml file.
```toml
[a.b.c]
d = 10
[a]
e = 2.718
```
2019-03-05 23:25:25 +09:00
ToruNiina
d88521d63c feat: enable to change region of value
To allow the following toml file, we need to replace the region after
the more precise region is found.
```toml
[a.b.c]
d = 42
[a]
e = 2.71
```
If the precise region (here, [a]) is found, the region of `a` should be
`[a]`, not `[a.b.c]`. After `[a]` is defined, toml does not allow to
write `[a]` twice. To check it, we need to replace the region of values
to the precise one.
2019-03-04 15:01:28 +09:00
ToruNiina
2accc9d22c fix: diagnose, but not throw for unicode error
in 2.0.x and 2.1.0, README says "it shows warning" for invalid unicode
codepoints. So far, this library just show an error message in stderr
for this case. It is not good to change the behavior fatal in the next
minor release, 2.1.1, that includes patches and improved error msgs.
I will make it throw syntax_error after 2.2.0 for invalid unicode
codepoints. For now, I will keep it to be "warning".
2019-03-03 18:56:45 +09:00
ToruNiina
ae793fb631 feat: improve error message for invalid array 2019-03-02 17:56:16 +09:00
ToruNiina
944b83642a feat: make location to inherit region_base
To generate error message, it is better to have the same interface.
Also, location can be considered as a region having only one character.
2019-03-02 17:52:00 +09:00
ToruNiina
7f870d5861 fix: diagnose invalid UTF-8 codepoints 2019-03-02 01:57:05 +09:00
ToruNiina
536b23dc84 fix: allow empty table in the middle of a file 2019-03-01 22:53:16 +09:00
ToruNiina
0c9806e99f fix: diagnose key after [table.key] pattern
the following is not a valid toml format.
```
[table] key = "value"
```
this commit enables to diagnose that pattern.
2019-03-01 22:37:52 +09:00
ToruNiina
5a92932019 fix: disallow invalid escape sequence 2019-03-01 22:13:32 +09:00
ToruNiina
e929d2f00f fix: allow empty input file (to be an empty table) 2019-02-27 12:30:57 +09:00
ToruNiina
d0726db473 chore: merge branch master into err-msg-dotted-key 2019-02-27 01:26:36 +09:00
ToruNiina
b36fdf2f54 refactor: remove internal fn not needed any more
The function was needed to copy region information from value to value,
for a useful error message. Because of the last few commits, the region
information about keys are passed to insert_nested_keys that requires
the function which is removed. And it turned out that the function is no
longer required. It is originally a workaround, so I removed it.
2019-02-27 01:07:00 +09:00
ToruNiina
73ba6b385f feat: use key-region to represent table
use x.y.z = 42
    ~~~ here as the region of the table `x.y`
2019-02-27 01:02:39 +09:00
ToruNiina
30d1639aa4 refactor: return region info from parse_kvpair 2019-02-27 00:21:05 +09:00
Quentin Khan
d82814fc86 Add location to error string in parse_* functions 2019-02-26 14:56:58 +01:00
ToruNiina
679b365cf7 feat: get region info when parsing keys
Error messages related to dotted keys looks weird. like:
 1 | a.b.c = 42
   |         ~~ in this table
The underlined token is not a table. This should be like the following.
 1 | a.b.c = 42
   | ~~~ in this table
To implement this, the region information is needed when the keys are
read. This commit add this functionality, though currently the region
information is not used yet.
2019-02-26 00:17:28 +09:00
ToruNiina
83bf83b6dd style: add braces to if and remove additional else 2019-02-19 02:56:15 +09:00
ToruNiina
321364c7c2 fix: format char in an error message correctly 2019-02-19 02:46:48 +09:00
ToruNiina
2dd0a78c52 fix: reset stream width before printing
without this, the first line of the serialized result becomes too wide
2019-02-16 23:55:19 +09:00
Toru Niina
d7b8c3c78f
Merge pull request #18 from ToruNiina/threadsafe-localtime
add threadsafe localtime_(s|r)
2019-02-16 23:28:48 +09:00
ToruNiina
a00a906482 fix: add comma at correct position 2019-02-14 16:17:32 +09:00
ToruNiina
19ad7d7c96 fix: remove needless empty line from serialization 2019-02-14 16:17:04 +09:00
ToruNiina
251e55da42 fix: don't ignore std::setw(0) 2019-02-14 15:49:27 +09:00
ToruNiina
32f1b2060a fix: avoid width overflow 2019-02-14 15:49:13 +09:00
ToruNiina
b1c54532df feat: improve array serialization
- make multiline array more clean
- short-circuit for empty array
2019-02-14 15:48:05 +09:00
ToruNiina
38c67f16e8 fix: initialize float precition correctly 2019-02-14 15:47:00 +09:00
ToruNiina
31193d99ba Merge branch 'master' into serialize 2019-02-13 23:16:39 +09:00
ToruNiina
dd9319245e fix: open file as binary-mode #16
to avoid inconsistency between file size (obtained by tellg) and the
size of the actual contents that would be read later
2019-02-13 19:18:09 +09:00
ToruNiina
5bdc022627 fix: correctly serialize quoted keys 2019-02-13 13:51:08 +09:00
ToruNiina
41e354f1ee supress warnings while skipping switch-cases 2019-02-13 13:50:33 +09:00
ToruNiina
d1c76709b0 add serializer #23 2019-02-13 13:37:58 +09:00
ToruNiina
64774a8db0 add toml::visit to use it in serializer 2019-02-13 13:36:55 +09:00
ToruNiina
53f6b8268b fix: compare offset_datetime correctly 2019-02-13 13:34:26 +09:00
ToruNiina
32dcc35918 move return_type_of_t from result to traits 2019-02-13 13:34:03 +09:00
Quentin Khan
1dfe32acd8 Fix multiple definition error 2019-01-30 17:06:23 +01:00
Toru Niina
5dfdbe4bff
Merge pull request #20 from ToruNiina/format-error
add an extra parameter `hints` to format_error
2018-12-27 20:34:53 +09:00
ToruNiina
aa67069387 move hints to the internal function 2018-12-27 16:32:20 +09:00
ToruNiina
ee3424ad51 add an extra parameter hints to format_error 2018-12-27 16:26:23 +09:00
ToruNiina
17def14ab6 add default template arg to toml::find
in most of the use cases, toml::value is used (to show error message).
2018-12-27 15:58:50 +09:00
ToruNiina
51dd3abcae remove one branch by preprocessor
since localtime in windows is already thread-safe, there are no need to
change the function.
2018-12-26 13:38:01 +09:00
ToruNiina
825b2c30a1 add threadsafe localtime_(s|r) 2018-12-25 22:40:52 +09:00
Toru Niina
b5b8830c29
Merge pull request #17 from ToruNiina/hotfix
fix the error with BOM and end of file w/o newline
2018-12-24 16:37:10 +09:00
ToruNiina
11c7ee4501 fix the case of file w/o newline at the end
toml::parse failed with the file that contains whitespace or comment at
the end of file without newline. this commit fixes the error.
2018-12-24 16:00:33 +09:00
ToruNiina
d24a188d4c fix the error while reading BOM.
remove possible UB because of the use-after-move.
2018-12-24 15:06:26 +09:00
ToruNiina
7c03c446fe speedup by removing needless format_underline
drastical speedup for long toml files
2018-12-23 15:22:12 +09:00
ToruNiina
5546b3389d Merge branch 'master' into error-message 2018-12-22 17:55:59 +09:00
ToruNiina
9c95992dad fix error message for empty value 2018-12-22 17:44:09 +09:00
ToruNiina
c63ac7e435 detect syntax_error; appending array-of-tables
toml file like the following is explicitly prohibited.
a = [{b = 1}]
[[a]]
b = 2
this commit detects this kind of syntax-error while parsing toml file
2018-12-22 17:07:06 +09:00
ToruNiina
fec49aaaa3 fix error message: add missing spaces 2018-12-22 17:06:36 +09:00
ToruNiina
e3217cd572 quit returning rvalue ref from unwrap_or 2018-12-17 23:17:45 +09:00
ToruNiina
24723226f1 remove template argument from result::unwrap_or 2018-12-17 19:18:16 +09:00
ToruNiina
7b3684b54e add and_other and or_other to toml::result
effectively same as Rust's std::Result::and and or.
2018-12-17 18:24:41 +09:00
ToruNiina
13c1f9c259 output filename of the second value2 if different
in format_error.
2018-12-17 18:07:57 +09:00
ToruNiina
74fc70cfee return copied object from except
having reference makes some technical difficulties.
2018-12-17 10:57:40 +09:00
Toru Niina
91ac2debce
Merge pull request #12 from ToruNiina/hotfix
enable to get toml::value as toml::value
2018-12-17 10:50:05 +09:00
ToruNiina
ab41e7acb9 enable to pass 2 value and change interface for clarity 2018-12-16 21:50:18 +09:00
ToruNiina
c15bc8df4a add format_error(toml::value, msg, comment) 2018-12-16 21:46:32 +09:00
ToruNiina
c2e733a65d enable to get toml::value as toml::value 2018-12-16 20:50:40 +09:00
ToruNiina
0c08b9e940 fix typo 2018-12-15 22:02:46 +09:00
ToruNiina
fd21d5dd95 add simplest copyright notice 2018-12-13 20:44:10 +09:00
ToruNiina
57de57a1de improve error message for empty value 2018-12-13 20:37:40 +09:00
ToruNiina
e86777d19c improve error message for conflicting tables 2018-12-13 20:17:57 +09:00
ToruNiina
e79069cc47 enable to show err msg for invalid insertion
like, with the following (invalid) toml file

> a.b = "value"
> a.b.c = 42

The error message becomes

> terminate called after throwing an instance of 'toml::syntax_error'
>   what():  [error] toml::insert_value: target (a.b) is neither table nor
> an array of tables
>  --> example.toml
>  1 | a.b = "value"
>    |       ~~~~~~~ actual type is string
>  ...
>  2 | a.b.c = 42
>    |         ~~ inserting this
2018-12-13 17:09:38 +09:00
ToruNiina
f60e93c36f enable to assign value keeping region info 2018-12-13 17:07:26 +09:00
ToruNiina
e5c29c2870 enable to show err msg for 2 different location 2018-12-13 17:07:03 +09:00
ToruNiina
acc7b7870f remove format_error_for_value and add get_region instead
it is convenient to have get_region function that can access region_info
in toml::value. get_region is placed in toml::detail and made friend of
toml::value because I don't want to make toml::value::region_info public
and keep it internal use only.
2018-12-13 16:13:05 +09:00
ToruNiina
5125287ac7 fix datetime conversion
use internal duration type in std::chrono::system_clock::time_point
2018-12-13 14:57:42 +09:00
ToruNiina
26e0d87d3b enable nanoseconds in datetimes 2018-12-13 12:49:53 +09:00
ToruNiina
514f3c773f set test_from_toml 2018-12-13 02:24:03 +09:00
ToruNiina
27a80b1214 rename get(table, key) to find() 2018-12-13 02:00:13 +09:00
ToruNiina
affa159c82 add get_or(value, key, opt) 2018-12-13 01:29:23 +09:00
ToruNiina
901c299c40 add unwrap_or to result 2018-12-13 01:28:55 +09:00
ToruNiina
c15cb15c4c simplify to_toml implementation 2018-12-13 00:38:04 +09:00
ToruNiina
c69969733f use carriage return depending on env 2018-12-12 23:22:31 +09:00
ToruNiina
47cd6f5a41 remove redundant error message 2018-12-12 23:17:28 +09:00
ToruNiina
65cfa9d06b remove unused file because its not stable
since toml::format is not stable now, remove once for the next release.
2018-12-12 20:35:21 +09:00
ToruNiina
03be08a2e6 fix conversion from offset_datetime to system_clock::time_point 2018-12-12 20:28:11 +09:00
ToruNiina
5aae0b17c8 change error message; require unicode codepoint
before this, it recommends the range that can be represented by utf-8
but the range of valid unicode codepoint is narrower than that. for
error message, it is good to recommend valid unicode codepoint.
2018-12-12 19:14:27 +09:00
ToruNiina
0f83ee6039 change temporaly loc from token to copy of loc
location constructed from token string does not has correct line number
information. to show an informative error message about UTF-8 and escape
sequences, parse_(ml_)basic_string requires those information that can
only be given from root location<Container>.
2018-12-12 19:12:23 +09:00
ToruNiina
879b7d3bff improve format of error message for utf-8 2018-12-12 19:01:22 +09:00
ToruNiina
c33ad31981 split lexer for escape sequence for unicode 2018-12-12 18:59:20 +09:00
ToruNiina
5d29509d98 remove duplicated default argument for SFINAE 2018-12-12 18:58:54 +09:00
ToruNiina
717e03cd4a add find-get overload functions 2018-12-12 17:55:34 +09:00
ToruNiina
dc060ba840 add explicit std::move to toml::get(&&) 2018-12-12 17:22:41 +09:00
ToruNiina
0c9b785969 add missing include file 2018-12-12 16:11:37 +09:00
ToruNiina
bcaf5baf88 fix parse_array_of_table_key
allow whitespace before and after [[ and ]] (like, [[ a.b ]])
2018-12-12 12:14:11 +09:00
ToruNiina
a1a81089c5 skip whitespace before/inside/after dotted-keys 2018-12-12 01:30:47 +09:00
ToruNiina
765ab97d8b add whitespace between [] and key
[ a.b.c ] is allowed. also, [[ a . b ]] is allowed.
dotted key matches `a.b.c` only, so the explicit whitespace is needed.
2018-12-12 01:27:10 +09:00
ToruNiina
fc6a15440d enable format_underline to print hint with region 2018-12-11 22:22:07 +09:00
ToruNiina
d7bba10fa3 improve error message in parse_key_value_pair 2018-12-11 22:21:22 +09:00
ToruNiina
247bcb0714 show error message for inhomogenous array 2018-12-11 22:17:28 +09:00
ToruNiina
27b9334f10 skip BOM if exists 2018-12-11 21:40:48 +09:00
ToruNiina
38135940e9 add expect<T>(toml::value) 2018-12-11 11:36:40 +09:00
ToruNiina
d75a977066 improve error message for bad unwrap a bit 2018-12-11 11:35:07 +09:00
ToruNiina
75c136924b add datetimes to chrono 2018-12-10 22:06:06 +09:00
ToruNiina
0759e757ae move is_chrono_duration from types to traits 2018-12-10 22:05:42 +09:00
ToruNiina
4e57c5f5df improve error message for invalid line
like a = 12 = true, newline is expected after 12
2018-12-10 21:43:02 +09:00
ToruNiina
ff83a6a477 remove redundant part of error messages 2018-12-10 21:42:56 +09:00
ToruNiina
3f991c4759 improve power of get 2018-12-10 15:58:20 +09:00
ToruNiina
bf2158ae98 add map from exact toml type -> toml::value_t 2018-12-10 15:57:44 +09:00
ToruNiina
ff19c9f492 add corresponding region to each value 2018-12-10 15:57:17 +09:00
ToruNiina
28ba2713ee fix initialization of region in value 2018-12-10 15:25:27 +09:00
ToruNiina
129ea81f66 remove redundant words in error message 2018-12-10 15:23:46 +09:00
ToruNiina
8dfe187d59 add a function to show a better error message 2018-12-10 15:06:28 +09:00
ToruNiina
8078c719fe remove old code 2018-12-10 00:15:41 +09:00
ToruNiina
8e18aa9b16 add toml::parse 2018-12-10 00:14:46 +09:00
ToruNiina
ed155a5040 remove help msgs in parse_value
because the error message becomes too long
2018-12-09 21:54:47 +09:00
ToruNiina
cf03a08632 re-write parser using result and new value
wip.
2018-12-09 19:32:30 +09:00
ToruNiina
34c3d33936 use vector instead of initializer_list 2018-12-09 19:30:46 +09:00
ToruNiina
c04b75b2e3 consider LF in the range when writing error msg 2018-12-09 18:08:04 +09:00
ToruNiina
e24039f4ef update toml::value and improve test_value
- enable to store new types
- store source string if possible
- refactoring
2018-12-09 18:03:20 +09:00
ToruNiina
dc8ccdc458 construct much more tmp variables
std::chrono::seconds -= std::chrono::milliseconds cannot be done bc
it represents the duration as integer value and milliseconds are less
than seconds. it causes compilation error when we pass a duration to
toml::local_time. to avoid this, we need to type-cast the values to
smaller duration, like sec -> msec
2018-12-09 18:00:46 +09:00
ToruNiina
2696e4e6ba split storage from value
also, quit inheritance in storage class
2018-12-09 16:41:45 +09:00
ToruNiina
d1d5ca6bf8 add toml::string to have basic/literal flag 2018-12-09 16:40:57 +09:00
ToruNiina
80eafd1424 add datetime variants and rearrange type-related functions 2018-12-09 16:34:47 +09:00
ToruNiina
9fadf71a10 add constructor from duration to local_time 2018-12-09 16:27:47 +09:00
ToruNiina
ac3025d92f change default return value of region_base 2018-12-09 13:39:13 +09:00
ToruNiina
b0e7efa1e0 make some constructors explicit 2018-12-09 13:38:57 +09:00
ToruNiina
84676eab0b improve quality of error message 2018-12-09 13:05:09 +09:00
ToruNiina
2b3a4d49a5 add region_base to contain it in toml::value
to make toml::get and toml::value::cast return better error messages
2018-12-09 12:41:38 +09:00
ToruNiina
f834e0d142 cosmetic: sort value_t in types.h 2018-12-09 11:06:19 +09:00