cl-parser: Sync error::Parsing with cl-ast
This commit is contained in:
		@@ -44,14 +44,18 @@ impl From<LexError> 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",
 | 
			
		||||
 
 | 
			
		||||
@@ -208,7 +208,7 @@ impl<'t> Parser<'t> {
 | 
			
		||||
    /// [Path] = `::` *RelativePath*? | *RelativePath* \
 | 
			
		||||
    /// *RelativePath* = [PathPart] (`::` [PathPart])*
 | 
			
		||||
    pub fn path(&mut self) -> PResult<Path> {
 | 
			
		||||
        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<ExprKind> {
 | 
			
		||||
        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),
 | 
			
		||||
        })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user