summaryrefslogtreecommitdiff
path: root/chewed/src
diff options
context:
space:
mode:
Diffstat (limited to 'chewed/src')
-rw-r--r--chewed/src/parse.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/chewed/src/parse.rs b/chewed/src/parse.rs
index 65e9272..2d01757 100644
--- a/chewed/src/parse.rs
+++ b/chewed/src/parse.rs
@@ -1,3 +1,5 @@
+use std::fmt::Display;
+
use super::{
error::{ParseError, TakeError},
position::LineCol,
@@ -102,7 +104,7 @@ impl<I: ?Sized + Iterator<Item = char>> Parser for IterWrapper<I> {
}
}
-pub trait Parse: Sized {
+pub trait Parse: Display + Sized {
fn take<P: Parser + ?Sized>(input: &mut P) -> Result<Self, TakeError>;
fn parse<P: Parser>(mut input: P) -> Result<Self, ParseError> {
@@ -124,23 +126,18 @@ pub trait Parse: Sized {
}
}
-impl Parse for () {
- fn take<P: Parser + ?Sized>(_: &mut P) -> Result<Self, TakeError> {
- Ok(())
- }
-}
+#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
+pub struct Epsilon;
-impl<A: Parse, B: Parse> Parse for (A, B) {
- fn take<P: Parser + ?Sized>(input: &mut P) -> Result<Self, TakeError> {
- let a = input.take()?;
- let b = input.take()?;
- Ok((a, b))
+impl Display for Epsilon {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "")
}
+}
- fn parse<P: Parser>(mut input: P) -> Result<Self, ParseError> {
- let a = A::take(&mut input)?;
- let b = B::parse(input)?;
- Ok((a, b))
+impl Parse for Epsilon {
+ fn take<P: Parser + ?Sized>(_: &mut P) -> Result<Self, TakeError> {
+ Ok(Epsilon)
}
}