summaryrefslogtreecommitdiff
path: root/chewed
diff options
context:
space:
mode:
Diffstat (limited to 'chewed')
-rw-r--r--chewed/src/error.rs4
-rw-r--r--chewed/src/parse.rs8
2 files changed, 11 insertions, 1 deletions
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<TakeError> 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<Item = char> {
@@ -37,6 +39,12 @@ pub trait Parser: Iterator<Item = char> {
}
}
+impl<I: Iterator<Item = char>> Parser for Peekable<I> {
+ fn peek(&mut self) -> Option<char> {
+ Peekable::peek(self).copied()
+ }
+}
+
pub trait Parse: Sized {
fn take<P: Parser + ?Sized>(input: &mut P) -> Result<Self, TakeError>;