Skip to content

Commit

Permalink
feat: rust plugin rename rust keywords with trail underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Jun 29, 2024
1 parent 4988418 commit 7bae730
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 291 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI
on:
push:
branches: [ master, develop, staging, trying ]
branches: [master, develop, staging, trying]
pull_request:
branches: [ master ]
branches: [master]
defaults:
run:
shell: bash
Expand Down Expand Up @@ -38,19 +38,19 @@ jobs:
run: make clippy
test-msrv:
name: Tests / Build (MSRV)
needs: [ rustfmt, clippy ]
needs: [rustfmt, clippy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.56.1 # MSRV
toolchain: 1.75.0 # MSRV
- name: Run
run: make ci-msrv
test-crates:
name: Tests / Build & Test
needs: [ rustfmt, clippy ]
needs: [rustfmt, clippy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -62,7 +62,7 @@ jobs:
run: make ci-crates
test-examples:
name: Tests / Run Examples
needs: [ rustfmt, clippy ]
needs: [rustfmt, clippy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -75,7 +75,7 @@ jobs:
success:
name: Success
if: ${{ success() }}
needs: [ test-crates, test-examples ]
needs: [test-crates, test-examples]
runs-on: ubuntu-latest
steps:
- name: Succeed
Expand Down
50 changes: 27 additions & 23 deletions examples/ci-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/lazy-reader-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/tests-utils-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
codegen = { package ="molecule-codegen", path = "../../tools/codegen" }
tests-loader = { package ="molecule-tests-loader", path = "../tests-loader" }
serde_yaml = "0.8.26"
codegen = { package = "molecule-codegen", path = "../../tools/codegen" }
tests-loader = { package = "molecule-tests-loader", path = "../tests-loader" }
serde_yaml = "0.9"
6 changes: 3 additions & 3 deletions examples/tests-utils-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ edition = "2018"
proc-macro = true

[dependencies]
codegen = { package ="molecule-codegen", path = "../../tools/codegen" }
tests-loader = { package ="molecule-tests-loader", path = "../tests-loader" }
codegen = { package = "molecule-codegen", path = "../../tools/codegen" }
tests-loader = { package = "molecule-tests-loader", path = "../tests-loader" }
syn = "1.0.58"
quote = "1.0.8"
proc-macro2 = "1.0.24"
serde_yaml = "0.8.26"
serde_yaml = "0.9"
49 changes: 45 additions & 4 deletions tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tools/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = [
"parser-implementations",
"development-tools::build-utils",
"encoding",
"data-structures"
"data-structures",
]
license = "MIT"

Expand All @@ -27,7 +27,7 @@ same-file = "1.0.6"
semver = "0.11.0"
serde = { version = "1.0.195", features = ["derive", "rc"], optional = true }
serde_json = { version = "1.0.111", optional = true }
serde_yaml = { version = "0.8.26", optional = true }
serde_yaml = { version = "0.9", optional = true }

[dev-dependencies]
tempfile = "=3.6.0"
Expand Down
9 changes: 9 additions & 0 deletions tools/codegen/src/ast/verified/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ impl super::Ast {
if decls_idx.insert(name, decl).is_some() || !decls_keys.insert(name) {
panic!("the name `{}` is used more than once", name);
};

let decls_keys_clone = decls_keys
.iter()
.cloned()
.map(str::to_lowercase)
.collect::<HashSet<String>>();
if decls_keys_clone.len() != decls_keys.len() {
panic!("the name `{}` is used more than once, It seems that only the capitalization is inconsistent", name);
}
}
let mut decls_result = HashMap::new();
decls_result.insert(
Expand Down
6 changes: 3 additions & 3 deletions tools/codegen/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ impl Compiler {
let output = output.as_mut().ok_or("output is not set")?;

#[cfg(not(feature = "compiler-plugin"))]
let file_name;
let mut file_name = Default::default();
#[cfg(feature = "compiler-plugin")]
let mut file_name = None;

let ast = match input {
Input::SchemaFile(ref file_path) => {
file_name = file_path
file_path
.as_path()
.file_name()
.and_then(ffi::OsStr::to_str)
.to_owned();
.clone_into(&mut file_name);
parser::Parser::parse(file_path)
}
#[cfg(feature = "compiler-plugin")]
Expand Down
2 changes: 1 addition & 1 deletion tools/codegen/src/generator/languages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{convert::TryFrom, fmt, io};
use crate::ast;

mod c;
mod rust;
pub(crate) mod rust;
mod rust_lazy_reader;

#[derive(Debug, Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion tools/codegen/src/generator/languages/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use quote::quote;

use crate::{ast, VERSION};

mod utilities;
pub(crate) mod utilities;

mod builder;
mod entity;
Expand Down
Loading

0 comments on commit 7bae730

Please sign in to comment.