Skip to content

Commit 7e9a17b

Browse files
committed
Revert back to Visibility::PublicIn(String) cache a fn.
1 parent 3c702cf commit 7e9a17b

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum LexerKind {
3838

3939
/// Specify the visibility of the module generated by [CTLexerBuilder].
4040
#[derive(Clone, PartialEq, Eq, Debug)]
41-
pub enum Visibility<'a> {
41+
pub enum Visibility {
4242
/// Module-level visibility only.
4343
Private,
4444
/// `pub`
@@ -50,10 +50,10 @@ pub enum Visibility<'a> {
5050
/// `pub(crate)`
5151
PublicCrate,
5252
/// `pub(in {arg})`
53-
PublicIn(&'a str),
53+
PublicIn(String),
5454
}
5555

56-
impl ToTokens for Visibility<'_> {
56+
impl ToTokens for Visibility {
5757
fn to_tokens(&self, tokens: &mut TokenStream) {
5858
tokens.extend(match self {
5959
Visibility::Private => quote!(),
@@ -128,7 +128,7 @@ where
128128
output_path: Option<PathBuf>,
129129
lexerkind: LexerKind,
130130
mod_name: Option<&'a str>,
131-
visibility: Visibility<'a>,
131+
visibility: Visibility,
132132
rust_edition: RustEdition,
133133
rule_ids_map: Option<HashMap<String, LexerTypesT::StorageT>>,
134134
allow_missing_terms_in_lexer: bool,
@@ -297,7 +297,7 @@ where
297297
}
298298

299299
/// Set the visibility of the generated module to `vis`. Defaults to `Visibility::Private`.
300-
pub fn visibility(mut self, vis: Visibility<'a>) -> Self {
300+
pub fn visibility(mut self, vis: Visibility) -> Self {
301301
self.visibility = vis;
302302
self
303303
}

lrpar/src/lib/ctbuilder.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
95105
impl<StorageT> fmt::Display for CTConflictsError<StorageT>
96106
where
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

Comments
 (0)