From fe2eac31d9dbec772796c3ea75be32e9cd01b810 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 7 Jan 2021 12:44:06 +0000 Subject: Add first steps of AutoChomp --- chewed/src/error.rs | 4 +++- chewed/src/parse.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'chewed') diff --git a/chewed/src/error.rs b/chewed/src/error.rs index cb2cc4b..420a376 100644 --- a/chewed/src/error.rs +++ b/chewed/src/error.rs @@ -11,7 +11,7 @@ impl fmt::Display for TakeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::BadBranch(got, expected) => { - write!(f, "Unexpected character {:?}.", got)?; + write!(f, "Unexpected character {:?}. ", got)?; if expected.is_empty() { write!(f, "Expected end of input.") @@ -51,6 +51,8 @@ impl fmt::Display for ParseError { } } +impl Error for ParseError {} + impl From for ParseError { fn from(e: TakeError) -> Self { Self::TakeError(e) diff --git a/chewed/src/parse.rs b/chewed/src/parse.rs index 0687ea5..f6bbd66 100644 --- a/chewed/src/parse.rs +++ b/chewed/src/parse.rs @@ -1,3 +1,5 @@ +use std::iter::Peekable; + use super::error::{ParseError, TakeError}; pub trait Parser: Iterator { @@ -37,6 +39,12 @@ pub trait Parser: Iterator { } } +impl> Parser for Peekable { + fn peek(&mut self) -> Option { + Peekable::peek(self).copied() + } +} + pub trait Parse: Sized { fn take(input: &mut P) -> Result; -- cgit v1.2.3