зеркало из https://github.com/github/codeql.git
Rust: rename `generate-schema -> ast-generator`
This commit is contained in:
Родитель
5a4cd1c578
Коммит
96dda8808c
|
@ -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"
|
||||
|
|
|
@ -7,7 +7,7 @@ members = [
|
|||
"ruby/extractor",
|
||||
"rust/extractor",
|
||||
"rust/extractor/macros",
|
||||
"rust/generate-schema",
|
||||
"rust/ast-generator",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
|
|
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -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(
|
|
@ -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"
|
||||
|
|
@ -55,24 +55,24 @@ fn write_schema(
|
|||
let mut buf: Vec<u8> = 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<String> = cls.iter().map(|x| class_name(x)).collect();
|
||||
let super_classes: Vec<String> = 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<String> = cls.iter().map(|x| class_name(x)).collect();
|
||||
let super_classes: Vec<String> = 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<String> {
|
|||
let mut buf: Vec<u8> = 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<String, BTreeSet<String>> = 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());
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче