mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Refactor dbg expression parsing to work more like function application
Instead of parsing dbg with an expression block, parse the dbg keyword with no additional arguments. This way the parser treats dbg just like a variable in function application. We desugar by pattern matching on `Apply(Dbg, args, called_via)` nodes. This changes the output of syntax tests since the initial AST is different, but does not change the output of can or mono. Add two new errors for dbg in expression position with either no args or too many args. This is similar to the error behavior of `crash`. Continue to parse dbg statements with an expression block, as before.
This commit is contained in:
parent
14fabdff07
commit
56c5b790a7
11 changed files with 242 additions and 72 deletions
|
@ -498,8 +498,9 @@ pub enum Expr<'a> {
|
|||
Backpassing(&'a [Loc<Pattern<'a>>], &'a Loc<Expr<'a>>, &'a Loc<Expr<'a>>),
|
||||
Expect(&'a Loc<Expr<'a>>, &'a Loc<Expr<'a>>),
|
||||
|
||||
Dbg(&'a Loc<Expr<'a>>),
|
||||
Dbg,
|
||||
DbgStmt(&'a Loc<Expr<'a>>, &'a Loc<Expr<'a>>),
|
||||
|
||||
// This form of debug is a desugared call to roc_dbg
|
||||
LowLevelDbg(&'a (&'a str, &'a str), &'a Loc<Expr<'a>>, &'a Loc<Expr<'a>>),
|
||||
|
||||
|
@ -666,7 +667,7 @@ pub fn is_expr_suffixed(expr: &Expr) -> bool {
|
|||
Expr::OpaqueRef(_) => false,
|
||||
Expr::Backpassing(_, _, _) => false, // TODO: we might want to check this?
|
||||
Expr::Expect(a, b) => is_expr_suffixed(&a.value) || is_expr_suffixed(&b.value),
|
||||
Expr::Dbg(a) => is_expr_suffixed(&a.value),
|
||||
Expr::Dbg => false,
|
||||
Expr::DbgStmt(a, b) => is_expr_suffixed(&a.value) || is_expr_suffixed(&b.value),
|
||||
Expr::LowLevelDbg(_, a, b) => is_expr_suffixed(&a.value) || is_expr_suffixed(&b.value),
|
||||
Expr::UnaryOp(a, _) => is_expr_suffixed(&a.value),
|
||||
|
@ -965,10 +966,6 @@ impl<'a, 'b> RecursiveValueDefIter<'a, 'b> {
|
|||
expr_stack.push(&condition.value);
|
||||
expr_stack.push(&cont.value);
|
||||
}
|
||||
Dbg(expr) => {
|
||||
expr_stack.reserve(1);
|
||||
expr_stack.push(&expr.value);
|
||||
}
|
||||
DbgStmt(condition, cont) => {
|
||||
expr_stack.reserve(2);
|
||||
expr_stack.push(&condition.value);
|
||||
|
@ -1046,6 +1043,7 @@ impl<'a, 'b> RecursiveValueDefIter<'a, 'b> {
|
|||
| Var { .. }
|
||||
| Underscore(_)
|
||||
| Crash
|
||||
| Dbg
|
||||
| Tag(_)
|
||||
| OpaqueRef(_)
|
||||
| MalformedIdent(_, _)
|
||||
|
@ -2533,7 +2531,7 @@ impl<'a> Malformed for Expr<'a> {
|
|||
Defs(defs, body) => defs.is_malformed() || body.is_malformed(),
|
||||
Backpassing(args, call, body) => args.iter().any(|arg| arg.is_malformed()) || call.is_malformed() || body.is_malformed(),
|
||||
Expect(condition, continuation) => condition.is_malformed() || continuation.is_malformed(),
|
||||
Dbg(expr) => expr.is_malformed(),
|
||||
Dbg => false,
|
||||
DbgStmt(condition, continuation) => condition.is_malformed() || continuation.is_malformed(),
|
||||
LowLevelDbg(_, condition, continuation) => condition.is_malformed() || continuation.is_malformed(),
|
||||
Apply(func, args, _) => func.is_malformed() || args.iter().any(|arg| arg.is_malformed()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue