cl-parser: Sync error::Parsing with cl-ast
This commit is contained in:
parent
e36a684422
commit
02323ae6f2
@ -44,14 +44,18 @@ impl From<LexError> for ErrorKind {
|
|||||||
/// Compactly represents the stage of parsing an [Error] originated in
|
/// Compactly represents the stage of parsing an [Error] originated in
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum Parsing {
|
pub enum Parsing {
|
||||||
|
Mutability,
|
||||||
|
Visibility,
|
||||||
|
Identifier,
|
||||||
|
Literal,
|
||||||
|
|
||||||
File,
|
File,
|
||||||
|
|
||||||
Attrs,
|
Attrs,
|
||||||
Meta,
|
Meta,
|
||||||
|
MetaKind,
|
||||||
|
|
||||||
Item,
|
Item,
|
||||||
Visibility,
|
|
||||||
Mutability,
|
|
||||||
ItemKind,
|
ItemKind,
|
||||||
Alias,
|
Alias,
|
||||||
Const,
|
Const,
|
||||||
@ -78,6 +82,9 @@ pub enum Parsing {
|
|||||||
TyRef,
|
TyRef,
|
||||||
TyFn,
|
TyFn,
|
||||||
|
|
||||||
|
Path,
|
||||||
|
PathPart,
|
||||||
|
|
||||||
Stmt,
|
Stmt,
|
||||||
StmtKind,
|
StmtKind,
|
||||||
Let,
|
Let,
|
||||||
@ -95,10 +102,6 @@ pub enum Parsing {
|
|||||||
Fielder,
|
Fielder,
|
||||||
Call,
|
Call,
|
||||||
Member,
|
Member,
|
||||||
PathExpr,
|
|
||||||
PathPart,
|
|
||||||
Identifier,
|
|
||||||
Literal,
|
|
||||||
Array,
|
Array,
|
||||||
ArrayRep,
|
ArrayRep,
|
||||||
AddrOf,
|
AddrOf,
|
||||||
@ -145,14 +148,17 @@ impl Display for ErrorKind {
|
|||||||
impl Display for Parsing {
|
impl Display for Parsing {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
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::File => "a file",
|
||||||
|
|
||||||
Parsing::Attrs => "an attribute-set",
|
Parsing::Attrs => "an attribute-set",
|
||||||
Parsing::Meta => "an attribute",
|
Parsing::Meta => "an attribute",
|
||||||
|
Parsing::MetaKind => "an attribute's arguments",
|
||||||
Parsing::Item => "an item",
|
Parsing::Item => "an item",
|
||||||
Parsing::Visibility => "a visibility qualifier",
|
|
||||||
Parsing::Mutability => "a mutability qualifier",
|
|
||||||
Parsing::ItemKind => "an item",
|
Parsing::ItemKind => "an item",
|
||||||
Parsing::Alias => "a type alias",
|
Parsing::Alias => "a type alias",
|
||||||
Parsing::Const => "a const item",
|
Parsing::Const => "a const item",
|
||||||
@ -179,6 +185,9 @@ impl Display for Parsing {
|
|||||||
Parsing::TyRef => "a reference type",
|
Parsing::TyRef => "a reference type",
|
||||||
Parsing::TyFn => "a function pointer type",
|
Parsing::TyFn => "a function pointer type",
|
||||||
|
|
||||||
|
Parsing::Path => "a path",
|
||||||
|
Parsing::PathPart => "a path component",
|
||||||
|
|
||||||
Parsing::Stmt => "a statement",
|
Parsing::Stmt => "a statement",
|
||||||
Parsing::StmtKind => "a statement",
|
Parsing::StmtKind => "a statement",
|
||||||
Parsing::Let => "a local variable declaration",
|
Parsing::Let => "a local variable declaration",
|
||||||
@ -196,10 +205,6 @@ impl Display for Parsing {
|
|||||||
Parsing::Fielder => "a struct field expression",
|
Parsing::Fielder => "a struct field expression",
|
||||||
Parsing::Call => "a call expression",
|
Parsing::Call => "a call expression",
|
||||||
Parsing::Member => "a member access 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::Array => "an array",
|
||||||
Parsing::ArrayRep => "an array of form [k;N]",
|
Parsing::ArrayRep => "an array of form [k;N]",
|
||||||
Parsing::AddrOf => "a borrow op",
|
Parsing::AddrOf => "a borrow op",
|
||||||
|
@ -208,7 +208,7 @@ impl<'t> Parser<'t> {
|
|||||||
/// [Path] = `::` *RelativePath*? | *RelativePath* \
|
/// [Path] = `::` *RelativePath*? | *RelativePath* \
|
||||||
/// *RelativePath* = [PathPart] (`::` [PathPart])*
|
/// *RelativePath* = [PathPart] (`::` [PathPart])*
|
||||||
pub fn path(&mut self) -> PResult<Path> {
|
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 absolute = self.match_op(Punct::ColonColon, PARSING).is_ok();
|
||||||
let mut parts = vec![];
|
let mut parts = vec![];
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ impl<'t> Parser<'t> {
|
|||||||
parts.push(self.path_part()?)
|
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()?)
|
parts.push(self.path_part()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,7 +598,7 @@ impl<'t> Parser<'t> {
|
|||||||
Ok(ImplKind::Trait { impl_trait, for_type: self.ty()?.into() })
|
Ok(ImplKind::Trait { impl_trait, for_type: self.ty()?.into() })
|
||||||
} else {
|
} else {
|
||||||
Err(Error {
|
Err(Error {
|
||||||
reason: ExpectedParsing { want: { Parsing::PathExpr } },
|
reason: ExpectedParsing { want: Parsing::Path },
|
||||||
while_parsing: PARSING,
|
while_parsing: PARSING,
|
||||||
loc: target.extents.head,
|
loc: target.extents.head,
|
||||||
})?
|
})?
|
||||||
@ -925,7 +925,7 @@ impl<'t> Parser<'t> {
|
|||||||
/// Parses an expression beginning with a [Path] (i.e. [Path] or [Structor])
|
/// Parses an expression beginning with a [Path] (i.e. [Path] or [Structor])
|
||||||
pub fn exprkind_pathlike(&mut self) -> PResult<ExprKind> {
|
pub fn exprkind_pathlike(&mut self) -> PResult<ExprKind> {
|
||||||
let head = self.path()?;
|
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)?),
|
Ok(_) => ExprKind::Structor(self.structor_body(head)?),
|
||||||
Err(_) => ExprKind::Path(head),
|
Err(_) => ExprKind::Path(head),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user