Skip to content

Commit 247e54b

Browse files
authored
Merge pull request #22112 from github/tausbn/yeast-reify-output-schema-as-ast-types
2 parents 161c8c4 + 9e99a3c commit 247e54b

21 files changed

Lines changed: 2110 additions & 1092 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"shared/tree-sitter-extractor",
77
"shared/yeast",
88
"shared/yeast-macros",
9+
"shared/yeast-schema",
910
"ruby/extractor",
1011
"unified/extractor",
1112
"unified/extractor/tree-sitter-swift",

misc/bazel/3rdparty/tree_sitter_extractors_deps/defs.bzl

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/yeast-macros/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,43 @@ pub fn rule(input: TokenStream) -> TokenStream {
113113
Err(err) => err.to_compile_error().into(),
114114
}
115115
}
116+
117+
/// Bundle a list of YEAST rewrite rules with input/output node-types
118+
/// schema paths. Returns a `Vec<Rule>`; substitutable for
119+
/// `vec![rule!(...), ...]`.
120+
///
121+
/// Each comma-separated item in the bracketed list may be:
122+
///
123+
/// 1. A **bare rule body** `(query) => (template)` — the `rule!(...)`
124+
/// wrapper is implicit.
125+
/// 2. An explicit `rule!(...)` invocation, possibly chained as
126+
/// `rule!(...).repeated()` or path-prefixed as `yeast::rule!(...)`.
127+
/// 3. Any other expression returning a `Rule` (helper-function calls,
128+
/// conditionals).
129+
///
130+
/// ```ignore
131+
/// let translation_rules: Vec<yeast::Rule> = yeast::rules! {
132+
/// input: "tree-sitter-swift/node-types.yml",
133+
/// output: "ast_types.yml",
134+
/// [
135+
/// (source_file (_)* @cs) => (top_level body: {..cs}),
136+
/// (simple_identifier) @id => (name_expr identifier: (identifier #{id})),
137+
/// rule!((integer_literal) @lit => (int_literal #{lit})).repeated(),
138+
/// helper_fn(),
139+
/// ]
140+
/// };
141+
/// ```
142+
///
143+
/// Paths are resolved relative to the consuming crate's `CARGO_MANIFEST_DIR`
144+
/// (the same convention `include_str!` uses for relative paths). The
145+
/// resolved paths are also emitted as `include_str!` references so the
146+
/// consuming crate gets invalidated when a schema YAML changes, prepping
147+
/// the ground for compile-time type-checking against those schemas.
148+
#[proc_macro]
149+
pub fn rules(input: TokenStream) -> TokenStream {
150+
let input2: TokenStream2 = input.into();
151+
match parse::parse_rules_top(input2) {
152+
Ok(output) => output.into(),
153+
Err(err) => err.to_compile_error().into(),
154+
}
155+
}

0 commit comments

Comments
 (0)