diff --git a/src/ast/basic.rs b/src/ast/basic.rs index 9790f8c..5056f21 100644 --- a/src/ast/basic.rs +++ b/src/ast/basic.rs @@ -77,26 +77,6 @@ impl HasSpan for Ident { } } -#[derive(Debug, Clone)] -pub enum Separated { - Empty(Span), - NonEmpty { - first_elem: E, - last_elems: Vec<(S1, E)>, - trailing: Option, - span: Span, - }, -} - -impl HasSpan for Separated { - fn span(&self) -> Span { - match self { - Self::Empty(span) => *span, - Self::NonEmpty { span, .. } => *span, - } - } -} - #[derive(Debug, Clone)] pub struct BoundedSeparated { pub elems: Vec<(Space, E, Space)>, diff --git a/src/desugar/basic.rs b/src/desugar/basic.rs index 1b0f4fc..156445f 100644 --- a/src/desugar/basic.rs +++ b/src/desugar/basic.rs @@ -1,39 +1,4 @@ -use crate::ast::{BoundedSeparated, Separated}; - -impl Separated { - pub fn desugar_elem(self, desugar_elem: impl Fn(E) -> (E, bool)) -> (Self, bool) { - match self { - Self::Empty(span) => (Self::Empty(span), false), - - Self::NonEmpty { - first_elem, - last_elems, - trailing, - span, - } => { - let (new_first_elem, mut desugared) = desugar_elem(first_elem); - let mut new_last_elems = vec![]; - for (separator, elem) in last_elems { - if desugared { - new_last_elems.push((separator, elem)); - } else { - let (elem, elem_desugared) = desugar_elem(elem); - desugared = desugared || elem_desugared; - new_last_elems.push((separator, elem)); - } - } - - let new = Self::NonEmpty { - first_elem: new_first_elem, - last_elems: new_last_elems, - trailing, - span, - }; - (new, desugared) - } - } - } -} +use crate::ast::BoundedSeparated; impl BoundedSeparated { pub fn desugar(self, desugar_elem: impl Fn(E) -> (E, bool)) -> (Self, bool) { diff --git a/src/parser/basic.rs b/src/parser/basic.rs index 2c8254d..9ca8d09 100644 --- a/src/parser/basic.rs +++ b/src/parser/basic.rs @@ -3,7 +3,7 @@ use chumsky::prelude::*; use chumsky::text::Character; -use crate::ast::{BoundedSeparated, Ident, Line, Separated, Space}; +use crate::ast::{BoundedSeparated, Ident, Line, Space}; use crate::span::Span; pub type Error = Simple; @@ -62,27 +62,6 @@ pub fn local(space: EParser) -> EParser> { // This function is more of a utility function. Because of this and to keep the // code nicer, I have decided that the rules specified in the `parser` module // don't apply to it. -pub fn separated_by( - elem: impl Parser + Clone + 'static, - separator: impl Parser + 'static, - trailing_separator: impl Parser + 'static, -) -> EParser> { - elem.clone() - .then(separator.then(elem).repeated()) - .then(trailing_separator.or_not()) - .or_not() - .map_with_span(|s, span| match s { - Some(((first_elem, last_elems), trailing)) => Separated::NonEmpty { - first_elem, - last_elems, - trailing, - span, - }, - None => Separated::Empty(span), - }) - .boxed() -} - pub fn bounded_separated( space: impl Parser + Clone + 'static, start: impl Parser + 'static, diff --git a/src/pretty/basic.rs b/src/pretty/basic.rs index 5d4ae8e..632007c 100644 --- a/src/pretty/basic.rs +++ b/src/pretty/basic.rs @@ -1,6 +1,6 @@ use pretty::{DocAllocator, DocBuilder, Pretty}; -use crate::ast::{BoundedSeparated, Ident, Separated}; +use crate::ast::{BoundedSeparated, Ident}; use super::NEST_DEPTH; @@ -10,44 +10,6 @@ impl<'a, D: DocAllocator<'a>> Pretty<'a, D> for Ident { } } -impl Separated { - pub fn pretty<'a, D, FE, FS1, FS2>( - self, - allocator: &'a D, - elem_to_doc: FE, - separator_to_doc: FS1, - trailing_separator_to_doc: FS2, - ) -> DocBuilder<'a, D> - where - D: DocAllocator<'a>, - FE: Fn(E) -> DocBuilder<'a, D>, - FS1: Fn(S1) -> DocBuilder<'a, D>, - FS2: Fn(S2) -> DocBuilder<'a, D>, - { - match self { - Self::Empty(_) => allocator.nil(), - Self::NonEmpty { - first_elem, - last_elems, - trailing, - span: _span, - } => elem_to_doc(first_elem) - .append( - allocator.concat( - last_elems - .into_iter() - .map(|(s, e)| separator_to_doc(s).append(elem_to_doc(e))), - ), - ) - .append( - trailing - .map(trailing_separator_to_doc) - .unwrap_or_else(|| allocator.nil()), - ), - } - } -} - impl BoundedSeparated { pub fn pretty<'a, D, FE>( self,