feat: finish moving definitions and start exprs

This commit is contained in:
rvcas
2023-06-21 16:54:13 -04:00
parent fc580d4fa0
commit 3339d41fdd
12 changed files with 417 additions and 387 deletions

View File

@@ -0,0 +1,3 @@
mod sequence;
pub use sequence::parser as sequence;

View File

@@ -0,0 +1,36 @@
use chumsky::prelude::*;
use crate::{
ast::TraceKind,
expr::UntypedExpr,
parser::{error::ParseError, token::Token},
};
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
recursive(|r| {
choice((
just(Token::Trace)
.ignore_then(expr_parser(r.clone()))
.then(r.clone())
.map_with_span(|(text, then_), span| UntypedExpr::Trace {
kind: TraceKind::Trace,
location: span,
then: Box::new(then_),
text: Box::new(flexible_string_literal(text)),
}),
just(Token::ErrorTerm)
.ignore_then(expr_parser(r.clone()).or_not())
.map_with_span(|reason, span| {
UntypedExpr::error(span, reason.map(flexible_string_literal))
}),
just(Token::Todo)
.ignore_then(expr_parser(r.clone()).or_not())
.map_with_span(|reason, span| {
UntypedExpr::todo(span, reason.map(flexible_string_literal))
}),
expr_parser(r.clone())
.then(r.repeated())
.foldl(|current, next| current.append_in_sequence(next)),
))
})
}