| 36 | |
| 37 | impl<'a> Parse<'a> for AttrName { |
| 38 | fn parse<I>(p: &mut Parser<'a, I>) -> ParserResult<Self> |
| 39 | where |
| 40 | I: Iterator<Item = Cursor> + Clone, |
| 41 | { |
| 42 | let a = p.parse_if_peek::<T![Ident]>()?; |
| 43 | let b = p.parse_if_peek::<T![|]>()?; |
| 44 | |
| 45 | if a.is_some() && b.is_none() { |
| 46 | return Ok(Self(None, None, a)); |
| 47 | } |
| 48 | |
| 49 | if a.is_none() && b.is_some() { |
| 50 | return Ok(Self(None, b, Some(p.parse::<T![Ident]>()?))); |
| 51 | } |
| 52 | |
| 53 | if a.is_none() && b.is_none() { |
| 54 | Err(Diagnostic::new(p.next(), Diagnostic::expected_ident))? |
| 55 | } |
| 56 | |
| 57 | debug_assert!(a.is_some() && b.is_some()); |
| 58 | |
| 59 | Ok(Self(a, b, Some(p.parse::<T![Ident]>()?))) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /// ```text,ignore |