From 6d50ac5b37b550702fab924988e5fa2fe265771b Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 19 Mar 2024 17:12:32 -0400 Subject: [PATCH] Remove boxing from parse function --- src/lib.rs | 2 +- src/parser.rs | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c4a31d..cb395c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ use abstract_tree::{AbstractTree, Action, WithPosition}; use context::Context; use error::Error; use lexer::lex; -pub use parser::{parse, parser, DustParser}; +use parser::parse; pub use value::Value; pub fn interpret(source: &str) -> Result, Vec> { diff --git a/src/parser.rs b/src/parser.rs index 3f3f842..8e48f14 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -8,14 +8,6 @@ use crate::{ lexer::{Control, Operator, Token}, }; -pub type DustParser<'src> = Boxed< - 'src, - 'src, - ParserInput<'src>, - Vec>, - extra::Err, SimpleSpan>>, ->; - pub type ParserInput<'src> = SpannedInput, SimpleSpan, &'src [(Token<'src>, SimpleSpan)]>; @@ -28,7 +20,12 @@ pub fn parse<'src>( .map_err(|errors| errors.into_iter().map(|error| error.into()).collect()) } -pub fn parser<'src>() -> DustParser<'src> { +pub fn parser<'src>() -> impl Parser< + 'src, + ParserInput<'src>, + Vec>, + extra::Err, SimpleSpan>>, +> { let identifiers: RefCell> = RefCell::new(HashMap::new()); let identifier = select! { @@ -57,8 +54,7 @@ pub fn parser<'src>() -> DustParser<'src> { Token::Integer(integer) => ValueNode::Integer(integer), Token::String(string) => ValueNode::String(string.to_string()), } - .map_with(|value, state| Expression::Value(value).with_position(state.span())) - .boxed(); + .map_with(|value, state| Expression::Value(value).with_position(state.span())); let r#type = recursive(|r#type| { let function_type = r#type @@ -436,7 +432,7 @@ pub fn parser<'src>() -> DustParser<'src> { .then_ignore(just(Token::Control(Control::Semicolon)).or_not()) }); - positioned_statement.repeated().collect().boxed() + positioned_statement.repeated().collect() } #[cfg(test)]