From 02323ae6f219eff4551513ff2cc858e2f0e0e8ec Mon Sep 17 00:00:00 2001 From: John Date: Sun, 21 Apr 2024 21:20:55 -0500 Subject: [PATCH] cl-parser: Sync error::Parsing with cl-ast --- compiler/cl-parser/src/error.rs | 31 ++++++++++++++++++------------- compiler/cl-parser/src/parser.rs | 8 ++++---- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/compiler/cl-parser/src/error.rs b/compiler/cl-parser/src/error.rs index dc63c26..0661ad5 100644 --- a/compiler/cl-parser/src/error.rs +++ b/compiler/cl-parser/src/error.rs @@ -44,14 +44,18 @@ impl From for ErrorKind { /// Compactly represents the stage of parsing an [Error] originated in #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Parsing { + Mutability, + Visibility, + Identifier, + Literal, + File, Attrs, Meta, + MetaKind, Item, - Visibility, - Mutability, ItemKind, Alias, Const, @@ -78,6 +82,9 @@ pub enum Parsing { TyRef, TyFn, + Path, + PathPart, + Stmt, StmtKind, Let, @@ -95,10 +102,6 @@ pub enum Parsing { Fielder, Call, Member, - PathExpr, - PathPart, - Identifier, - Literal, Array, ArrayRep, AddrOf, @@ -145,14 +148,17 @@ impl Display for ErrorKind { impl Display for Parsing { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { + Parsing::Visibility => "a visibility qualifier", + Parsing::Mutability => "a mutability qualifier", + Parsing::Identifier => "an identifier", + Parsing::Literal => "a literal", + Parsing::File => "a file", Parsing::Attrs => "an attribute-set", Parsing::Meta => "an attribute", - + Parsing::MetaKind => "an attribute's arguments", Parsing::Item => "an item", - Parsing::Visibility => "a visibility qualifier", - Parsing::Mutability => "a mutability qualifier", Parsing::ItemKind => "an item", Parsing::Alias => "a type alias", Parsing::Const => "a const item", @@ -179,6 +185,9 @@ impl Display for Parsing { Parsing::TyRef => "a reference type", Parsing::TyFn => "a function pointer type", + Parsing::Path => "a path", + Parsing::PathPart => "a path component", + Parsing::Stmt => "a statement", Parsing::StmtKind => "a statement", Parsing::Let => "a local variable declaration", @@ -196,10 +205,6 @@ impl Display for Parsing { Parsing::Fielder => "a struct field expression", Parsing::Call => "a call expression", Parsing::Member => "a member access expression", - Parsing::PathExpr => "a path", - Parsing::PathPart => "a path component", - Parsing::Identifier => "an identifier", - Parsing::Literal => "a literal", Parsing::Array => "an array", Parsing::ArrayRep => "an array of form [k;N]", Parsing::AddrOf => "a borrow op", diff --git a/compiler/cl-parser/src/parser.rs b/compiler/cl-parser/src/parser.rs index c3faf35..4facf95 100644 --- a/compiler/cl-parser/src/parser.rs +++ b/compiler/cl-parser/src/parser.rs @@ -208,7 +208,7 @@ impl<'t> Parser<'t> { /// [Path] = `::` *RelativePath*? | *RelativePath* \ /// *RelativePath* = [PathPart] (`::` [PathPart])* pub fn path(&mut self) -> PResult { - const PARSING: Parsing = Parsing::PathExpr; + const PARSING: Parsing = Parsing::Path; let absolute = self.match_op(Punct::ColonColon, PARSING).is_ok(); let mut parts = vec![]; @@ -221,7 +221,7 @@ impl<'t> Parser<'t> { parts.push(self.path_part()?) }; - while self.match_op(Punct::ColonColon, Parsing::PathExpr).is_ok() { + while self.match_op(Punct::ColonColon, Parsing::Path).is_ok() { parts.push(self.path_part()?) } @@ -598,7 +598,7 @@ impl<'t> Parser<'t> { Ok(ImplKind::Trait { impl_trait, for_type: self.ty()?.into() }) } else { Err(Error { - reason: ExpectedParsing { want: { Parsing::PathExpr } }, + reason: ExpectedParsing { want: Parsing::Path }, while_parsing: PARSING, loc: target.extents.head, })? @@ -925,7 +925,7 @@ impl<'t> Parser<'t> { /// Parses an expression beginning with a [Path] (i.e. [Path] or [Structor]) pub fn exprkind_pathlike(&mut self) -> PResult { let head = self.path()?; - Ok(match self.match_op(Punct::Colon, Parsing::PathExpr) { + Ok(match self.match_op(Punct::Colon, Parsing::Path) { Ok(_) => ExprKind::Structor(self.structor_body(head)?), Err(_) => ExprKind::Path(head), })