зеркало из 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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ast-generator"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"itertools 0.10.5",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"ungrammar",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atomic"
|
name = "atomic"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
|
@ -681,16 +691,6 @@ version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7ab85b9b05e3978cc9a9cf8fea7f01b494e1a09ed3037e16ba39edc7a29eb61a"
|
checksum = "7ab85b9b05e3978cc9a9cf8fea7f01b494e1a09ed3037e16ba39edc7a29eb61a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "generate-schema"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"itertools 0.10.5",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"ungrammar",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
|
|
@ -7,7 +7,7 @@ members = [
|
||||||
"ruby/extractor",
|
"ruby/extractor",
|
||||||
"rust/extractor",
|
"rust/extractor",
|
||||||
"rust/extractor/macros",
|
"rust/extractor/macros",
|
||||||
"rust/generate-schema",
|
"rust/ast-generator",
|
||||||
]
|
]
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|
|
@ -61,7 +61,7 @@ r.from_cargo(
|
||||||
"//ruby/extractor:Cargo.toml",
|
"//ruby/extractor:Cargo.toml",
|
||||||
"//rust/extractor:Cargo.toml",
|
"//rust/extractor:Cargo.toml",
|
||||||
"//rust/extractor/macros:Cargo.toml",
|
"//rust/extractor/macros:Cargo.toml",
|
||||||
"//rust/generate-schema:Cargo.toml",
|
"//rust/ast-generator:Cargo.toml",
|
||||||
"//shared/tree-sitter-extractor:Cargo.toml",
|
"//shared/tree-sitter-extractor:Cargo.toml",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
load("//misc/bazel:rust.bzl", "codeql_rust_binary")
|
load("//misc/bazel:rust.bzl", "codeql_rust_binary")
|
||||||
|
|
||||||
codeql_rust_binary(
|
codeql_rust_binary(
|
||||||
name = "generate-schema",
|
name = "ast-generator",
|
||||||
srcs = glob(["src/**/*.rs"]),
|
srcs = glob(["src/**/*.rs"]),
|
||||||
aliases = aliases(),
|
aliases = aliases(),
|
||||||
proc_macro_deps = all_crate_deps(
|
proc_macro_deps = all_crate_deps(
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "generate-schema"
|
name = "ast-generator"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -8,4 +8,3 @@ ungrammar = "1.16.1"
|
||||||
proc-macro2 = "1.0.33"
|
proc-macro2 = "1.0.33"
|
||||||
quote = "1.0.12"
|
quote = "1.0.12"
|
||||||
itertools = "0.10.1"
|
itertools = "0.10.1"
|
||||||
|
|
|
@ -55,24 +55,24 @@ fn write_schema(
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
writeln!(
|
writeln!(
|
||||||
buf,
|
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")?;
|
writeln!(buf, "from .prelude import *\n")?;
|
||||||
|
|
||||||
for node in &grammar.enums {
|
for node in &grammar.enums {
|
||||||
let super_classses = if let Some(cls) = super_types.get(&node.name) {
|
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(",")
|
super_classes.join(",")
|
||||||
} else {
|
} else {
|
||||||
"AstNode".to_owned()
|
"AstNode".to_owned()
|
||||||
};
|
};
|
||||||
writeln!(buf, "class {}({}):", class_name(&node.name), super_classses)?;
|
writeln!(buf, "class {}({}):", class_name(&node.name), super_classses)?;
|
||||||
writeln!(buf, " pass")?;
|
writeln!(buf, " pass")?;
|
||||||
writeln!(buf, "")?;
|
writeln!(buf)?;
|
||||||
}
|
}
|
||||||
for node in &grammar.nodes {
|
for node in &grammar.nodes {
|
||||||
let super_classses = if let Some(cls) = super_types.get(&node.name) {
|
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(",")
|
super_classes.join(",")
|
||||||
} else {
|
} else {
|
||||||
"AstNode".to_owned()
|
"AstNode".to_owned()
|
||||||
|
@ -111,7 +111,7 @@ fn write_schema(
|
||||||
if empty {
|
if empty {
|
||||||
writeln!(buf, " pass")?;
|
writeln!(buf, " pass")?;
|
||||||
}
|
}
|
||||||
writeln!(buf, "")?;
|
writeln!(buf)?;
|
||||||
}
|
}
|
||||||
Ok(String::from_utf8_lossy(&buf).to_string())
|
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();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
writeln!(
|
writeln!(
|
||||||
buf,
|
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 crate::generated;
|
||||||
use super::base::{{TextValue, Translator}};
|
use super::base::{{TextValue, Translator}};
|
||||||
use crate::trap::{{Label, TrapId}};
|
use crate::trap::{{Label, TrapId}};
|
||||||
|
@ -462,7 +462,7 @@ impl Translator {{
|
||||||
type_name,
|
type_name,
|
||||||
class_name
|
class_name
|
||||||
)?;
|
)?;
|
||||||
for field in get_fields(&node) {
|
for field in get_fields(node) {
|
||||||
if &field.tp == "SyntaxToken" {
|
if &field.tp == "SyntaxToken" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -500,7 +500,7 @@ impl Translator {{
|
||||||
class_name
|
class_name
|
||||||
)?;
|
)?;
|
||||||
writeln!(buf, " id: TrapId::Star,")?;
|
writeln!(buf, " id: TrapId::Star,")?;
|
||||||
for field in get_fields(&node) {
|
for field in get_fields(node) {
|
||||||
if field.tp == "SyntaxToken" {
|
if field.tp == "SyntaxToken" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ impl Translator {{
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
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()
|
.unwrap()
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -537,9 +537,7 @@ fn main() -> std::io::Result<()> {
|
||||||
let mut super_types: BTreeMap<String, BTreeSet<String>> = BTreeMap::new();
|
let mut super_types: BTreeMap<String, BTreeSet<String>> = BTreeMap::new();
|
||||||
for node in &grammar.enums {
|
for node in &grammar.enums {
|
||||||
for variant in &node.variants {
|
for variant in &node.variants {
|
||||||
let set = super_types
|
let set = super_types.entry(variant.to_owned()).or_default();
|
||||||
.entry(variant.to_owned())
|
|
||||||
.or_insert_with(|| BTreeSet::new());
|
|
||||||
set.insert(node.name.to_owned());
|
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 super::base::{TextValue, Translator};
|
||||||
use crate::generated;
|
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 *
|
from .prelude import *
|
||||||
|
|
||||||
|
@ -663,4 +663,3 @@ class YeetExpr(Expr):
|
||||||
class YieldExpr(Expr):
|
class YieldExpr(Expr):
|
||||||
attrs: list["Attr"] | child
|
attrs: list["Attr"] | child
|
||||||
expr: optional["Expr"] | child
|
expr: optional["Expr"] | child
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче