@@ -13,11 +13,14 @@ pub struct LanguageSpec {
1313 pub prefix : & ' static str ,
1414 pub ts_language : tree_sitter:: Language ,
1515 pub node_types : & ' static str ,
16- /// Optional yeast desugaring configuration. When set, the parsed
17- /// tree is rewritten through yeast before TRAP extraction. The
18- /// config's `output_node_types_yaml` (if set) provides the schema
19- /// used both at runtime (for the rewriter) and for TRAP validation.
20- pub desugar : Option < yeast:: DesugaringConfig > ,
16+ /// Optional desugarer. When set, the parsed tree is rewritten through
17+ /// the desugarer before TRAP extraction. The desugarer's
18+ /// `output_node_types_yaml()` (if set) provides the schema used both
19+ /// at runtime (for the rewriter) and for TRAP validation.
20+ ///
21+ /// `Box<dyn yeast::Desugarer>` so the shared extractor is agnostic to
22+ /// the user-defined context type the desugarer uses internally.
23+ pub desugar : Option < Box < dyn yeast:: Desugarer > > ,
2124 pub file_globs : Vec < String > ,
2225}
2326
@@ -91,35 +94,22 @@ impl Extractor {
9194 . collect ( ) ;
9295
9396 let mut schemas = vec ! [ ] ;
94- let mut yeast_runners = Vec :: new ( ) ;
9597 for lang in & self . languages {
96- let effective_node_types: String =
97- match lang. desugar . as_ref ( ) . and_then ( |c| c. output_node_types_yaml ) {
98- Some ( yaml) => yeast:: node_types_yaml:: convert ( yaml) . map_err ( |e| {
99- std:: io:: Error :: other ( format ! (
100- "Failed to convert YAML node-types to JSON for {}: {e}" ,
101- lang. prefix
102- ) )
103- } ) ?,
104- None => lang. node_types . to_string ( ) ,
105- } ;
106- let schema = node_types:: read_node_types_str ( lang. prefix , & effective_node_types) ?;
107- schemas. push ( schema) ;
108-
109- // Build the yeast runner once per language so the YAML schema
110- // isn't re-parsed for every file.
111- let yeast_runner = lang
98+ let effective_node_types: String = match lang
11299 . desugar
113100 . as_ref ( )
114- . map ( |config| yeast :: Runner :: from_config ( lang . ts_language . clone ( ) , config ) )
115- . transpose ( )
116- . map_err ( |e| {
101+ . and_then ( |d| d . output_node_types_yaml ( ) )
102+ {
103+ Some ( yaml ) => yeast :: node_types_yaml :: convert ( yaml ) . map_err ( |e| {
117104 std:: io:: Error :: other ( format ! (
118- "Failed to build desugaring runner for {}: {e}" ,
105+ "Failed to convert YAML node-types to JSON for {}: {e}" ,
119106 lang. prefix
120107 ) )
121- } ) ?;
122- yeast_runners. push ( yeast_runner) ;
108+ } ) ?,
109+ None => lang. node_types . to_string ( ) ,
110+ } ;
111+ let schema = node_types:: read_node_types_str ( lang. prefix , & effective_node_types) ?;
112+ schemas. push ( schema) ;
123113 }
124114
125115 // Construct a single globset containing all language globs,
@@ -194,7 +184,7 @@ impl Extractor {
194184 & path,
195185 & source,
196186 & [ ] ,
197- yeast_runners [ i ] . as_ref ( ) ,
187+ lang . desugar . as_deref ( ) ,
198188 ) ;
199189 std:: fs:: create_dir_all ( src_archive_file. parent ( ) . unwrap ( ) ) ?;
200190 std:: fs:: copy ( & path, & src_archive_file) ?;
0 commit comments