mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
fix(compiler): Fix if
with brackets parsing (#812)
This commit is contained in:
parent
50ba194b86
commit
4c3c32b7c4
@ -24,8 +24,10 @@ object ArrowExpr extends Expr.AndIndented {
|
||||
PushToStreamExpr ::
|
||||
ForExpr ::
|
||||
Expr.defer(OnExpr) ::
|
||||
CallArrowExpr ::
|
||||
// It is important for IfExpr to be before CallArrowExpr
|
||||
// because `if (1 + 1) == 2` is parsed as if `if(1 + 1)` is an arrow call
|
||||
IfExpr ::
|
||||
CallArrowExpr ::
|
||||
TryExpr ::
|
||||
ElseOtherwiseExpr ::
|
||||
CatchExpr ::
|
||||
|
@ -16,6 +16,7 @@ import aqua.parser.lift.LiftParser.Implicits.idLiftParser
|
||||
import aqua.types.ScalarType.*
|
||||
import cats.Id
|
||||
import cats.data.{Chain, NonEmptyList}
|
||||
import cats.data.Chain.*
|
||||
import cats.free.Cofree
|
||||
import cats.syntax.foldable.*
|
||||
import cats.data.Validated.{Invalid, Valid}
|
||||
@ -23,6 +24,7 @@ import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.{Inside, Inspectors}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import cats.~>
|
||||
import cats.Eval
|
||||
|
||||
import scala.collection.mutable
|
||||
import scala.language.implicitConversions
|
||||
@ -286,4 +288,27 @@ class FuncExprSpec extends AnyFlatSpec with Matchers with Inside with Inspectors
|
||||
|
||||
parser.parseAll(script).value.toEither.isRight shouldBe true
|
||||
}
|
||||
|
||||
"function with if" should "be parsed correctly" in {
|
||||
val script =
|
||||
"""func ifTest():
|
||||
| if (1 + 1) == 2:
|
||||
| Test.test("one")
|
||||
|
|
||||
| if 2 < 3 != (1 > 2):
|
||||
| Test.test("two")
|
||||
|""".stripMargin
|
||||
|
||||
inside(parser.parseAll(script).value) { case Valid(ast) =>
|
||||
ast
|
||||
.cata[Int]((expr, results) =>
|
||||
// Count `if`s inside the tree
|
||||
Eval.later(results.sumAll + (expr match {
|
||||
case IfExpr(_, _, _) => 1
|
||||
case _ => 0
|
||||
}))
|
||||
)
|
||||
.value shouldBe 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user