Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle runs of uppercase letters for name generation #218

Merged
merged 7 commits into from
Jul 3, 2024

Conversation

SebastienGllmt
Copy link
Collaborator

@SebastienGllmt SebastienGllmt commented Dec 25, 2023

Previous handling of uppercase letters in @name generation was not ideal

Notably, @name NFT would result in the generated rust code having functions like new_n_f_t instead of new_nft

This PR should fix this.

Two other things this PR does:

  • Fixed the clippy error (doesn't look like it was caused by this PR)
  • Adds the missing WASM_BINDGEN_WEAKREF=1 that should be added to the generated package.json

@SebastienGllmt SebastienGllmt self-assigned this Dec 25, 2023
Copy link
Collaborator

@rooooooooob rooooooooob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clippy error wasn't caused by this PR. It was caused from the rust version used on github being upgraded from 1.75 to 1.77. I didn't get it locally (on 1.75) but when I upgraded to 1.77 I did even on master.

I ran the branch on the current spec to see and I noticed for example:

auxiliary_data =
  shelley_format_aux_data ; @name shelley
  / shelley_ma_format_aux_data ; @name Shelley_m_a
  / conway_format_aux_data ; @name conway

which is how it is now produces shelleyma as the variable instead of shelley_ma like I would have expected. I tried changing it to ; @name ShelleyMA and it's the same.

Is this the expected behavior?

@SebastienGllmt
Copy link
Collaborator Author

Shelley_m_a

I figured out the bug here (it happens even if the name is just m_a

What is happening is that the value passed to convert_to_snake_case is not the comment DSL value as-is. Rather, the label gets converted to camel case first

In both parse_group and create_variants_from_type_choices we do

let variant_ident = VariantIdent::new_custom(convert_to_camel_case(&ident_name));
EnumVariant::new(variant_ident, ty, serialize_as_embedded)

so if you start with m_a

  • convert_to_camel_case("m_a")MA
  • convert_to_snake_case("MA")ma (with this new PR)

not sure what is the best way to solve this in the code without making a mess of everything

@rooooooooob
Copy link
Collaborator

@SebastienGllmt I updated this and fixed the issues we had with things like shelley_ma, etc. The general approach seems to be to either do ShelleyMA or for general cddl consistency/similarity to our usual cddl defs from IOHK shelley_MA (snake case everywhere but runs of uppercases are recommended to be in all-caps e.g. IP_address, VRF_vkey, etc)

rooooooooob added a commit to dcSpark/cardano-multiplatform-lib that referenced this pull request Jul 2, 2024
Using dcSpark/cddl-codegen#218 and dcSpark/cddl-codegen#238

Also renames some cert fields to be clear as `coin` was not very
helpful.
@rooooooooob rooooooooob merged commit 1ec516f into master Jul 3, 2024
1 check passed
SebastienGllmt pushed a commit to dcSpark/cardano-multiplatform-lib that referenced this pull request Jul 10, 2024
* Add documentation + fix acronym names

Using dcSpark/cddl-codegen#218 and dcSpark/cddl-codegen#238

Also renames some cert fields to be clear as `coin` was not very
helpful.

* update multi-era crates too

* clippy fix
rooooooooob added a commit to dcSpark/cardano-multiplatform-lib that referenced this pull request Jul 23, 2024
* Add documentation + fix acronym names

Using dcSpark/cddl-codegen#218 and dcSpark/cddl-codegen#238

Also renames some cert fields to be clear as `coin` was not very
helpful.

* update multi-era crates too

* clippy fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants