This commit is contained in:
LunarAkai 2025-08-08 21:10:35 +02:00
commit 92db6f7f6e
4 changed files with 51 additions and 30 deletions

View file

@ -9,7 +9,6 @@ use crate::language_frontend::{abstract_syntax_tree::{ast::Expr, definitions::*}
pub fn parse(source: &str) ->Result<Vec<Expr>, Vec<Rich<'_, Token>>> {
let token_iter = Token::lexer(source).spanned().map(|(token, span)| (token.unwrap_or(Token::Error), span.into()));
let end_of_input: SimpleSpan = (0..source.len()).into();
let token_stream = Stream::from_iter(token_iter)
// Tell chumsky to split the (Token, SimpleSpan) stream into its parts so that it can handle the spans for us
@ -86,6 +85,18 @@ where
target: Box::new(Expr::Ident(name)),
value: Box::new(rhs),
});
/*
let fun = just(Token::Fun)
.ignore_then(ident.clone())
.then_ignore(just(Token::LParen))
.then_ignore(just(Token::RParen))
.map(|(((name, args), ret), (body, body_expr))| Expr::Function(Function {
name,
params: args,
return_type: ret,
body,
body_expr
})); */
var.or(expr)
});
@ -93,6 +104,11 @@ where
}
pub fn lex(source: &str) -> Vec<Token> {
Token::lexer(&source)
.filter_map(|t| t.ok()).collect()
}
#[cfg(test)]
mod tests {
use super::*;