diondokter / device-driver

A toolkit to create better Rust device drivers, faster
Apache License 2.0
94 stars 4 forks source link

More control over case conversions? #35

Open alexmoon opened 1 month ago

alexmoon commented 1 month ago

Right now converting names from pascal case to snake case can lead to some undesirable word boundaries. For example I2cSettings turns into i_2_c_settings in snake case and I2CSettings (note the capital C) in pascal case. I'm not sure what the best solution would be to give the user more control over those conversions. One option would be to use an unambiguous casing as the input in all cases (such as snake case). Another option would be to let the user optionally specify the casings somehow.

I would consider this a pretty minor issue, but something worth thinking about; particularly if you move forward with something like #34.

diondokter commented 1 month ago

Yeah that's true. Can be annoying at times. I made it like this so it's easy to copy from datasheets which are not always consistent.

I want to have some global settings and the casing can be part of that. The current could be called 'best guess', but others could maybe specify that the input case is always Pascal.

diondokter commented 3 weeks ago

So what I've settled on now is being able to specify the word boundaries yourself fully in the global config: https://github.com/diondokter/device-driver/blob/4c2a0414f68a99f9e7d10759556484d5aaac54d8/generation/src/dsl_hir/mod.rs#L20-L34

You can specify the boundaries as an array: https://docs.rs/convert_case/latest/convert_case/enum.Boundary.html Or as a string: https://docs.rs/convert_case/latest/convert_case/enum.Boundary.html#method.list_from