fix: some attempted adjustments
This commit is contained in:
parent
252b760ca1
commit
2edfd33594
|
@ -1,25 +1,48 @@
|
||||||
use chumsky::prelude::*;
|
use chumsky::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
ast::TraceKind,
|
||||||
expr::UntypedExpr,
|
expr::UntypedExpr,
|
||||||
parser::{
|
parser::{
|
||||||
error::ParseError,
|
error::ParseError,
|
||||||
expr::{block::parser as block, string},
|
expr::{string, when::clause},
|
||||||
token::Token,
|
token::Token,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn parser(
|
pub fn parser<'a>(
|
||||||
sequence: Recursive<'_, Token, UntypedExpr, ParseError>,
|
expression: Recursive<'a, Token, UntypedExpr, ParseError>,
|
||||||
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
sequence: Recursive<'a, Token, UntypedExpr, ParseError>,
|
||||||
let message = || choice((string::hybrid(), block(sequence.clone())));
|
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + 'a {
|
||||||
choice((
|
choice((
|
||||||
just(Token::Todo)
|
just(Token::Todo).ignore_then(choice((
|
||||||
.ignore_then(message().or_not())
|
clause(expression.clone())
|
||||||
|
.ignored()
|
||||||
|
.rewind()
|
||||||
|
.map_with_span(|_, span| UntypedExpr::todo(None, span)),
|
||||||
|
choice((string::hybrid(), expression.clone()))
|
||||||
|
.or_not()
|
||||||
.map_with_span(UntypedExpr::todo),
|
.map_with_span(UntypedExpr::todo),
|
||||||
just(Token::Fail)
|
))),
|
||||||
.ignore_then(message().or_not())
|
just(Token::Fail).ignore_then(choice((
|
||||||
|
clause(expression.clone())
|
||||||
|
.ignored()
|
||||||
|
.rewind()
|
||||||
|
.map_with_span(|_, span| UntypedExpr::fail(None, span)),
|
||||||
|
choice((string::hybrid(), expression.clone()))
|
||||||
|
.or_not()
|
||||||
.map_with_span(UntypedExpr::fail),
|
.map_with_span(UntypedExpr::fail),
|
||||||
|
))),
|
||||||
|
just(Token::Trace)
|
||||||
|
.ignore_then(clause(expression.clone()).or_not().ignored().rewind())
|
||||||
|
.ignore_then(choice((string::hybrid(), expression.clone())))
|
||||||
|
.then(sequence.clone())
|
||||||
|
.map_with_span(|(text, then_), span| UntypedExpr::Trace {
|
||||||
|
kind: TraceKind::Trace,
|
||||||
|
location: span,
|
||||||
|
then: Box::new(then_),
|
||||||
|
text: Box::new(text),
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,4 +94,22 @@ mod tests {
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fail_empty() {
|
||||||
|
assert_expr!(
|
||||||
|
r#"
|
||||||
|
fail
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trace_expr() {
|
||||||
|
assert_expr!(
|
||||||
|
r#"
|
||||||
|
trace some_var
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub fn parser(
|
||||||
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
||||||
recursive(|expression| {
|
recursive(|expression| {
|
||||||
choice((
|
choice((
|
||||||
fail_todo(sequence.clone()),
|
fail_todo(expression.clone(), sequence.clone()),
|
||||||
pure_expression(sequence, expression),
|
pure_expression(sequence, expression),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,15 +13,19 @@ use crate::{
|
||||||
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||||
recursive(|sequence| {
|
recursive(|sequence| {
|
||||||
choice((
|
choice((
|
||||||
just(Token::Trace)
|
// just(Token::Trace)
|
||||||
.ignore_then(choice((string::hybrid(), block(sequence.clone()))))
|
// .ignore_then(choice((
|
||||||
.then(sequence.clone())
|
// string::hybrid(),
|
||||||
.map_with_span(|(text, then_), span| UntypedExpr::Trace {
|
// block(sequence.clone()),
|
||||||
kind: TraceKind::Trace,
|
// sequence.clone(),
|
||||||
location: span,
|
// )))
|
||||||
then: Box::new(then_),
|
// .then(sequence.clone())
|
||||||
text: Box::new(text),
|
// .map_with_span(|(text, then_), span| UntypedExpr::Trace {
|
||||||
}),
|
// kind: TraceKind::Trace,
|
||||||
|
// location: span,
|
||||||
|
// then: Box::new(then_),
|
||||||
|
// text: Box::new(text),
|
||||||
|
// }),
|
||||||
super::parser(sequence.clone())
|
super::parser(sequence.clone())
|
||||||
.then(sequence.repeated())
|
.then(sequence.repeated())
|
||||||
.foldl(|current, next| current.append_in_sequence(next)),
|
.foldl(|current, next| current.append_in_sequence(next)),
|
||||||
|
|
|
@ -581,3 +581,14 @@ fn format_int_uint() {
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fail_expr() {
|
||||||
|
assert_format!(
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
fail some_var
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue