| 499 | } |
| 500 | |
| 501 | fn parse_function_config(input: ParseStream<'_>) -> Result<FunctionConfig> { |
| 502 | let content; |
| 503 | syn::braced!(content in input); |
| 504 | let mut ret = FunctionConfig::new(); |
| 505 | |
| 506 | let list = Punctuated::<FunctionConfigSyntax, Token![,]>::parse_terminated(&content)?; |
| 507 | for item in list.into_iter() { |
| 508 | ret.push(item.filter, item.flags); |
| 509 | } |
| 510 | |
| 511 | return Ok(ret); |
| 512 | |
| 513 | struct FunctionConfigSyntax { |
| 514 | filter: FunctionFilter, |
| 515 | flags: FunctionFlags, |
| 516 | } |
| 517 | |
| 518 | impl Parse for FunctionConfigSyntax { |
| 519 | fn parse(input: ParseStream<'_>) -> Result<Self> { |
| 520 | let l = input.lookahead1(); |
| 521 | let filter = if l.peek(syn::LitStr) { |
| 522 | FunctionFilter::Name(input.parse::<syn::LitStr>()?.value()) |
| 523 | } else if l.peek(Token![default]) { |
| 524 | input.parse::<Token![default]>()?; |
| 525 | FunctionFilter::Default |
| 526 | } else { |
| 527 | return Err(l.error()); |
| 528 | }; |
| 529 | |
| 530 | input.parse::<Token![:]>()?; |
| 531 | |
| 532 | let mut flags = FunctionFlags::empty(); |
| 533 | while !input.is_empty() { |
| 534 | let l = input.lookahead1(); |
| 535 | if l.peek(Token![async]) { |
| 536 | input.parse::<Token![async]>()?; |
| 537 | flags |= FunctionFlags::ASYNC; |
| 538 | } else if l.peek(kw::tracing) { |
| 539 | input.parse::<kw::tracing>()?; |
| 540 | flags |= FunctionFlags::TRACING; |
| 541 | } else if l.peek(kw::verbose_tracing) { |
| 542 | input.parse::<kw::verbose_tracing>()?; |
| 543 | flags |= FunctionFlags::VERBOSE_TRACING; |
| 544 | } else if l.peek(kw::store) { |
| 545 | input.parse::<kw::store>()?; |
| 546 | flags |= FunctionFlags::STORE; |
| 547 | } else if l.peek(kw::trappable) { |
| 548 | input.parse::<kw::trappable>()?; |
| 549 | flags |= FunctionFlags::TRAPPABLE; |
| 550 | } else if l.peek(kw::ignore_wit) { |
| 551 | input.parse::<kw::ignore_wit>()?; |
| 552 | flags |= FunctionFlags::IGNORE_WIT; |
| 553 | } else if l.peek(kw::exact) { |
| 554 | input.parse::<kw::exact>()?; |
| 555 | flags |= FunctionFlags::EXACT; |
| 556 | } else { |
| 557 | return Err(l.error()); |
| 558 | } |