11use std:: collections:: { BTreeMap , BTreeSet } ;
22
33use crate :: captures:: Captures ;
4- use crate :: tree_builder:: FreshScope ;
54use crate :: { Ast , FieldId , Id , KindId , NodeContent , Range , TranslatorHandle } ;
65
76/// Context for building new AST nodes during a transformation.
87///
98/// Used by the `tree!` and `trees!` macros. Holds a mutable reference to the
10- /// AST, a reference to the captures from a query match, a `FreshScope` for
11- /// generating unique identifiers, and a mutable reference to a user-defined
12- /// context of type `C`.
9+ /// AST, a reference to the captures from a query match, and a mutable reference
10+ /// to a user-defined context of type `C`.
1311///
1412/// The user context `C` is shared across rules via the framework's driver:
1513/// outer rules can write to it before recursive translation, and inner rules
@@ -32,7 +30,6 @@ use crate::{Ast, FieldId, Id, KindId, NodeContent, Range, TranslatorHandle};
3230pub struct BuildCtx < ' a , C : ' a = ( ) > {
3331 pub ast : & ' a mut Ast ,
3432 pub captures : & ' a Captures ,
35- pub fresh : & ' a FreshScope ,
3633 /// Source range of the node matched by the current rule.
3734 ///
3835 /// The `rule!` macro applies this range to locally-created result roots
@@ -54,16 +51,10 @@ pub struct BuildCtx<'a, C: 'a = ()> {
5451}
5552
5653impl < ' a , C > BuildCtx < ' a , C > {
57- pub fn new (
58- ast : & ' a mut Ast ,
59- captures : & ' a Captures ,
60- fresh : & ' a FreshScope ,
61- user_ctx : & ' a mut C ,
62- ) -> Self {
54+ pub fn new ( ast : & ' a mut Ast , captures : & ' a Captures , user_ctx : & ' a mut C ) -> Self {
6355 Self {
6456 ast,
6557 captures,
66- fresh,
6758 source_range : None ,
6859 user_ctx,
6960 translator : None ,
@@ -75,14 +66,12 @@ impl<'a, C> BuildCtx<'a, C> {
7566 pub fn with_source_range (
7667 ast : & ' a mut Ast ,
7768 captures : & ' a Captures ,
78- fresh : & ' a FreshScope ,
7969 source_range : Option < Range > ,
8070 user_ctx : & ' a mut C ,
8171 ) -> Self {
8272 Self {
8373 ast,
8474 captures,
85- fresh,
8675 source_range,
8776 user_ctx,
8877 translator : None ,
@@ -95,15 +84,13 @@ impl<'a, C> BuildCtx<'a, C> {
9584 pub fn with_translator (
9685 ast : & ' a mut Ast ,
9786 captures : & ' a Captures ,
98- fresh : & ' a FreshScope ,
9987 source_range : Option < Range > ,
10088 user_ctx : & ' a mut C ,
10189 translator : TranslatorHandle < ' a , C > ,
10290 ) -> Self {
10391 Self {
10492 ast,
10593 captures,
106- fresh,
10794 source_range,
10895 user_ctx,
10996 translator : Some ( translator) ,
@@ -262,12 +249,6 @@ impl<'a, C> BuildCtx<'a, C> {
262249 let source_range = self . source_range_of ( source) . map ( Range :: empty_at_start) ;
263250 self . literal_with_source_range ( kind, value, source_range)
264251 }
265-
266- /// Create a leaf node with an auto-generated unique name.
267- pub fn fresh ( & mut self , kind : & ' static str , name : & str ) -> Id {
268- let generated = self . fresh . resolve ( name) ;
269- self . create_named_token_with_range ( kind, generated, None )
270- }
271252}
272253
273254impl < C : Clone > BuildCtx < ' _ , C > {
@@ -302,7 +283,7 @@ impl<C: Clone> BuildCtx<'_, C> {
302283
303284 /// Run `f` with a temporary child [`BuildCtx`] whose `user_ctx` is
304285 /// a fresh clone of the current one, sharing everything else
305- /// (`ast`, `captures`, `fresh`, source ranges, `translator`) by re-borrow.
286+ /// (`ast`, `captures`, source ranges, `translator`) by re-borrow.
306287 /// Nodes constructed through the child remain part of the current rule
307288 /// invocation. Any mutations `f` makes to the child's `user_ctx`
308289 /// are discarded when it returns — no restore needed, because the
@@ -334,7 +315,6 @@ impl<C: Clone> BuildCtx<'_, C> {
334315 let mut child = BuildCtx {
335316 ast : & mut * self . ast ,
336317 captures : self . captures ,
337- fresh : self . fresh ,
338318 source_range : self . source_range ,
339319 user_ctx : & mut child_user_ctx,
340320 translator : self . translator ,
0 commit comments