feat: assert and boolean negation
This commit is contained in:
parent
c7c11d1bd5
commit
695ac409b7
|
@ -310,21 +310,6 @@ pub fn expr_parser(
|
||||||
tail,
|
tail,
|
||||||
});
|
});
|
||||||
|
|
||||||
let assignment_parser = just(Token::Let)
|
|
||||||
.ignore_then(pattern_parser())
|
|
||||||
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
|
|
||||||
.then_ignore(just(Token::Equal))
|
|
||||||
.then(r.clone())
|
|
||||||
.map_with_span(
|
|
||||||
|((pattern, annotation), value), span| expr::UntypedExpr::Assignment {
|
|
||||||
location: span,
|
|
||||||
value: Box::new(value),
|
|
||||||
pattern,
|
|
||||||
kind: ast::AssignmentKind::Let,
|
|
||||||
annotation,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let block_parser = seq_r.delimited_by(just(Token::LeftBrace), just(Token::RightBrace));
|
let block_parser = seq_r.delimited_by(just(Token::LeftBrace), just(Token::RightBrace));
|
||||||
|
|
||||||
// TODO: do guards later
|
// TODO: do guards later
|
||||||
|
@ -372,16 +357,59 @@ pub fn expr_parser(
|
||||||
clauses,
|
clauses,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let let_parser = just(Token::Let)
|
||||||
|
.ignore_then(pattern_parser())
|
||||||
|
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
|
||||||
|
.then_ignore(just(Token::Equal))
|
||||||
|
.then(r.clone())
|
||||||
|
.map_with_span(
|
||||||
|
|((pattern, annotation), value), span| expr::UntypedExpr::Assignment {
|
||||||
|
location: span,
|
||||||
|
value: Box::new(value),
|
||||||
|
pattern,
|
||||||
|
kind: ast::AssignmentKind::Let,
|
||||||
|
annotation,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let assert_parser = just(Token::Assert)
|
||||||
|
.ignore_then(pattern_parser())
|
||||||
|
.then(just(Token::Colon).ignore_then(type_parser()).or_not())
|
||||||
|
.then_ignore(just(Token::Equal))
|
||||||
|
.then(r.clone())
|
||||||
|
.map_with_span(
|
||||||
|
|((pattern, annotation), value), span| expr::UntypedExpr::Assignment {
|
||||||
|
location: span,
|
||||||
|
value: Box::new(value),
|
||||||
|
pattern,
|
||||||
|
kind: ast::AssignmentKind::Assert,
|
||||||
|
annotation,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let expr_unit_parser = choice((
|
let expr_unit_parser = choice((
|
||||||
string_parser,
|
string_parser,
|
||||||
int_parser,
|
int_parser,
|
||||||
var_parser,
|
var_parser,
|
||||||
todo_parser,
|
todo_parser,
|
||||||
list_parser,
|
list_parser,
|
||||||
assignment_parser,
|
|
||||||
block_parser,
|
block_parser,
|
||||||
when_parser,
|
when_parser,
|
||||||
))
|
let_parser,
|
||||||
|
assert_parser,
|
||||||
|
));
|
||||||
|
|
||||||
|
let op = just(Token::Bang);
|
||||||
|
|
||||||
|
let unary = op
|
||||||
|
.ignored()
|
||||||
|
.map_with_span(|_, span| span)
|
||||||
|
.repeated()
|
||||||
|
.then(expr_unit_parser)
|
||||||
|
.foldr(|span, value| expr::UntypedExpr::Negate {
|
||||||
|
location: span.union(value.location()),
|
||||||
|
value: Box::new(value),
|
||||||
|
})
|
||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
// Product
|
// Product
|
||||||
|
@ -391,9 +419,9 @@ pub fn expr_parser(
|
||||||
just(Token::Percent).to(BinOp::ModInt),
|
just(Token::Percent).to(BinOp::ModInt),
|
||||||
));
|
));
|
||||||
|
|
||||||
let product = expr_unit_parser
|
let product = unary
|
||||||
.clone()
|
.clone()
|
||||||
.then(op.then(expr_unit_parser).repeated())
|
.then(op.then(unary).repeated())
|
||||||
.foldl(|a, (op, b)| expr::UntypedExpr::BinOp {
|
.foldl(|a, (op, b)| expr::UntypedExpr::BinOp {
|
||||||
location: a.location().union(b.location()),
|
location: a.location().union(b.location()),
|
||||||
name: op,
|
name: op,
|
||||||
|
|
Loading…
Reference in New Issue