@@ -92,6 +92,16 @@ impl<A: ToTokens, B: ToTokens> ToTokens for QuoteTuple<(A, B)> {
9292 }
9393}
9494
95+ /// The wrapped `&str` value will be emitted with a call to `to_string()`
96+ struct QuoteToString < ' a > ( & ' a str ) ;
97+
98+ impl ToTokens for QuoteToString < ' _ > {
99+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
100+ let x = & self . 0 ;
101+ tokens. append_all ( quote ! { #x. to_string( ) } ) ;
102+ }
103+ }
104+
95105impl < StorageT > fmt:: Display for CTConflictsError < StorageT >
96106where
97107 StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
@@ -149,7 +159,7 @@ impl Error for ErrorString {}
149159
150160/// Specify the visibility of the module generated by `CTBuilder`.
151161#[ derive( Clone , PartialEq , Eq , Debug ) ]
152- pub enum Visibility < ' a > {
162+ pub enum Visibility {
153163 /// Module-level visibility only.
154164 Private ,
155165 /// `pub`
@@ -161,7 +171,7 @@ pub enum Visibility<'a> {
161171 /// `pub(crate)`
162172 PublicCrate ,
163173 /// `pub(in {arg})`
164- PublicIn ( & ' a str ) ,
174+ PublicIn ( String ) ,
165175}
166176
167177/// Specifies the [Rust Edition] that will be emitted during code generation.
@@ -174,7 +184,7 @@ pub enum RustEdition {
174184 Rust2021 ,
175185}
176186
177- impl ToTokens for Visibility < ' _ > {
187+ impl ToTokens for Visibility {
178188 fn to_tokens ( & self , tokens : & mut TokenStream ) {
179189 tokens. extend ( match self {
180190 Visibility :: Private => quote ! ( ) ,
@@ -190,17 +200,19 @@ impl ToTokens for Visibility<'_> {
190200 }
191201}
192202
193- impl Visibility < ' _ > {
203+ impl Visibility {
194204 fn to_variant_tokens ( & self , tokens : & mut TokenStream ) {
195205 tokens. extend ( match self {
196- Visibility :: Private => quote ! ( :: lrpar:: Visibility :: Private ) ,
197- Visibility :: Public => quote ! ( :: lrpar:: Visibility :: Public ) ,
198- Visibility :: PublicSuper => quote ! ( :: lrpar:: Visibility :: PublicSuper ) ,
199- Visibility :: PublicSelf => quote ! ( :: lrpar:: Visibility :: PublicSelf ) ,
200- Visibility :: PublicCrate => quote ! ( :: lrpar:: Visibility :: PublicCrate ) ,
201- Visibility :: PublicIn ( data) => quote ! ( :: lrpar:: Visibility :: PublicIn ( #data) ) ,
206+ Visibility :: Private => quote ! ( :: lrpar:: Visibility :: Private ) ,
207+ Visibility :: Public => quote ! ( :: lrpar:: Visibility :: Public ) ,
208+ Visibility :: PublicSuper => quote ! ( :: lrpar:: Visibility :: PublicSuper ) ,
209+ Visibility :: PublicSelf => quote ! ( :: lrpar:: Visibility :: PublicSelf ) ,
210+ Visibility :: PublicCrate => quote ! ( :: lrpar:: Visibility :: PublicCrate ) ,
211+ Visibility :: PublicIn ( data) => {
212+ let data = QuoteToString ( data) ;
213+ quote ! ( :: lrpar:: Visibility :: PublicIn ( #data) )
202214 }
203- )
215+ } )
204216 }
205217}
206218
@@ -222,7 +234,7 @@ where
222234 error_on_conflicts : bool ,
223235 warnings_are_errors : bool ,
224236 show_warnings : bool ,
225- visibility : Visibility < ' a > ,
237+ visibility : Visibility ,
226238 rust_edition : RustEdition ,
227239 phantom : PhantomData < LexerTypesT > ,
228240}
@@ -353,7 +365,7 @@ where
353365 }
354366
355367 /// Set the visibility of the generated module to `vis`. Defaults to `Visibility::Private`.
356- pub fn visibility ( mut self , vis : Visibility < ' a > ) -> Self {
368+ pub fn visibility ( mut self , vis : Visibility ) -> Self {
357369 self . visibility = vis;
358370 self
359371 }
@@ -811,17 +823,19 @@ where
811823 let cache_module = quote ! {
812824 #[ allow( unused) ]
813825 mod _cache_information_ {
814- use :: lrpar:: { RecoveryKind , Visibility } ;
826+ use :: lrpar:: { RecoveryKind , Visibility , RustEdition } ;
815827 use :: cfgrammar:: yacc:: YaccKind ;
816828
817829 const BUILD_TIME : & ' static str = #build_time;
818830 const GRAMMAR_PATH : & ' static str = #grammar_path;
819831 const MOD_NAME : Option <& ' static str > = #mod_name;
820832 const RECOVERER : RecoveryKind = #recoverer;
821833 const YACC_KIND : YaccKind = #yacckind;
822- const VISIBILITY : Visibility = #visibility;
823834 const ERROR_ON_CONFLICTS : bool = #error_on_conflicts;
824835 const RULE_IDS_MAP : [ ( usize , & ' static str ) ; #rule_map_len] = [ #( #rule_map, ) * ] ;
836+ fn visibility( ) -> Visibility {
837+ #visibility
838+ }
825839 }
826840 } ;
827841 cache_module. to_string ( )
0 commit comments