Skip to content

Commit

Permalink
refactor: use ; in ParYield (#4913)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaschdoc committed Nov 14, 2022
1 parent 9f8ada9 commit 469bcd1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion main/src/ca/uwaterloo/flix/language/phase/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ class Parser(val source: Source) extends org.parboiled2.Parser {
}

rule {
SP ~ keyword("par") ~ optWS ~ "(" ~ oneOrMore(Fragment).separatedBy(optWS ~ "," ~ optWS) ~ ")" ~ optWS ~ keyword("yield") ~ WS ~ Expression ~ SP ~> ParsedAst.Expression.ParYield
SP ~ keyword("par") ~ optWS ~ "(" ~ oneOrMore(Fragment).separatedBy(optWS ~ ";" ~ optWS) ~ ")" ~ optWS ~ keyword("yield") ~ WS ~ Expression ~ SP ~> ParsedAst.Expression.ParYield
}
}

Expand Down
26 changes: 26 additions & 0 deletions main/test/ca/uwaterloo/flix/language/phase/TestParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,30 @@ class TestParser extends FunSuite with TestUtils {
expectError[ParseError](result)
}

test("ParseError.ParYield.01") {
val input =
"""
|def f(): Int32 = par () yield 1
|""".stripMargin
val result = compile(input, Options.TestWithLibNix)
expectError[ParseError](result)
}

test("ParseError.ParYield.02") {
val input =
"""
|def f(): Int32 = par a <- 1 yield a
|""".stripMargin
val result = compile(input, Options.TestWithLibNix)
expectError[ParseError](result)
}

test("ParseError.ParYield.03") {
val input =
"""
|def f(): (Int32, Int32) = par (a <- let b = 1; b; c <- 2) yield (a, c)
|""".stripMargin
val result = compile(input, Options.TestWithLibNix)
expectError[ParseError](result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ class TestRedundancy extends FunSuite with TestUtils {
val input =
"""
|def f(): Int32 =
| par (a <- 5, a <- 1) yield a
| par (a <- 5; a <- 1) yield a
|""".stripMargin
val result = compile(input, Options.TestWithLibNix)
expectError[RedundancyError.ShadowedVar](result)
Expand Down
2 changes: 1 addition & 1 deletion main/test/ca/uwaterloo/flix/language/phase/TestTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ class TestTyper extends FunSuite with TestUtils {
val input =
"""
| def f(g: Unit -> Unit \ Impure): Unit \ Impure =
| let _ = par (a <- 1, b <- { 1 as \ Impure }) yield (a, b);
| let _ = par (a <- 1; b <- { 1 as \ Impure }) yield (a, b);
| g()
|""".stripMargin
val result = compile(input, Options.TestWithLibNix)
Expand Down
23 changes: 14 additions & 9 deletions main/test/flix/Test.Exp.ParYield.flix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ namespace Test/Exp/ParYield {

@test
def testParYield01(): Int32 =
par (a <- 1, b <- 2, c <- 3) yield a + b + c
par (a <- 1; b <- 2; c <- 3) yield a + b + c

@test
def testParYield02(): Int32 =
par ((a, b) <- (1, 2), (c, d, e) <- (3, 4, 5), f <- 6)
par ((a, b) <- (1, 2); (c, d, e) <- (3, 4, 5); f <- 6)
yield a + b + c + d + e + f

@test
def testParYield03(): Bool =
let x = par (a <- 1, b <- 2, c <- 3) yield a + b + c;
let x = par (a <- 1; b <- 2; c <- 3) yield a + b + c;
x == 6

@test
Expand All @@ -20,27 +20,27 @@ namespace Test/Exp/ParYield {

@test
def testParYield05(): Int32 =
par (a <- 5, b <- let a = 1; a) yield a + b
par (a <- 5; b <- let a = 1; a) yield a + b

@test
def testParYield06(): Bool =
(par (a <- 5, b <- let a = 1; a) yield a + b) == 6
(par (a <- 5; b <- let a = 1; a) yield a + b) == 6

@test
def testParYield07(): Int32 =
par (a <- par (a <- 5, b <- 6, c <- 7) yield a + b + c, b <- 10) yield a + b
par (a <- par (a <- 5; b <- 6; c <- 7) yield a + b + c; b <- 10) yield a + b

@test
def testParYield08(): Bool =
(par (a <- par (a <- 5, b <- 6, c <- 7) yield a + b + c, b <- 10) yield a + b) == 28
(par (a <- par (a <- 5; b <- 6; c <- 7) yield a + b + c; b <- 10) yield a + b) == 28

@test
def testParYield09(): Int32 =
par (a <- 1, b <- par (c <- 2, d <- par (e <- 10) yield e) yield d + c) yield b + a
par (a <- 1; b <- par (c <- 2; d <- par (e <- 10) yield e) yield d + c) yield b + a

@test
def testParYield10(): Bool =
(par (a <- 1, b <- par (c <- 2, d <- par (e <- 3) yield e) yield d + c) yield b + a) == 6
(par (a <- 1; b <- par (c <- 2; d <- par (e <- 3) yield e) yield d + c) yield b + a) == 6

@test
def testParYield11(): Int32 =
Expand All @@ -61,4 +61,9 @@ namespace Test/Exp/ParYield {
let a = ref 10 @ r;
(par (x <- 1) yield x + deref a) == 11
}

@test
def testParYield15(): Bool =
(par (a <- 5; b <- (let a = 1; a); c <- 6) yield a + b + c) == 12

}

0 comments on commit 469bcd1

Please sign in to comment.