Distinguishing FooBar and fooBar when converting to snake case module name
I have a small patch for the module_name function in capnpc that inserts a leading _ in the module name when the camel case name begins by a lower case letter. This is intended to prevent name clashes between the module generated for something like a struct FooBar and the module generated from something like annotation fooBar (these cases occur in the capnp codebase I am using). Would this patch be something that could be contributed upstream, perhaps as an option rather than as default behaviour? I'm willing to do all the heavy lifting to submit a PR that is mergeable. I'm mostly asking for direction about what would be the preferred approach.
What if we updated the name annotation in rust.capnp so that it could be used to annotate annotations?
https://github.com/capnproto/capnproto-rust/blob/ffcb213b6223d0d25ee5f622c9842b3c5a1f78ba/capnpc/rust.capnp#L9-L15
Would that work for you?
That might work but it does not seem a great solution for my use case, mainly because of two reasons:
-
The capnp code base is rather large and I would have to go through it manually adding these annotations where needed. We also have C++ and Python tools making use of these capnp files, and I would need to check that this introduces no conflicts. For simplicity, I would rather implement a solution that doesn't involve modifying the capnp files.
-
According to the comment in the code you linked, the name that is given is the capnp name, rather than the Rust name, so this does not seem to allow me to rename an annotation
fooBarinto_foo_bar. I guess I could rename the annotationfooBarinto something likefooBarAnnotation, so that its Rust module ends up beingfoo_bar_annotationinstead offoo_bar, which would clash withstruct FooBar. However, the problem is that I also have Rust code generated inbuild.rsthat needs to be able to predict the names of the Rust types and modules generated by capnpc based on the names in the capnp files. Allowing renames introduces an extra layer of complexity.