diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-12-30 11:37:11 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-12-30 12:00:12 +0100 |
| commit | f5dcb84e36a38182218c7f907b861b12d2bd2c1c (patch) | |
| tree | 1fce04fb53d2ad5b61f5f3151e43d80e2684e579 /src/parse | |
| parent | fef55025177ea4f248e61b68fab365bfbc0e47fb (diff) | |
Make clippy a bit happier
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/mod.rs | 12 | ||||
| -rw-r--r-- | src/parse/parser.rs | 23 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 0a2f73f5..10aaad23 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -275,13 +275,13 @@ fn primary(p: &mut Parser, atomic: bool) -> ParseResult { Some(NodeKind::Error(_, _)) => { p.eat(); - Err(()) + Err(ParseError) } // Nothing. _ => { p.expected("expression"); - Err(()) + Err(ParseError) } } } @@ -428,7 +428,7 @@ fn item(p: &mut Parser) -> ParseResult<NodeKind> { marker.end(p, error); p.eat(); expr(p).ok(); - Err(()) + Err(ParseError) } })?; @@ -519,7 +519,7 @@ fn args(p: &mut Parser, direct: bool, brackets: bool) -> ParseResult { Some(NodeKind::LeftBracket) if brackets => {} _ => { p.expected("argument list"); - return Err(()); + return Err(ParseError); } } @@ -689,7 +689,7 @@ fn ident(p: &mut Parser) -> ParseResult { } _ => { p.expected("identifier"); - Err(()) + Err(ParseError) } } } @@ -701,7 +701,7 @@ fn body(p: &mut Parser) -> ParseResult { Some(NodeKind::LeftBrace) => block(p), _ => { p.expected_at("body"); - return Err(()); + return Err(ParseError); } } Ok(()) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 503158a9..af8a7c5c 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -1,13 +1,10 @@ +use std::fmt::{self, Display, Formatter}; use std::mem; use super::{TokenMode, Tokens}; use crate::syntax::{ErrorPos, Green, GreenData, GreenNode, NodeKind}; use crate::util::EcoString; -/// Allows parser methods to use the try operator. Not exposed as the parser -/// recovers from all errors. -pub(crate) type ParseResult<T = ()> = Result<T, ()>; - /// A convenient token-based parser. pub struct Parser<'s> { /// An iterator over the source tokens. @@ -121,7 +118,7 @@ impl<'s> Parser<'s> { if !eaten { self.expected_at(t.as_str()); } - if eaten { Ok(()) } else { Err(()) } + if eaten { Ok(()) } else { Err(ParseError) } } /// Eat, debug-asserting that the token is the given one. @@ -448,3 +445,19 @@ pub enum Group { /// A group for import items, ended by a semicolon, line break or `from`. Imports, } + +/// Allows parser methods to use the try operator. Never returned top-level +/// because the parser recovers from all errors. +pub type ParseResult<T = ()> = Result<T, ParseError>; + +/// The error type for parsing. +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub struct ParseError; + +impl Display for ParseError { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.pad("failed to parse") + } +} + +impl std::error::Error for ParseError {} |
