diff --git a/Cargo.lock b/Cargo.lock index a0d31f77ad8..07176705783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,6 +112,16 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "ast-generator" +version = "0.1.0" +dependencies = [ + "itertools 0.10.5", + "proc-macro2", + "quote", + "ungrammar", +] + [[package]] name = "atomic" version = "0.6.0" @@ -681,16 +691,6 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab85b9b05e3978cc9a9cf8fea7f01b494e1a09ed3037e16ba39edc7a29eb61a" -[[package]] -name = "generate-schema" -version = "0.1.0" -dependencies = [ - "itertools 0.10.5", - "proc-macro2", - "quote", - "ungrammar", -] - [[package]] name = "getrandom" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 4b80e2ac9b7..b63e3971ee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ "ruby/extractor", "rust/extractor", "rust/extractor/macros", - "rust/generate-schema", + "rust/ast-generator", ] [patch.crates-io] diff --git a/MODULE.bazel b/MODULE.bazel index 38f182d14ba..4a2219d43a5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -61,7 +61,7 @@ r.from_cargo( "//ruby/extractor:Cargo.toml", "//rust/extractor:Cargo.toml", "//rust/extractor/macros:Cargo.toml", - "//rust/generate-schema:Cargo.toml", + "//rust/ast-generator:Cargo.toml", "//shared/tree-sitter-extractor:Cargo.toml", ], ) diff --git a/rust/generate-schema/.gitignore b/rust/ast-generator/.gitignore similarity index 100% rename from rust/generate-schema/.gitignore rename to rust/ast-generator/.gitignore diff --git a/rust/generate-schema/BUILD.bazel b/rust/ast-generator/BUILD.bazel similarity index 91% rename from rust/generate-schema/BUILD.bazel rename to rust/ast-generator/BUILD.bazel index 2a1be1d2c1a..19c078e2342 100644 --- a/rust/generate-schema/BUILD.bazel +++ b/rust/ast-generator/BUILD.bazel @@ -1,7 +1,7 @@ load("//misc/bazel:rust.bzl", "codeql_rust_binary") codeql_rust_binary( - name = "generate-schema", + name = "ast-generator", srcs = glob(["src/**/*.rs"]), aliases = aliases(), proc_macro_deps = all_crate_deps( diff --git a/rust/generate-schema/Cargo.toml b/rust/ast-generator/Cargo.toml similarity index 84% rename from rust/generate-schema/Cargo.toml rename to rust/ast-generator/Cargo.toml index 0eb36ecbc63..c04619f5d4f 100644 --- a/rust/generate-schema/Cargo.toml +++ b/rust/ast-generator/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "generate-schema" +name = "ast-generator" version = "0.1.0" edition = "2021" @@ -8,4 +8,3 @@ ungrammar = "1.16.1" proc-macro2 = "1.0.33" quote = "1.0.12" itertools = "0.10.1" - diff --git a/rust/generate-schema/rust.ungram b/rust/ast-generator/rust.ungram similarity index 100% rename from rust/generate-schema/rust.ungram rename to rust/ast-generator/rust.ungram diff --git a/rust/generate-schema/src/codegen.rs b/rust/ast-generator/src/codegen.rs similarity index 100% rename from rust/generate-schema/src/codegen.rs rename to rust/ast-generator/src/codegen.rs diff --git a/rust/generate-schema/src/codegen/grammar.rs b/rust/ast-generator/src/codegen/grammar.rs similarity index 100% rename from rust/generate-schema/src/codegen/grammar.rs rename to rust/ast-generator/src/codegen/grammar.rs diff --git a/rust/generate-schema/src/codegen/grammar/ast_src.rs b/rust/ast-generator/src/codegen/grammar/ast_src.rs similarity index 100% rename from rust/generate-schema/src/codegen/grammar/ast_src.rs rename to rust/ast-generator/src/codegen/grammar/ast_src.rs diff --git a/rust/generate-schema/src/flags.rs b/rust/ast-generator/src/flags.rs similarity index 100% rename from rust/generate-schema/src/flags.rs rename to rust/ast-generator/src/flags.rs diff --git a/rust/generate-schema/src/main.rs b/rust/ast-generator/src/main.rs similarity index 96% rename from rust/generate-schema/src/main.rs rename to rust/ast-generator/src/main.rs index 20e70f2344b..4d0c1acd81e 100644 --- a/rust/generate-schema/src/main.rs +++ b/rust/ast-generator/src/main.rs @@ -55,24 +55,24 @@ fn write_schema( let mut buf: Vec = Vec::new(); writeln!( buf, - "# Generated by `cargo generate-schema`, do not edit by hand.\n" + "# Generated by `ast-generator`, do not edit by hand.\n" )?; writeln!(buf, "from .prelude import *\n")?; for node in &grammar.enums { let super_classses = if let Some(cls) = super_types.get(&node.name) { - let super_classes: Vec = cls.iter().map(|x| class_name(x)).collect(); + let super_classes: Vec = cls.iter().map(class_name).collect(); super_classes.join(",") } else { "AstNode".to_owned() }; writeln!(buf, "class {}({}):", class_name(&node.name), super_classses)?; writeln!(buf, " pass")?; - writeln!(buf, "")?; + writeln!(buf)?; } for node in &grammar.nodes { let super_classses = if let Some(cls) = super_types.get(&node.name) { - let super_classes: Vec = cls.iter().map(|x| class_name(x)).collect(); + let super_classes: Vec = cls.iter().map(class_name).collect(); super_classes.join(",") } else { "AstNode".to_owned() @@ -111,7 +111,7 @@ fn write_schema( if empty { writeln!(buf, " pass")?; } - writeln!(buf, "")?; + writeln!(buf)?; } Ok(String::from_utf8_lossy(&buf).to_string()) } @@ -408,7 +408,7 @@ fn write_extractor(grammar: &AstSrc) -> std::io::Result { let mut buf: Vec = Vec::new(); writeln!( buf, - "//! Generated by `cargo generate-schema`, do not edit by hand.\n + "//! Generated by `ast-generator`, do not edit by hand.\n use crate::generated; use super::base::{{TextValue, Translator}}; use crate::trap::{{Label, TrapId}}; @@ -462,7 +462,7 @@ impl Translator {{ type_name, class_name )?; - for field in get_fields(&node) { + for field in get_fields(node) { if &field.tp == "SyntaxToken" { continue; } @@ -500,7 +500,7 @@ impl Translator {{ class_name )?; writeln!(buf, " id: TrapId::Star,")?; - for field in get_fields(&node) { + for field in get_fields(node) { if field.tp == "SyntaxToken" { continue; } @@ -523,7 +523,7 @@ impl Translator {{ } fn main() -> std::io::Result<()> { - let grammar: Grammar = fs::read_to_string(project_root().join("generate-schema/rust.ungram")) + let grammar: Grammar = fs::read_to_string(project_root().join("ast-generator/rust.ungram")) .unwrap() .parse() .unwrap(); @@ -537,9 +537,7 @@ fn main() -> std::io::Result<()> { let mut super_types: BTreeMap> = BTreeMap::new(); for node in &grammar.enums { for variant in &node.variants { - let set = super_types - .entry(variant.to_owned()) - .or_insert_with(|| BTreeSet::new()); + let set = super_types.entry(variant.to_owned()).or_default(); set.insert(node.name.to_owned()); } } diff --git a/rust/extractor/src/translate/generated.rs b/rust/extractor/src/translate/generated.rs index d7b7760febf..f6f2df6483b 100644 --- a/rust/extractor/src/translate/generated.rs +++ b/rust/extractor/src/translate/generated.rs @@ -1,4 +1,4 @@ -//! Generated by `cargo generate-schema`, do not edit by hand. +//! Generated by `ast-generator`, do not edit by hand. use super::base::{TextValue, Translator}; use crate::generated; diff --git a/rust/generate-schema/Cargo.lock b/rust/generate-schema/Cargo.lock deleted file mode 100644 index 9ca5960b780..00000000000 --- a/rust/generate-schema/Cargo.lock +++ /dev/null @@ -1,16 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "generate-schema" -version = "0.1.0" -dependencies = [ - "ungrammar", -] - -[[package]] -name = "ungrammar" -version = "1.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e5df347f0bf3ec1d670aad6ca5c6a1859cd9ea61d2113125794654ccced68f" diff --git a/rust/schema/ast.py b/rust/schema/ast.py index 13eb54e7acf..665afe12b7d 100644 --- a/rust/schema/ast.py +++ b/rust/schema/ast.py @@ -1,4 +1,4 @@ -# Generated by `cargo generate-schema`, do not edit by hand. +# Generated by `ast-generator`, do not edit by hand. from .prelude import * @@ -663,4 +663,3 @@ class YeetExpr(Expr): class YieldExpr(Expr): attrs: list["Attr"] | child expr: optional["Expr"] | child -