MCPcopy Index your code
hub / github.com/dtolnay/thiserror / parse_token_expr

Function parse_token_expr

impl/src/attr.rs:196–300  ·  view source on GitHub ↗
(input: ParseStream, mut begin_expr: bool)

Source from the content-addressed store, hash-verified

194}
195
196fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<TokenStream> {
197 let mut tokens = Vec::new();
198 while !input.is_empty() {
199 if input.peek(token::Group) {
200 let group: TokenTree = input.parse()?;
201 tokens.push(group);
202 begin_expr = false;
203 continue;
204 }
205
206 if begin_expr && input.peek(Token![.]) {
207 if input.peek2(Ident) {
208 input.parse::<Token![.]>()?;
209 begin_expr = false;
210 continue;
211 } else if input.peek2(LitInt) {
212 input.parse::<Token![.]>()?;
213 let int: Index = input.parse()?;
214 tokens.push({
215 let ident = format_ident!("_{}", int.index, span = int.span);
216 TokenTree::Ident(ident)
217 });
218 begin_expr = false;
219 continue;
220 } else if input.peek2(LitFloat) {
221 let ahead = input.fork();
222 ahead.parse::<Token![.]>()?;
223 let float: LitFloat = ahead.parse()?;
224 let repr = float.to_string();
225 let mut indices = repr.split('.').map(syn::parse_str::<Index>);
226 if let (Some(Ok(first)), Some(Ok(second)), None) =
227 (indices.next(), indices.next(), indices.next())
228 {
229 input.advance_to(&ahead);
230 tokens.push({
231 let ident = format_ident!("_{}", first, span = float.span());
232 TokenTree::Ident(ident)
233 });
234 tokens.push({
235 let mut punct = Punct::new('.', Spacing::Alone);
236 punct.set_span(float.span());
237 TokenTree::Punct(punct)
238 });
239 tokens.push({
240 let mut literal = Literal::u32_unsuffixed(second.index);
241 literal.set_span(float.span());
242 TokenTree::Literal(literal)
243 });
244 begin_expr = false;
245 continue;
246 }
247 }
248 }
249
250 begin_expr = input.peek(Token![break])
251 || input.peek(Token![continue])
252 || input.peek(Token![if])
253 || input.peek(Token![in])

Callers 1

parse_error_attributeFunction · 0.85

Calls 3

parseMethod · 0.80
set_spanMethod · 0.80
spanMethod · 0.80

Tested by

no test coverage detected