diff --git a/hkmc2/shared/src/main/scala/hkmc2/syntax/Parser.scala b/hkmc2/shared/src/main/scala/hkmc2/syntax/Parser.scala index e0bd732c3..7a6ba4326 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/syntax/Parser.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/syntax/Parser.scala @@ -900,7 +900,7 @@ abstract class Parser( case (NEWLINE, _) :: (KEYWORD(kw), _) :: _ if kw.canStartInfixOnNewLine && kw.leftPrecOrMin > prec && infixRules.kwAlts.contains(kw.name) - && kw != Keyword.`do` // This is to avoid the following case: + && (kw isnt Keyword.`do`) // This is to avoid the following case: // ``` // 0 then "null" // do console.log("non-null") diff --git a/hkmc2/shared/src/test/mlscript/codegen/While.mls b/hkmc2/shared/src/test/mlscript/codegen/While.mls index 9b1830199..249d239f9 100644 --- a/hkmc2/shared/src/test/mlscript/codegen/While.mls +++ b/hkmc2/shared/src/test/mlscript/codegen/While.mls @@ -143,6 +143,14 @@ let i = 0 in while //│ > 2 //│ > 3 +let i = 0 in while + do log(i) + i < 3 do set i += 1 +//│ > 0 +//│ > 1 +//│ > 2 +//│ > 3 + // * Note that the semantics of UCS-while is quite subtle. // * Currently, we only treat the *top-level* `else` as terminating the loop; @@ -232,6 +240,16 @@ f(Cons(1, Cons(2, Cons(3, 0)))) //│ > 3 //│ > Done! +fun f(ls) = + while + do print(ls) + ls is Cons(h, tl) do set ls = tl + +f(Cons(1, Cons(2, Cons(3, 0)))) +//│ > Cons(1, Cons(2, Cons(3, 0))) +//│ > Cons(2, Cons(3, 0)) +//│ > Cons(3, 0) +//│ > 0 // ——— FIXME: ——— @@ -246,7 +264,7 @@ while log("Hello World"); false then 0(0) else 1 //│ ╔══[PARSE ERROR] Unexpected 'then' keyword here -//│ ║ l.246: then 0(0) +//│ ║ l.264: then 0(0) //│ ╙── ^^^^ //│ ═══[ERROR] Unrecognized term split (false literal). //│ ═══[RUNTIME ERROR] Error: match error diff --git a/hkmc2/shared/src/test/mlscript/ucs/syntax/Do.mls b/hkmc2/shared/src/test/mlscript/ucs/syntax/Do.mls index 6390900a5..0e42340b3 100644 --- a/hkmc2/shared/src/test/mlscript/ucs/syntax/Do.mls +++ b/hkmc2/shared/src/test/mlscript/ucs/syntax/Do.mls @@ -16,6 +16,21 @@ if x do x //│ = false +if not(x) do + print("executed") +//│ > executed + +:e +:re +if not of x do + print("executed") +//│ ╔══[ERROR] Unrecognized term split (application). +//│ ║ l.25: if not of x do +//│ ║ ^^^^^^^^^^^ +//│ ║ l.26: print("executed") +//│ ╙── ^^^^^^^^^^^^^^^^^^^ +//│ ═══[RUNTIME ERROR] Error: match error + if (not of x) do print("executed") set x = false @@ -56,10 +71,10 @@ fun g(y) = x //│ ╔══[ERROR] Mixed use of `do` and `then` in the `if` expression. //│ ╟── Keyword `then` is used here. -//│ ║ l.55: Some(v) and v % 2 == 0 then set x = Some(v / 2) +//│ ║ l.70: Some(v) and v % 2 == 0 then set x = Some(v / 2) //│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //│ ╟── Keyword `do` is used here. -//│ ║ l.54: Some(0) do set x = None +//│ ║ l.69: Some(0) do set x = None //│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^ g(0)