-
Notifications
You must be signed in to change notification settings - Fork 200
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
Add lens for reading termcap-style databases #274
Conversation
One annoyance I have is that new records will be added without any whitespace like so:
which is fine for small records, but long ones will wrap and look a bit meh so I made the following change to my lens: diff --git a/lenses/getcap.aug b/lenses/getcap.aug
index bd002de..c38893a 100644
--- a/lenses/getcap.aug
+++ b/lenses/getcap.aug
@@ -28,10 +28,9 @@ module Getcap =
(* field must not contain ':' unless quoted or '\'-escaped *)
let field = /([^:\n]|\\\\:)+|[^:\n]*(\"[^\n]+\"[^:\n]*)+/
- let sep = del /:|:[ \t]*\\\\\n[ \t]*:/ ":"
- let name = store field . sep
- let capability = [ label "capability" . store field . sep ]
- let record = [ seq "record" . name . capability+ . eol ]
+ let sep = del /:([ \t]*\\\\\n[ \t]*:)?/ ":\\\n\t:"
+ let capability = [ label "capability" . store field ]
+ let record = [ seq "record" . store field . sep . capability . ( sep . capability )* . Sep.colon . eol ]
let lns = ( empty | comment | record )*
which should in theory should mean new records are added like so:
however what gets written to the file with
The |
lenses/tests/test_getcap.aug
Outdated
" | ||
|
||
test Getcap.lns get getcap = | ||
{ "1" = "example|an example of binding multiple values to names" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't match what your lens is doing.
I've added a CSV lens this morning, which is very similar to what you're trying to achieve. In fact, You might want to check it out. |
I realised the structure I was parsing records into didn't allow me easily to write idempotent changes for use with Puppet so I've changed how records are parsed. I still have a problem with my tests in that I can't give some sample test output containing literal I will take a look at the CVS lens and see how that works. |
Any news on this lens @bodgit ? |
Oooh yes, this would be quite useful. |
Still not working 100% but now we know there are some bugs with backslashes in general it makes sense to get those ironed out first. |
@bodgit typechecking doesn't pass yet though |
@bodgit nice work .. one minor nit: I now consider |
Ironically I think it was |
Other than that, the only thing to point out is that I've dropped reading the actual
In theory I should just be able to use a simple regex such as |
Actually, thinking about this, I can split this into two lenses with one lens written mostly in terms of the other with just a different regexp for matching the capabilities. Bear with me 😄 |
@bodgit sounds good .. awaiting the refactored, much expanded lens anxiously ;) Looks like you've stumbled on one of the great things about config files: the discrepancy of the documented format and the format tools actually understand; in a lot of cases, I've had to read the parsing code of whatever consumes a file to discover that. Seems termcap is no different in that regard. @raphink yes, #244 would still be useful, but I'd like to get a little more feedback on syntax etc. So if you have thoughts, would love to discuss more on the PR |
The termcap lens still doesn't work on an OpenBSD |
Awesome ! I am merging this for now; when you resolve the |
This is my stab at fixing #271 which seems to parse everything I've thrown at it including a ~900 KB termcap file. I can also add new records to files. However unless I disable type checking I get:
Any advice on cleaning that up would be appreciated.
I've tried writing some basic tests however I'm getting stuck where there should be a literal
\
in the output. If I try\
-escaping it then I get something like the following:Any ideas?