|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | use crate::ParseResult;
|
8 |
| -use proc_macro2::{Delimiter, Ident, Spacing, Span, TokenStream, TokenTree}; |
| 8 | +use proc_macro2::{Delimiter, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; |
9 | 9 | use quote::ToTokens;
|
10 | 10 | use std::collections::HashMap;
|
11 | 11 | use venial::Attribute;
|
@@ -77,6 +77,28 @@ impl KvParser {
|
77 | 77 | Ok(found_attrs)
|
78 | 78 | }
|
79 | 79 |
|
| 80 | + pub fn parse_from_list_parser(parser: ListParser, delimiter: Delimiter) -> ParseResult<Self> { |
| 81 | + let span = parser.span_close; |
| 82 | + let tokens = parser |
| 83 | + .lists |
| 84 | + .into_iter() |
| 85 | + .flat_map(|v| { |
| 86 | + let mut tokens = v.into_tokens(); |
| 87 | + tokens.push(TokenTree::Punct(Punct::new(',', Spacing::Alone))); |
| 88 | + |
| 89 | + tokens |
| 90 | + }) |
| 91 | + .collect::<Vec<TokenTree>>(); |
| 92 | + |
| 93 | + Ok(Self { |
| 94 | + span, |
| 95 | + map: ParserState::parse( |
| 96 | + "nested list".to_string(), |
| 97 | + &venial::AttributeValue::Group(venial::GroupSpan { delimiter, span }, tokens), |
| 98 | + )?, |
| 99 | + }) |
| 100 | + } |
| 101 | + |
80 | 102 | pub fn span(&self) -> Span {
|
81 | 103 | self.span
|
82 | 104 | }
|
@@ -333,7 +355,11 @@ impl<'a> ParserState<'a> {
|
333 | 355 | } else {
|
334 | 356 | "".to_owned()
|
335 | 357 | };
|
336 |
| - return bail!(cur, "expected identifier{parens_hint}"); |
| 358 | + let attr_name = self.attr_name; |
| 359 | + let tokens = self.tokens; |
| 360 | + let prev = self.prev; |
| 361 | + let cur = self.cur; |
| 362 | + return bail!(cur, "expected identifier{parens_hint} attr {attr_name} tokens {tokens:?} prev {prev:?} cur {cur:?}"); |
337 | 363 | }
|
338 | 364 | }
|
339 | 365 | }
|
|
0 commit comments