diff options
Diffstat (limited to 'src/parse/parser.rs')
| -rw-r--r-- | src/parse/parser.rs | 23 |
1 files changed, 18 insertions, 5 deletions
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 {} |
