From aac3549a72663c523a456b2f5d7c3b77f509cdd6 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 14 Jan 2021 11:42:55 +0000 Subject: Add labelled expressions. Restructure project (again). Convert `Cat` and `Alt` from binary to n+2-ary. --- chewed/src/parse.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'chewed/src') 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> Parser for IterWrapper { } } -pub trait Parse: Sized { +pub trait Parse: Display + Sized { fn take(input: &mut P) -> Result; fn parse(mut input: P) -> Result { @@ -124,23 +126,18 @@ pub trait Parse: Sized { } } -impl Parse for () { - fn take(_: &mut P) -> Result { - Ok(()) - } -} +#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] +pub struct Epsilon; -impl Parse for (A, B) { - fn take(input: &mut P) -> Result { - 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(mut input: P) -> Result { - let a = A::take(&mut input)?; - let b = B::parse(input)?; - Ok((a, b)) +impl Parse for Epsilon { + fn take(_: &mut P) -> Result { + Ok(Epsilon) } } -- cgit v1.2.3