3 ms·
A few protips for nimble_parsec: - ninja in a struct for your context, just generally a better choice due to the stronger typing. - decide if your parser is a
by dnautics 6y ago
A few protips for nimble_parsec:
- ninja in a struct for your context, just generally a better choice due to the stronger typing.
- decide if your parser is a transformer or an analyzer. If it only analyzes text, then throw away all of the text after you use it and use the text stream as a contextual buffer. If it transforms, be consistent about the tokens you return in the stream. Use structs if you can.
- build intermediate defparsecs which create testable functions that you can test. If you like, fence them in `if Mix.env == :test` blocks to keep them from being compiled except in test.
Example: https://github.com/ityonemo/zigler/blob/master/lib/zig/parser.ex https://github.com/ityonemo/zigler/blob/master/lib/zig/parse...