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

feat: rust plugin rename rust keywords with trail underscore #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

driftluo
Copy link
Collaborator

@driftluo driftluo commented Jun 28, 2024

This PR Fix two bugs on molecule:

  1. rust keywords on table/struct can generate code, but cannot compile with rustc, for example:
array struct [byte; 2];

struct StructP {
    type: struct
}

It is OK to name a type as a rust keyword; the rust plugin will automatically camelCase the name. However, when the field of a table/struct is named as a rust keyword, the current version does not automatically handle this problem, causing the generated code to fail to compile. This PR will automatically check the field name and add an underscore to the end of the keyword to avoid keyword conflicts.

Just like the type above, in the generated code, it will become type_(Or prefix it with r#? I'm not sure)

I think the solution to keyword conflicts must be solved in each language's plugins.

  1. Since type names support uppercase and lowercase letters, they will be uniformly camel-cased. When two types have inconsistent names but consistent camel case, uncompilable code will be generated, as in the following schema:
array struct [byte; 2];

struct StructP {
    a: struct
}

union structP {
    struct,
}

This PR will detect this situation and report an error: "the name structP is used more than once, It seems that only the capitalization is inconsistent"

other change: upgrade serde_yaml/clap/pest deps

@driftluo driftluo force-pushed the rust-plugin-add-keyword-rename-feature branch 2 times, most recently from ed0dd42 to ed8a5fd Compare June 28, 2024 11:56
eval-exec
eval-exec previously approved these changes Jun 28, 2024
tools/codegen/src/generator/languages/rust/utilities.rs Outdated Show resolved Hide resolved
eval-exec
eval-exec previously approved these changes Jul 1, 2024
@zhangsoledad
Copy link
Member

MSRV was bumped because of the introduction of https://doc.rust-lang.org/std/sync/struct.OnceLock.html, this should have been stated in the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:enhancement Type: Feature, refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants