vulkano
vulkano copied to clipboard
Nom nom
-
[x] Update documentation to reflect any user-facing changes - in this repository.
-
[x] Make sure that the changes are covered by unit-tests.
-
[x] Run
cargo clippy
on the changes. -
[x] Run
cargo +nightly fmt
on the changes. -
[x] Please put changelog entries in the description of this Pull Request if knowledge of this change could be valuable to users. No need to put the entries to the changelog directly, they will be transferred to the changelog file by maintainers right after the Pull Request merge.
Please remove any items from the template below that are not applicable.
-
[x] Describe in common words what is the purpose of this change, related Github Issues, and highlight important implementation aspects.
The regexes for parsing the vk.xml file have been replaced with equivalent nom constructions. The nom code I wrote is probably not optimal, since I was learning the library as I went along. That's also why one will find different "styles" of nom code.
Changelog:
### Public dependency updates
- [regex](https://crates.io/crates/regex) has been replaced with [nom](https://crates.io/crates/nom)
And now the benchmarks, as promised.
I did them by running
cargo clean
cargo build --lib --timings
There are 3 benchmarks for before (regex), and 2 benchmarks for after migrating to nom cargo-timing-before-and-after.zip
At the very least, compile times didn't regress. I think on average, they slightly improved, but I haven't done a statistically rigorous test.
Looks good! @marc0246 do you have anything more to add?
A couple nit picks regarding overall code structure.
I'm seeing value
used as the variable name for parser input in a lot of places. I think it would be more self-documenting to use input
or i
in all cases.
This pattern:
parser(input).map(|(input, x)| (input, thing(x)))
Is what Parser::map
is for, so that you don't have to string the input along manually and it's cleaner. Note that types implementing Parser
also have Parser::parse
. Not only functions are parsers. This applies to e.g. the Map
parser:
parser.map(thing).parse(input)
Parsers are generally not prefixed with parse_
, rather they are called the thing that they parse. (Think char
or whatever.) This applies to parse_name
, parse_expression_start
and parse_expression_root
, but not parse_depends
for instance, because that one is not a parser just a function that parses. (It doesn't return the rest of the input alongside the result.)
I love it, thanks! :heart:
I must say I really enjoyed working on this, and then getting top tier feedback. It's been a while since I got to learn so much in such a short period of time. <3