1
0

Remove boxing from parse function

This commit is contained in:
Jeff 2024-03-19 17:12:32 -04:00
parent 953454a140
commit 6d50ac5b37
2 changed files with 9 additions and 13 deletions

View File

@ -9,7 +9,7 @@ use abstract_tree::{AbstractTree, Action, WithPosition};
use context::Context; use context::Context;
use error::Error; use error::Error;
use lexer::lex; use lexer::lex;
pub use parser::{parse, parser, DustParser}; use parser::parse;
pub use value::Value; pub use value::Value;
pub fn interpret(source: &str) -> Result<Option<Value>, Vec<Error>> { pub fn interpret(source: &str) -> Result<Option<Value>, Vec<Error>> {

View File

@ -8,14 +8,6 @@ use crate::{
lexer::{Control, Operator, Token}, lexer::{Control, Operator, Token},
}; };
pub type DustParser<'src> = Boxed<
'src,
'src,
ParserInput<'src>,
Vec<WithPosition<Statement>>,
extra::Err<Rich<'src, Token<'src>, SimpleSpan>>,
>;
pub type ParserInput<'src> = pub type ParserInput<'src> =
SpannedInput<Token<'src>, SimpleSpan, &'src [(Token<'src>, SimpleSpan)]>; SpannedInput<Token<'src>, SimpleSpan, &'src [(Token<'src>, SimpleSpan)]>;
@ -28,7 +20,12 @@ pub fn parse<'src>(
.map_err(|errors| errors.into_iter().map(|error| error.into()).collect()) .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<WithPosition<Statement>>,
extra::Err<Rich<'src, Token<'src>, SimpleSpan>>,
> {
let identifiers: RefCell<HashMap<&str, Identifier>> = RefCell::new(HashMap::new()); let identifiers: RefCell<HashMap<&str, Identifier>> = RefCell::new(HashMap::new());
let identifier = select! { let identifier = select! {
@ -57,8 +54,7 @@ pub fn parser<'src>() -> DustParser<'src> {
Token::Integer(integer) => ValueNode::Integer(integer), Token::Integer(integer) => ValueNode::Integer(integer),
Token::String(string) => ValueNode::String(string.to_string()), Token::String(string) => ValueNode::String(string.to_string()),
} }
.map_with(|value, state| Expression::Value(value).with_position(state.span())) .map_with(|value, state| Expression::Value(value).with_position(state.span()));
.boxed();
let r#type = recursive(|r#type| { let r#type = recursive(|r#type| {
let function_type = 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()) .then_ignore(just(Token::Control(Control::Semicolon)).or_not())
}); });
positioned_statement.repeated().collect().boxed() positioned_statement.repeated().collect()
} }
#[cfg(test)] #[cfg(test)]