From f9e49619c8d4c236303fa4c7751ceed261da4d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcial=20Gai=C3=9Fert?= Date: Tue, 4 Jun 2024 15:06:04 +0200 Subject: [PATCH] Allow matchGuards in expression position --- effekt/shared/src/main/scala/effekt/Parser.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/effekt/shared/src/main/scala/effekt/Parser.scala b/effekt/shared/src/main/scala/effekt/Parser.scala index 3f800789d..d2b4f7b42 100644 --- a/effekt/shared/src/main/scala/effekt/Parser.scala +++ b/effekt/shared/src/main/scala/effekt/Parser.scala @@ -401,7 +401,9 @@ class EffektParsers(positions: Positions) extends EffektLexers(positions) { /** * Expressions */ - lazy val expr: P[Term] = matchExpr | assignExpr | orExpr | failure("Expected an expression") + lazy val expr: P[Term] = "?(" ~/> matchGuards <~ ")" ^^ { mgs => + If(mgs, Stmt.Return(Literal(true, symbols.builtins.TBoolean)), Stmt.Return(Literal(false, symbols.builtins.TBoolean))) + } | matchExpr | assignExpr | orExpr | failure("Expected an expression") lazy val orExpr: P[Term] = orExpr ~ "||" ~/ andExpr ^^ thunkedBinaryOp | andExpr lazy val andExpr: P[Term] = andExpr ~ "&&" ~/ eqExpr ^^ thunkedBinaryOp | eqExpr lazy val eqExpr: P[Term] = eqExpr ~ oneof("==", "!=") ~/ relExpr ^^ binaryOp | relExpr