Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! <img src="https://raw.githubusercontent.com/maciejhirsz/logos/master/logos.svg?sanitize=true" alt="Logos logo" width="250" align="right">
2 //!
3 //! # Logos
4 //!
5 //! This is a `#[derive]` macro crate, [for documentation go to main crate](https://docs.rs/logos).
6
7 // The `quote!` macro requires deep recursion.
8 #![recursion_limit = "196"]
9 #![doc(html_logo_url = "https://maciej.codes/kosz/logos.png")]
10
11 mod errorrust-analyzer cargo logos-codegen 0.15.1 error/;
12 mod generatorrust-analyzer cargo logos-codegen 0.15.1 generator/;
13 #[cfg(not(feature = "fuzzing"))]
14 mod graphrust-analyzer cargo logos-codegen 0.15.1 graph/;
15 #[cfg(feature = "fuzzing")]
16 pub mod graphrust-analyzer cargo logos-codegen 0.15.1 graph/;
17 mod leafrust-analyzer cargo logos-codegen 0.15.1 leaf/;
18 #[cfg(not(feature = "fuzzing"))]
19 mod mirrust-analyzer cargo logos-codegen 0.15.1 mir/;
20 #[cfg(feature = "fuzzing")]
21 pub mod mirrust-analyzer cargo logos-codegen 0.15.1 mir/;
22 mod parserrust-analyzer cargo logos-codegen 0.15.1 parser/;
23 mod utilrust-analyzer cargo logos-codegen 0.15.1 util/;
24
25 #[macro_use]
26 #[allow(missing_docs)]
27 mod macrosrust-analyzer cargo logos-codegen 0.15.1 macros/;
28
29 use generatorrust-analyzer cargo logos-codegen 0.15.1 generator/::Generatorrust-analyzer cargo logos-codegen 0.15.1 generator/Generator#;
30 use graphrust-analyzer cargo logos-codegen 0.15.1 graph/::{DisambiguationErrorrust-analyzer cargo logos-codegen 0.15.1 graph/DisambiguationError#, Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#, Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#, Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#};
31 use leafrust-analyzer cargo logos-codegen 0.15.1 leaf/::Leafrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#;
32 use parserrust-analyzer cargo logos-codegen 0.15.1 parser/::{IgnoreFlagsrust-analyzer cargo logos-codegen 0.15.1 parser/ignore_flags/IgnoreFlags#, Moderust-analyzer cargo logos-codegen 0.15.1 parser/Mode#, Parserrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#};
33 use quoterust-analyzer cargo quote 1.0.40 crate/::ToTokensrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens#;
34 use utilrust-analyzer cargo logos-codegen 0.15.1 util/::MaybeVoidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#;
35
36 use proc_macro2rust-analyzer cargo proc-macro2 1.0.95 crate/::{Delimiterrust-analyzer cargo proc-macro2 1.0.95 Delimiter#, TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#, TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#};
37 use quoterust-analyzer cargo quote 1.0.40 crate/::quoterust-analyzer cargo quote 1.0.40 quote!;
38 use synrust-analyzer cargo syn 2.0.101 crate/::parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/;
39 use synrust-analyzer cargo syn 2.0.101 crate/::spannedrust-analyzer cargo syn 2.0.101 spanned/::Spannedrust-analyzer cargo syn 2.0.101 spanned/Spanned#;
40 use synrust-analyzer cargo syn 2.0.101 crate/::{Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#, ItemEnumrust-analyzer cargo syn 2.0.101 item/ItemEnum#};
41
42 const LOGOS_ATTRrust-analyzer cargo logos-codegen 0.15.1 LOGOS_ATTR.: &str = "logos";
43 const ERROR_ATTRrust-analyzer cargo logos-codegen 0.15.1 ERROR_ATTR.: &str = "error";
44 const TOKEN_ATTRrust-analyzer cargo logos-codegen 0.15.1 TOKEN_ATTR.: &str = "token";
45 const REGEX_ATTRrust-analyzer cargo logos-codegen 0.15.1 REGEX_ATTR.: &str = "regex";
46
47 /// Generate a `Logos` implementation for the given struct, provided as a stream of rust tokens.
48 pub fn generaterust-analyzer cargo logos-codegen 0.15.1 generate().(input: TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream# {
49 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Reading input token streams");
50
51 let mut item: ItemEnumrust-analyzer cargo syn 2.0.101 item/ItemEnum# = synrust-analyzer cargo syn 2.0.101 crate/::parse2rust-analyzer cargo syn 2.0.101 parse2().(input).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Logos can be only be derived for enums");
52
53 let name = &item.identrust-analyzer cargo syn 2.0.101 item/ItemEnum#ident.;
54
55 let mut parser = Parserrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#::defaultrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser][Default]default().();
56
57 for param in item.genericsrust-analyzer cargo syn 2.0.101 item/ItemEnum#generics..paramsrust-analyzer cargo syn 2.0.101 generics/Generics#params. {
58 parser.parse_genericrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]parse_generic().(param);
59 }
60
61 for attr in &mut item.attrsrust-analyzer cargo syn 2.0.101 item/ItemEnum#attrs. {
62 parser.try_parse_logosrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]try_parse_logos().(attr);
63 }
64
65 let mut ropes = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
66 let mut regex_ids = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
67 let mut graph = Graphrust-analyzer cargo logos-codegen 0.15.1 graph/Graph#::newrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]new().();
68
69 {
70 let errors = &mut parser.errorsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#errors.;
71
72 for mut skip in parser.skipsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#skips..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#) {
73 match skip
74 .literalrust-analyzer cargo logos-codegen 0.15.1 parser/skip/Skip#literal.
75 .to_mirrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]to_mir().(&parser.subpatternsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#subpatterns., IgnoreFlagsrust-analyzer cargo logos-codegen 0.15.1 parser/ignore_flags/IgnoreFlags#::Emptyrust-analyzer cargo logos-codegen 0.15.1 parser/ignore_flags/impl#[IgnoreFlags]Empty., errors)
76 {
77 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mir) => {
78 let then = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(
79 Leafrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#::new_skiprust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]new_skip().(skip.literalrust-analyzer cargo logos-codegen 0.15.1 parser/skip/Skip#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().())
80 .priorityrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]priority().(skip.priorityrust-analyzer cargo logos-codegen 0.15.1 parser/skip/Skip#priority..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().()))
81 .callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]callback().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(skip.into_callbackrust-analyzer cargo logos-codegen 0.15.1 parser/skip/impl#[Skip]into_callback().())),
82 );
83 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, then);
84
85 regex_ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(id);
86 }
87 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
88 errors.errrust-analyzer cargo logos-codegen 0.15.1 error/impl#[Errors]err().(err, skip.literalrust-analyzer cargo logos-codegen 0.15.1 parser/skip/Skip#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().());
89 }
90 }
91 }
92 }
93
94 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Iterating through enum variants");
95
96 for variant in &mut item.variantsrust-analyzer cargo syn 2.0.101 item/ItemEnum#variants. {
97 let field = match &mut variant.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields. {
98 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unitrust-analyzer cargo syn 2.0.101 data/Fields#Unit# => MaybeVoidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#::Voidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#Void#,
99 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.101 data/Fields#Unnamed#(fields) => {
100 if fields.unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed..lenrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 {
101 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().(
102 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
103 "Logos currently only supports variants with one field, found {}",
104 fields.unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed..lenrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]len().(),
105 ),
106 fields.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().(),
107 );
108 }
109
110 let ty = &mut fields
111 .unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed.
112 .first_mutrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]first_mut().()
113 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Already checked len; qed")
114 .tyrust-analyzer cargo syn 2.0.101 data/Field#ty.;
115 let ty = parser.get_typerust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]get_type().(ty);
116
117 MaybeVoidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#::Somerust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#Some#(ty)
118 }
119 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Namedrust-analyzer cargo syn 2.0.101 data/Fields#Named#(fields) => {
120 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().("Logos doesn't support named fields yet.", fields.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().());
121
122 MaybeVoidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#::Voidrust-analyzer cargo logos-codegen 0.15.1 util/MaybeVoid#Void#
123 }
124 };
125
126 // Lazy leaf constructor to avoid cloning
127 let var_ident = &variant.identrust-analyzer cargo syn 2.0.101 data/Variant#ident.;
128 let leaf = move |span| Leafrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#::newrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]new().(var_ident, span).fieldrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]field().(field.clonerust-analyzer cargo logos-codegen 0.15.1 util/impl#[MaybeVoid][Clone]clone().());
129
130 for attr in &mut variant.attrsrust-analyzer cargo syn 2.0.101 data/Variant#attrs. {
131 let attr_name = match attr.pathrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]path().().get_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]get_ident().() {
132 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) => ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
133 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue,
134 };
135
136 match attr_name.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
137 ERROR_ATTRrust-analyzer cargo logos-codegen 0.15.1 ERROR_ATTR. => {
138 // TODO: Remove in future versions
139 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().(
140 "\
141 Since 0.13 Logos no longer requires the #[error] variant.\n\
142 \n\
143 For help with migration see release notes: \
144 https://github.com/maciejhirsz/logos/releases\
145 ",
146 attr.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().(),
147 );
148 }
149 TOKEN_ATTRrust-analyzer cargo logos-codegen 0.15.1 TOKEN_ATTR. => {
150 let definition = match parser.parse_definitionrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]parse_definition().(attr) {
151 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(definition) => definition,
152 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
153 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().("Expected #[token(...)]", attr.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().());
154 continue;
155 }
156 };
157
158 if definition.ignore_flagsrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#ignore_flags..is_emptyrust-analyzer cargo logos-codegen 0.15.1 parser/ignore_flags/impl#[IgnoreFlags]is_empty().() {
159 let bytes = definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..to_bytesrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]to_bytes().();
160 let then = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(
161 leaf(definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().())
162 .priorityrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]priority().(definition.priorityrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#priority..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(bytes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().2))
163 .callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]callback().(definition.callbackrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#callback.),
164 );
165
166 ropes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Roperust-analyzer cargo logos-codegen 0.15.1 graph/rope/Rope#::newrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]new().(bytes, then));
167 } else {
168 let mir = definition
169 .literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal.
170 .escape_regexrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]escape_regex().()
171 .to_mirrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]to_mir().(
172 &Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo logos-codegen 0.15.1 parser/subpattern/impl#[Subpatterns][Default]default().(),
173 definition.ignore_flagsrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#ignore_flags.,
174 &mut parser.errorsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#errors.,
175 )
176 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("The literal should be perfectly valid regex");
177
178 let then = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(
179 leaf(definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().())
180 .priorityrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]priority().(definition.priorityrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#priority..unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().()))
181 .callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]callback().(definition.callbackrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#callback.),
182 );
183 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, then);
184
185 regex_ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(id);
186 }
187 }
188 REGEX_ATTRrust-analyzer cargo logos-codegen 0.15.1 REGEX_ATTR. => {
189 let definition = match parser.parse_definitionrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]parse_definition().(attr) {
190 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(definition) => definition,
191 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
192 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().("Expected #[regex(...)]", attr.spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().());
193 continue;
194 }
195 };
196 let mir = match definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..to_mirrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]to_mir().(
197 &parser.subpatternsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#subpatterns.,
198 definition.ignore_flagsrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#ignore_flags.,
199 &mut parser.errorsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#errors.,
200 ) {
201 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mir) => mir,
202 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
203 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().(err, definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().());
204 continue;
205 }
206 };
207
208 let then = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(
209 leaf(definition.literalrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#literal..spanrust-analyzer cargo logos-codegen 0.15.1 parser/definition/impl#[Literal]span().())
210 .priorityrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]priority().(definition.priorityrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#priority..unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| mir.priorityrust-analyzer cargo logos-codegen 0.15.1 mir/impl#[Mir]priority().()))
211 .callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/impl#[`Leaf<'t>`]callback().(definition.callbackrust-analyzer cargo logos-codegen 0.15.1 parser/definition/Definition#callback.),
212 );
213 let id = graph.regexrust-analyzer cargo logos-codegen 0.15.1 graph/regex/impl#[`Graph<Leaf>`]regex().(mir, then);
214
215 regex_ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(id);
216 }
217 _ => (),
218 }
219 }
220 }
221
222 let mut root = Forkrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#::newrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]new().();
223
224 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Parsing additional options (extras, source, ...)");
225
226 let (error_type, error_callback) = parserrust-analyzer cargo logos-codegen 0.15.1 parser/::ErrorTyperust-analyzer cargo logos-codegen 0.15.1 parser/error_type/ErrorType#::unwraprust-analyzer cargo logos-codegen 0.15.1 parser/error_type/impl#[ErrorType]unwrap().(parser.error_typerust-analyzer cargo logos-codegen 0.15.1 parser/Parser#error_type..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().());
227 let extras = parser.extrasrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#extras..takerust-analyzer cargo logos-codegen 0.15.1 util/impl#[MaybeVoid]take().();
228 let source = parser
229 .sourcerust-analyzer cargo logos-codegen 0.15.1 parser/Parser#source.
230 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()
231 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(strip_wrapping_parensrust-analyzer cargo logos-codegen 0.15.1 strip_wrapping_parens().)
232 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(match parser.moderust-analyzer cargo logos-codegen 0.15.1 parser/Parser#mode. {
233 Moderust-analyzer cargo logos-codegen 0.15.1 parser/Mode#::Utf8rust-analyzer cargo logos-codegen 0.15.1 parser/Mode#Utf8# => quoterust-analyzer cargo quote 1.0.40 quote!!(str),
234 Moderust-analyzer cargo logos-codegen 0.15.1 parser/Mode#::Binaryrust-analyzer cargo logos-codegen 0.15.1 parser/Mode#Binary# => quoterust-analyzer cargo quote 1.0.40 quote!!([u8]),
235 });
236 let logos_path = parser
237 .logos_pathrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#logos_path.
238 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()
239 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(::logos));
240
241 let make_error_impl = match error_callback {
242 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(leafrust-analyzer cargo logos-codegen 0.15.1 leaf/::Callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/Callback#::Labelrust-analyzer cargo logos-codegen 0.15.1 leaf/Callback#Label#(label)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.40 quote!! {
243 #[inline]
244 fn make_error(mut lex: &mut #logos_path::Lexer<'s, Self>) {
245 use #logos_path::{Lexer, internal::LexerInternal};
246
247 let error = #label(&mut lex);
248 lex.set(Err(error));
249 }
250 }),
251 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(leafrust-analyzer cargo logos-codegen 0.15.1 leaf/::Callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/Callback#::Inlinerust-analyzer cargo logos-codegen 0.15.1 leaf/Callback#Inline#(inline)) => {
252 let leafrust-analyzer cargo logos-codegen 0.15.1 leaf/::InlineCallbackrust-analyzer cargo logos-codegen 0.15.1 leaf/InlineCallback# { argrust-analyzer cargo logos-codegen 0.15.1 leaf/InlineCallback#arg., bodyrust-analyzer cargo logos-codegen 0.15.1 leaf/InlineCallback#body., .. } = *rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().inline;
253
254 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.40 quote!! {
255 #[inline]
256 fn make_error(#arg: &mut #logos_path::Lexer<'s, Self>) {
257 use #logos_path::internal::LexerInternal;
258
259 let error = { #body };
260 #arg.set(Err(error))
261 }
262 })
263 }
264 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
265 };
266
267 let generics = parser.genericsrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]generics().();
268 let this = quoterust-analyzer cargo quote 1.0.40 quote!!(#name #generics);
269
270 let impl_logos = |body| {
271 quoterust-analyzer cargo quote 1.0.40 quote!! {
272 impl<'s> #logos_path::Logos<'s> for #this {
273 type Error = #error_type;
274
275 type Extras = #extras;
276
277 type Source = #source;
278
279 fn lex(lex: &mut #logos_path::Lexer<'s, Self>) {
280 #body
281 }
282
283 #make_error_impl
284 }
285 }
286 };
287
288 for id in regex_ids {
289 let fork = graph.fork_offrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]fork_off().(id);
290
291 root.mergerust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]merge().(fork, &mut graph);
292 }
293 for rope in ropes {
294 root.mergerust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]merge().(rope.into_forkrust-analyzer cargo logos-codegen 0.15.1 graph/rope/impl#[Rope]into_fork().(&mut graph), &mut graph);
295 }
296 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id) = root.missrust-analyzer cargo logos-codegen 0.15.1 graph/fork/Fork#miss..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
297 let fork = graph.fork_offrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]fork_off().(id);
298
299 if fork.branchesrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]branches().().nextrust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[`ForkIter<'_>`][Iterator]next().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
300 root.mergerust-analyzer cargo logos-codegen 0.15.1 graph/fork/impl#[Fork]merge().(fork, &mut graph);
301 } else {
302 break;
303 }
304 }
305
306 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Checking if any two tokens have the same priority");
307
308 for &DisambiguationErrorrust-analyzer cargo logos-codegen 0.15.1 graph/DisambiguationError#(a, b) in graph.errorsrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]errors().() {
309 let a = graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().a]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index()..unwrap_leafrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Node<Leaf>`]unwrap_leaf().();
310 let b = graph[rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index().b]rust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`][`Index<NodeId>`]index()..unwrap_leafrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Node<Leaf>`]unwrap_leaf().();
311 let disambiguate = a.priorityrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#priority. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
312
313 let mut err = |a: &Leafrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#, b: &Leafrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#| {
314 parser.errrust-analyzer cargo logos-codegen 0.15.1 parser/impl#[Parser]err().(
315 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
316 "\
317 A definition of variant `{a}` can match the same input as another definition of variant `{b}`.\n\
318 \n\
319 hint: Consider giving one definition a higher priority: \
320 #[{attr}(..., priority = {disambiguate})]\
321 ",
322 attr = match a.callbackrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#callback. {
323 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => "regex",
324 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => "skip"
325 }
326 ),
327 a.spanrust-analyzer cargo logos-codegen 0.15.1 leaf/Leaf#span.
328 );
329 };
330
331 err(a, b);
332 err(b, a);
333 }
334
335 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(errors) = parser.errorsrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#errors..renderrust-analyzer cargo logos-codegen 0.15.1 error/impl#[Errors]render().() {
336 return impl_logos(errors);
337 }
338
339 let root = graph.pushrust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]push().(root);
340
341 graph.shakerust-analyzer cargo logos-codegen 0.15.1 graph/impl#[`Graph<Leaf>`]shake().(root);
342
343 #[cfg(feature = "debug")]
344 {
345 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Generating graphs");
346
347 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = parser.export_dirrust-analyzer cargo logos-codegen 0.15.1 parser/Parser#export_dir. {
348 let path = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&path);
349 let dir = if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
350 path
351 } else {
352 path.parentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]parent().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(""))
353 };
354 match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::create_dir_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir_all().(dir) {
355 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => {
356 if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("dot"))
357 || path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
358 {
359 match graph.get_dotrust-analyzer cargo logos-codegen 0.15.1 graph/export/impl#[`Graph<Leaf>`]get_dot().() {
360 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => {
361 let dot_path = if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
362 path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}.dot", name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()))
363 } else {
364 path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().()
365 };
366 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(dot_path, s) {
367 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Error writing dot graph: {}", e);
368 }
369 }
370 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
371 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Error generating dot graph: {}", e);
372 }
373 }
374 }
375
376 if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("mmd"))
377 || path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
378 {
379 match graph.get_mermaidrust-analyzer cargo logos-codegen 0.15.1 graph/export/impl#[`Graph<Leaf>`]get_mermaid().() {
380 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => {
381 let mermaid_path = if path.extensionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]extension().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
382 path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}.mmd", name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()))
383 } else {
384 path.to_path_bufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_path_buf().()
385 };
386 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(mermaid_path, s) {
387 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Error writing mermaid graph: {}", e);
388 }
389 }
390 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
391 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Error generating mermaid graph: {}", e);
392 }
393 }
394 }
395 }
396 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
397 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Error creating graph export dir: {}", e);
398 }
399 }
400 }
401 }
402
403 debugrust-analyzer cargo logos-codegen 0.15.1 macros/debug!!("Generating code from graph:\n{graph:#?}");
404
405 let generator = Generatorrust-analyzer cargo logos-codegen 0.15.1 generator/Generator#::newrust-analyzer cargo logos-codegen 0.15.1 generator/impl#[`Generator<'a>`]new().(name, &this, root, &graph);
406
407 let body = generator.generaterust-analyzer cargo logos-codegen 0.15.1 generator/impl#[`Generator<'a>`]generate().();
408 impl_logos(quoterust-analyzer cargo quote 1.0.40 quote!! {
409 use #logos_path::internal::{LexerInternal, CallbackResult, SkipCallbackResult};
410
411 type Lexer<'s> = #logos_path::Lexer<'s, #this>;
412
413 fn _end<'s>(lex: &mut Lexer<'s>) {
414 lex.end()
415 }
416
417 fn _error<'s>(lex: &mut Lexer<'s>) {
418 lex.bump_unchecked(1);
419
420 lex.error();
421 }
422
423 #body
424 })
425 }
426
427 /// Strip all logos attributes from the given struct, allowing it to be used in code without `logos-derive` present.
428 pub fn strip_attributesrust-analyzer cargo logos-codegen 0.15.1 strip_attributes().(input: TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream# {
429 let mut item: ItemEnumrust-analyzer cargo syn 2.0.101 item/ItemEnum# = synrust-analyzer cargo syn 2.0.101 crate/::parse2rust-analyzer cargo syn 2.0.101 parse2().(input).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Logos can be only be derived for enums");
430
431 strip_attrs_from_vecrust-analyzer cargo logos-codegen 0.15.1 strip_attrs_from_vec().(&mut item.attrsrust-analyzer cargo syn 2.0.101 item/ItemEnum#attrs.);
432
433 for attr in &mut item.attrsrust-analyzer cargo syn 2.0.101 item/ItemEnum#attrs. {
434 if let synrust-analyzer cargo syn 2.0.101 crate/::Metarust-analyzer cargo syn 2.0.101 attr/Meta#::Listrust-analyzer cargo syn 2.0.101 attr/Meta#List#(meta) = &mut attr.metarust-analyzer cargo syn 2.0.101 attr/Attribute#meta. {
435 if meta.pathrust-analyzer cargo syn 2.0.101 attr/MetaList#path..is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().("derive") {
436 let mut tokens =
437 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut meta.tokensrust-analyzer cargo syn 2.0.101 attr/MetaList#tokens., TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#::newrust-analyzer cargo proc-macro2 1.0.95 impl#[TokenStream]new().()).into_iterrust-analyzer cargo proc-macro2 1.0.95 token_stream/impl#[TokenStream][IntoIterator]into_iter().();
438
439 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#::Identrust-analyzer cargo proc-macro2 1.0.95 TokenTree#Ident#(ident)) = tokens.nextrust-analyzer cargo proc-macro2 1.0.95 token_stream/impl#[IntoIter][Iterator]next().() {
440 let punct = tokens.nextrust-analyzer cargo proc-macro2 1.0.95 token_stream/impl#[IntoIter][Iterator]next().();
441
442 if ident rust-analyzer cargo proc-macro2 1.0.95 impl#[Ident][`PartialEq<T>`]eq().==rust-analyzer cargo proc-macro2 1.0.95 impl#[Ident][`PartialEq<T>`]eq(). rust-analyzer cargo proc-macro2 1.0.95 impl#[Ident][`PartialEq<T>`]eq()."Logos" {
443 continue;
444 }
445
446 meta.tokensrust-analyzer cargo syn 2.0.101 attr/MetaList#tokens..extendrust-analyzer cargo proc-macro2 1.0.95 impl#[TokenStream][`Extend<TokenTree>`]extend().([TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#::Identrust-analyzer cargo proc-macro2 1.0.95 TokenTree#Ident#(ident)]);
447 meta.tokensrust-analyzer cargo syn 2.0.101 attr/MetaList#tokens..extendrust-analyzer cargo proc-macro2 1.0.95 impl#[TokenStream][`Extend<TokenTree>`]extend().(punct);
448 }
449 }
450 }
451 }
452
453 for variant in &mut item.variantsrust-analyzer cargo syn 2.0.101 item/ItemEnum#variants. {
454 strip_attrs_from_vecrust-analyzer cargo logos-codegen 0.15.1 strip_attrs_from_vec().(&mut variant.attrsrust-analyzer cargo syn 2.0.101 data/Variant#attrs.);
455 for field in &mut variant.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields. {
456 strip_attrs_from_vecrust-analyzer cargo logos-codegen 0.15.1 strip_attrs_from_vec().(&mut field.attrsrust-analyzer cargo syn 2.0.101 data/Field#attrs.);
457 }
458 }
459
460 item.to_token_streamrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens#to_token_stream().()
461 }
462
463 fn strip_attrs_from_vecrust-analyzer cargo logos-codegen 0.15.1 strip_attrs_from_vec().(attrs: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<synrust-analyzer cargo syn 2.0.101 crate/::Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#>) {
464 attrs.retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]retain().(|attr| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_logos_attrrust-analyzer cargo logos-codegen 0.15.1 is_logos_attr().(attr))
465 }
466
467 fn is_logos_attrrust-analyzer cargo logos-codegen 0.15.1 is_logos_attr().(attr: &synrust-analyzer cargo syn 2.0.101 crate/::Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#) -> bool {
468 attr.pathrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().(LOGOS_ATTRrust-analyzer cargo logos-codegen 0.15.1 LOGOS_ATTR.)
469 || attr.pathrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().(TOKEN_ATTRrust-analyzer cargo logos-codegen 0.15.1 TOKEN_ATTR.)
470 || attr.pathrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().(REGEX_ATTRrust-analyzer cargo logos-codegen 0.15.1 REGEX_ATTR.)
471 }
472
473 fn strip_wrapping_parensrust-analyzer cargo logos-codegen 0.15.1 strip_wrapping_parens().(t: TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.95 TokenStream# {
474 let tts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#> = t.into_iterrust-analyzer cargo proc-macro2 1.0.95 token_stream/impl#[TokenStream][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
475
476 if tts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 {
477 tts.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
478 } else {
479 match tts.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() {
480 TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#::Grouprust-analyzer cargo proc-macro2 1.0.95 TokenTree#Group#(g) => {
481 if g.delimiterrust-analyzer cargo proc-macro2 1.0.95 impl#[Group]delimiter().() rust-analyzer cargo proc-macro2 1.0.95 impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc-macro2 1.0.95 impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc-macro2 1.0.95 impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc-macro2 1.0.95 Delimiter#::Parenthesisrust-analyzer cargo proc-macro2 1.0.95 Delimiter#Parenthesis# {
482 g.streamrust-analyzer cargo proc-macro2 1.0.95 impl#[Group]stream().()
483 } else {
484 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(TokenTreerust-analyzer cargo proc-macro2 1.0.95 TokenTree#::Grouprust-analyzer cargo proc-macro2 1.0.95 TokenTree#Group#(g)).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
485 }
486 }
487 tt => corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(tt).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
488 }
489 }
490 }