From bc33b602655346832df622f1844a9162def04849 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 14 Apr 2024 18:01:58 -0500 Subject: [PATCH] cl-parser: Parse Impl/ImplKind --- cl-parser/src/parser.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cl-parser/src/parser.rs b/cl-parser/src/parser.rs index 4afedb6..e59b249 100644 --- a/cl-parser/src/parser.rs +++ b/cl-parser/src/parser.rs @@ -573,7 +573,29 @@ impl<'t> Parser<'t> { const PARSING: Parsing = Parsing::Impl; self.match_type(TokenKind::Impl, PARSING)?; - Err(self.error(Todo, PARSING)) + + Ok(Impl { + target: self.parse_impl_kind()?, + body: delim(Self::file, CURLIES, PARSING)(self)?, + }) + } + + pub fn parse_impl_kind(&mut self) -> PResult { + const PARSING: Parsing = Parsing::ImplKind; + + let target = self.ty()?; + + if self.match_type(TokenKind::For, PARSING).is_err() { + Ok(ImplKind::Type(target)) + } else if let TyKind::Path(impl_trait) = target.kind { + Ok(ImplKind::Trait { impl_trait, for_type: self.ty()?.into() }) + } else { + Err(Error { + reason: ExpectedParsing { want: { Parsing::PathExpr } }, + while_parsing: PARSING, + loc: target.extents.head, + })? + } } pub fn visibility(&mut self) -> PResult {