Skip to content

Commit d9faae5

Browse files
tausbnCopilot
andcommitted
yeast: Support separate output node types in extractor generator
Language and LanguageSpec gain optional output_node_types field. When set, the generator produces dbscheme/QL from the output types and the extractor validates TRAP against them. All existing extractors pass None (no behavior change). Ruby extract() calls gain vec![] for the new rules parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ccb3c6d commit d9faae5

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

ql/extractor/src/generator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ pub fn run(options: Options) -> std::io::Result<()> {
2121
Language {
2222
name: "QL".to_owned(),
2323
node_types: tree_sitter_ql::NODE_TYPES,
24+
output_node_types: None,
2425
},
2526
Language {
2627
name: "Dbscheme".to_owned(),
2728
node_types: tree_sitter_ql_dbscheme::NODE_TYPES,
29+
output_node_types: None,
2830
},
2931
Language {
3032
name: "Blame".to_owned(),
3133
node_types: tree_sitter_blame::NODE_TYPES,
34+
output_node_types: None,
3235
},
3336
Language {
3437
name: "JSON".to_owned(),
3538
node_types: tree_sitter_json::NODE_TYPES,
39+
output_node_types: None,
3640
},
3741
];
3842

ruby/extractor/src/generator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ pub fn run(options: Options) -> std::io::Result<()> {
2121
Language {
2222
name: "Ruby".to_owned(),
2323
node_types: tree_sitter_ruby::NODE_TYPES,
24+
output_node_types: None,
2425
},
2526
Language {
2627
name: "Erb".to_owned(),
2728
node_types: tree_sitter_embedded_template::NODE_TYPES,
29+
output_node_types: None,
2830
},
2931
];
3032

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
pub struct Language {
22
pub name: String,
33
pub node_types: &'static str,
4+
/// If set, the generator uses these node types for the dbscheme/QL library
5+
/// instead of `node_types`. This is useful when desugaring transforms produce
6+
/// an AST whose shape differs from the tree-sitter grammar.
7+
pub output_node_types: Option<&'static str>,
48
}

shared/tree-sitter-extractor/src/generator/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub fn generate(
6868
let token_name = format!("{}_token", &prefix);
6969
let tokeninfo_name = format!("{}_tokeninfo", &prefix);
7070
let reserved_word_name = format!("{}_reserved_word", &prefix);
71-
let nodes = node_types::read_node_types_str(&prefix, language.node_types)?;
71+
let effective_node_types = language.output_node_types.unwrap_or(language.node_types);
72+
let nodes = node_types::read_node_types_str(&prefix, effective_node_types)?;
7273
let (dbscheme_entries, mut ast_node_members, token_kinds) = convert_nodes(&nodes);
7374
ast_node_members.insert(&token_name);
7475
writeln!(&mut dbscheme_writer, "/*- {} dbscheme -*/", language.name)?;

0 commit comments

Comments
 (0)