-
Notifications
You must be signed in to change notification settings - Fork 203
TOML lens #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TOML lens #91
Conversation
Any update on this? I think a TOML parser would be very useful. Plus, I think the TOML project would benefit from having a lens because it assures that the language is regular. |
@tlimoncelli do you have an opinion on the possible implementation choices outlined above? |
1ae2414
to
e890a47
Compare
I guess the decision comes down to: should the subnodes reflect the TOML standard, which says that each value has a type; or should it reflect how it is formatted (quoted or bare). IMHO either is fine. I think the quoted/bare is sufficient; recording the type also works but seems to add detail that isn't used. Implement whatever is easiest. I would make sure a tests that include:
as well as
There should also be a tests that set the value (to the string and to the boolean). I do have a concern that the subnode could be confused with actual data if someone were to iterate over the data. Is that a possibility? Does any other lens use this technique of creating subnotes to store metadata? |
@tlimoncelli I currently have no use for that lens, but I'm willing to get it in shape. The current implementation parses the string and boolean values the same way. What would you suggest as a tree to keep the TOML functionalities? |
I'm not entirely sure I understand the question but that rarely prevents me from answering At a high level the request is that the lens should retain quotes (or lack of quotes) when it parses Of the implementation proposals listed above, I think the best is to add subnodes that indicate whether the element was quoted or not. For example this file:
should create this tree:
|
@tlimoncelli I see the issue. The tree should definitely denote the typing. |
It has dawned on me that instead of "quoted" and "bare", better words might be "string" and "boolean".
|
Any update? |
@tlimoncelli sorry, haven't looked at it for some time. |
The thing with "string"/"boolean" is that it only fixes the issue for booleans, not general quoting. |
I've just played around a little. If we want to reflect the typing, we will have to make a lens with a complex tree like |
Hi, I just play around with that lens but got some issues.
I'm using augeas 1.2. Any ideas ? Thx a lot :) |
any update on this? |
Any movement on this? @raphink? |
@jrabbit @flyinbutrs no, I haven't had a use for this (although I do use TOML in other contexts). If someone wants to work on it, I'd welcome patches. |
TODO: inline tables
@tlimoncelli @descrepes @jrabbit @flyinbutrs I've just restarted work on this, using the Json (fully typed) approach. Afaik it's only missing inline table support and quotes/dots on keys 🤢, so testing/feedback is most welcome! |
Is this enough to parse your typical |
Do you have a full example @lutter? |
At least https://github.com/slog-rs/example-lib/blob/master/Cargo.toml parses properly:
|
Note: in principle, arrays don't allow mixing types for elements (I don't really see why btw), but this lens allows it. |
@lutter do you want to merge this as is? |
I'll just merge as it is. |
Thanks for doing that ! THat's what I've been meaning to do, too. |
There's still a few details to fix imo, I'll try to run it on as many TOML files as possible and open issues. |
* fix(lens): toml: add write support The toml lens fails to save simple toml files due to problems with multi dimensional (>2) arrays. Therefore disable arrays with more than 2 dimensions for now to enable basic usage again. This commit fixes issue #715 by applying the suggested workaround. If anyone can come up with a better solution please feel free to do so. Fixes: 5e1cd31 (TOML lens (#91), 2018-11-29) Signed-off-by: Richard Leitner <[email protected]> * fix(lens): toml: update reference link toml.io now provides a versioned reference URL, therefore use this instead of the old GitHub repo link. Signed-off-by: Richard Leitner <[email protected]> * fix(lens): toml: typo in About: License Signed-off-by: Richard Leitner <[email protected]> * test(lens): toml: add basic write This test covers the bug described in issue #715. Signed-off-by: Richard Leitner <[email protected]> * test(lens): toml: fix "array of arrays" The "Test: Toml.array_norec; Array of arrays" tested a 3 dimensional array. This commit fixes the test to actually test a 2 dimensional array. More than 2 dimensional arrays are currently not supported due to issue #715. Signed-off-by: Richard Leitner <[email protected]> Co-authored-by: George Hansper <[email protected]>
TOML was brought to my attention several times recently: https://github.com/mojombo/toml
The attached patchset covers all the examples provided in the docs.
CAVEATS
QUOTES! Bare data types need to be clearly identified in order to force quoting only for values that are not integers, floats, booleans or datetimes… Even then, could a user want a quoted boolean? If so, we'll have to put quotes in the values, which is really ugly…
One way to fix this would be to type values strictly using subnodes for examples:
or simply marking them as quoted/bare:
or