vulkano icon indicating copy to clipboard operation
vulkano copied to clipboard

Nom nom

Open stefnotch opened this issue 11 months ago • 2 comments

  1. [x] Update documentation to reflect any user-facing changes - in this repository.

  2. [x] Make sure that the changes are covered by unit-tests.

  3. [x] Run cargo clippy on the changes.

  4. [x] Run cargo +nightly fmt on the changes.

  5. [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.

  6. [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)

stefnotch avatar Feb 27 '24 14:02 stefnotch

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.

stefnotch avatar Feb 27 '24 14:02 stefnotch

Looks good! @marc0246 do you have anything more to add?

Rua avatar Feb 29 '24 16:02 Rua

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.)

marc0246 avatar Mar 03 '24 20:03 marc0246

I love it, thanks! :heart:

marc0246 avatar Mar 04 '24 18:03 marc0246

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

stefnotch avatar Mar 04 '24 19:03 stefnotch