Remove boxing from parse function
This commit is contained in:
parent
953454a140
commit
6d50ac5b37
@ -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>> {
|
||||||
|
@ -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)]
|
||||||
|
Loading…
Reference in New Issue
Block a user