Skip to content

Commit

Permalink
Add updated test files
Browse files Browse the repository at this point in the history
  • Loading branch information
chengluyu committed Dec 4, 2024
1 parent 84320e3 commit 2c9be33
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 34 deletions.
15 changes: 8 additions & 7 deletions hkmc2/shared/src/test/mlscript/basics/OpBlocks.mls
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fun f(x) = if x
//│ Ident of "x"
//│ rhs = S of IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = App:
//│ lhs = Ident of "x"
//│ rhs = OpBlock of Ls of
Expand Down Expand Up @@ -120,10 +121,10 @@ fun f(x) = if x
> 0 then "a"
is 0 then "b"
//│ ╔══[PARSE ERROR] Expect an operator instead of 'is' keyword
//│ ║ l.121: is 0 then "b"
//│ ║ l.122: is 0 then "b"
//│ ╙── ^^
//│ ╔══[PARSE ERROR] Unexpected 'is' keyword here
//│ ║ l.121: is 0 then "b"
//│ ║ l.122: is 0 then "b"
//│ ╙── ^^
//│ ═══[ERROR] Unrecognized operator branch.

Expand All @@ -135,11 +136,11 @@ fun f(x) = if x
foo(A) then a
bar(B) then b
//│ ╔══[ERROR] Unrecognized term split (juxtaposition).
//│ ║ l.134: fun f(x) = if x
//│ ║ l.135: fun f(x) = if x
//│ ║ ^
//│ ║ l.135: foo(A) then a
//│ ║ l.136: foo(A) then a
//│ ║ ^^^^^^^^^^^^^^^
//│ ║ l.136: bar(B) then b
//│ ║ l.137: bar(B) then b
//│ ╙── ^^^^^^^^^^^^^^^


Expand All @@ -148,10 +149,10 @@ fun f(x) = if x
is 0 then "a"
is 1 then "b"
//│ ╔══[PARSE ERROR] Expected start of statement in this position; found 'is' keyword instead
//│ ║ l.149: is 1 then "b"
//│ ║ l.150: is 1 then "b"
//│ ╙── ^^
//│ ╔══[PARSE ERROR] Expected end of input; found literal instead
//│ ║ l.149: is 1 then "b"
//│ ║ l.150: is 1 then "b"
//│ ╙── ^
//│ = [Function: f]

Expand Down
18 changes: 9 additions & 9 deletions hkmc2/shared/src/test/mlscript/bbml/bbSyntax.mls
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,33 @@ fun id: [A] -> A -> A

x => if x == 0 then 1 else x
//│ Parsed:
//│ InfixApp(Tup(List(Ident(x))),keyword '=>',IfLike(keyword 'if',Block(List(InfixApp(App(Ident(==),Tup(List(Ident(x), IntLit(0)))),keyword 'then',IntLit(1)), Modified(keyword 'else',None,Ident(x))))))
//│ InfixApp(Tup(List(Ident(x))),keyword '=>',IfLike(keyword 'if',None,Block(List(InfixApp(App(Ident(==),Tup(List(Ident(x), IntLit(0)))),keyword 'then',IntLit(1)), Modified(keyword 'else',None,Ident(x))))))

if 1 < 2 then 1 else 0
//│ Parsed:
//│ IfLike(keyword 'if',Block(List(InfixApp(App(Ident(<),Tup(List(IntLit(1), IntLit(2)))),keyword 'then',IntLit(1)), Modified(keyword 'else',None,IntLit(0)))))
//│ IfLike(keyword 'if',None,Block(List(InfixApp(App(Ident(<),Tup(List(IntLit(1), IntLit(2)))),keyword 'then',IntLit(1)), Modified(keyword 'else',None,IntLit(0)))))

if false then 0 else 42
//│ Parsed:
//│ IfLike(keyword 'if',Block(List(InfixApp(BoolLit(false),keyword 'then',IntLit(0)), Modified(keyword 'else',None,IntLit(42)))))
//│ IfLike(keyword 'if',None,Block(List(InfixApp(BoolLit(false),keyword 'then',IntLit(0)), Modified(keyword 'else',None,IntLit(42)))))

if 24 then false else true
//│ Parsed:
//│ IfLike(keyword 'if',Block(List(InfixApp(IntLit(24),keyword 'then',BoolLit(false)), Modified(keyword 'else',None,BoolLit(true)))))
//│ IfLike(keyword 'if',None,Block(List(InfixApp(IntLit(24),keyword 'then',BoolLit(false)), Modified(keyword 'else',None,BoolLit(true)))))

if x then true else false
//│ Parsed:
//│ IfLike(keyword 'if',Block(List(InfixApp(Ident(x),keyword 'then',BoolLit(true)), Modified(keyword 'else',None,BoolLit(false)))))
//│ IfLike(keyword 'if',None,Block(List(InfixApp(Ident(x),keyword 'then',BoolLit(true)), Modified(keyword 'else',None,BoolLit(false)))))

if 1 is Int then 1 else 0
//│ Parsed:
//│ IfLike(keyword 'if',Block(List(InfixApp(InfixApp(IntLit(1),keyword 'is',Ident(Int)),keyword 'then',IntLit(1)), Modified(keyword 'else',None,IntLit(0)))))
//│ IfLike(keyword 'if',None,Block(List(InfixApp(InfixApp(IntLit(1),keyword 'is',Ident(Int)),keyword 'then',IntLit(1)), Modified(keyword 'else',None,IntLit(0)))))

fun fact = case
0 then 1
n then n * fact(n - 1)
//│ Parsed:
//│ TermDef(Fun,Ident(fact),Some(Case(Block(List(InfixApp(IntLit(0),keyword 'then',IntLit(1)), InfixApp(Ident(n),keyword 'then',App(Ident(*),Tup(List(Ident(n), App(Ident(fact),Tup(List(App(Ident(-),Tup(List(Ident(n), IntLit(1))))))))))))))))
//│ TermDef(Fun,Ident(fact),Some(Case(None,Block(List(InfixApp(IntLit(0),keyword 'then',IntLit(1)), InfixApp(Ident(n),keyword 'then',App(Ident(*),Tup(List(Ident(n), App(Ident(fact),Tup(List(App(Ident(-),Tup(List(Ident(n), IntLit(1))))))))))))))))


`42
Expand Down Expand Up @@ -186,12 +186,12 @@ g`(`1, `2)

`if x `== `0.0 then `1.0 else x
//│ Parsed:
//│ Quoted(IfLike(keyword 'if',Block(List(InfixApp(Unquoted(Quoted(App(Ident(==),Tup(List(Unquoted(Ident(x)), Unquoted(Quoted(DecLit(0.0)))))))),keyword 'then',Unquoted(Quoted(DecLit(1.0)))), Modified(keyword 'else',None,Unquoted(Ident(x)))))))
//│ Quoted(IfLike(keyword 'if',Some(Loc(1,3,bbSyntax.mls:+187)),Block(List(InfixApp(Unquoted(Quoted(App(Ident(==),Tup(List(Unquoted(Ident(x)), Unquoted(Quoted(DecLit(0.0)))))))),keyword 'then',Unquoted(Quoted(DecLit(1.0)))), Modified(keyword 'else',None,Unquoted(Ident(x)))))))


x `=> if 0 == 0 then x else `0
//│ Parsed:
//│ Quoted(InfixApp(Tup(List(Ident(x))),keyword '=>',Unquoted(IfLike(keyword 'if',Block(List(InfixApp(App(Ident(==),Tup(List(IntLit(0), IntLit(0)))),keyword 'then',Ident(x)), Modified(keyword 'else',None,Quoted(IntLit(0)))))))))
//│ Quoted(InfixApp(Tup(List(Ident(x))),keyword '=>',Unquoted(IfLike(keyword 'if',None,Block(List(InfixApp(App(Ident(==),Tup(List(IntLit(0), IntLit(0)))),keyword 'then',Ident(x)), Modified(keyword 'else',None,Quoted(IntLit(0)))))))))

region x in 42
//│ Parsed:
Expand Down
23 changes: 20 additions & 3 deletions hkmc2/shared/src/test/mlscript/codegen/Do.mls
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,32 @@ val f = case
do console.log("non-null")
1 then "unit"
_ then "other"
//│ ╔══[ERROR] Unrecognized pattern split.
//│ ╔══[ERROR] Unrecognized pattern.
//│ ║ l.25: 0 then "null"
//│ ╙── ^^^^^^^^^^^^^
//│ ╔══[ERROR] Mixed use of `do` and `then` in the `case` expression.
//│ ╟── Keyword `then` is used here.
//│ ║ l.27: 1 then "unit"
//│ ║ ^^^^^^^^^^^^^
//│ ╟── Keyword `do` is used here.
//│ ║ l.25: 0 then "null"
//│ ║ ^^^^^^^^^^^^^
//│ ║ l.26: do console.log("non-null")
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ╔══[ERROR] The following branches are unreachable.
//│ ╟── Because the previous split is full.
//│ ║ l.27: 1 then "unit"
//│ ║ ^^^^^^^^^^^^^
//│ ║ l.28: _ then "other"
//│ ╙── ^^^^^^^^^^^^^^^^
//│ f = [Function (anonymous)]

f(0)
//│ = 'null'
//│ = 'other'

f(1)
//│ = 'unit'

f(2)
//│ = 'other'

15 changes: 4 additions & 11 deletions hkmc2/shared/src/test/mlscript/codegen/ImpreativeConditionals.mls
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ let x = -1
//│ x = -1

if x < 0 do set x = 0
//│ ╔══[PARSE ERROR] Expected end of input; found 'do' keyword instead
//│ ║ l.8: if x < 0 do set x = 0
//│ ╙── ^^
//│ ╔══[ERROR] Unrecognized term split (integer literal).
//│ ║ l.8: if x < 0 do set x = 0
//│ ╙── ^
//│ ═══[RUNTIME ERROR] Error: match error


fun f(x) =
if x < 0 return 0
Math.sqrt(x)
//│ ╔══[PARSE ERROR] Unexpected 'return' keyword here
//│ ║ l.19: if x < 0 return 0
//│ ║ l.12: if x < 0 return 0
//│ ╙── ^^^^^^
//│ ╔══[ERROR] Unrecognized term split (integer literal).
//│ ║ l.19: if x < 0 return 0
//│ ║ l.12: if x < 0 return 0
//│ ╙── ^


Expand All @@ -32,10 +25,10 @@ fun hasZeroElement(xs) =
Cons(hd, tl) do set xs = tl
Nil return false
//│ ╔══[PARSE ERROR] Unexpected 'return' keyword here
//│ ║ l.31: Cons(0, tl) return true
//│ ║ l.24: Cons(0, tl) return true
//│ ╙── ^^^^^^
//│ ╔══[ERROR] Unrecognized pattern split.
//│ ║ l.31: Cons(0, tl) return true
//│ ║ l.24: Cons(0, tl) return true
//│ ╙── ^^^^^^^^^^^


6 changes: 3 additions & 3 deletions hkmc2/shared/src/test/mlscript/codegen/While.mls
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ f(Cons(1, Cons(2, Cons(3, 0))))

:fixme
() => while true then 0
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(InfixApp(Tup(List()),keyword '=>',IfLike(keyword 'while',BoolLit(true))),keyword 'then',IntLit(0)) (of class hkmc2.syntax.Tree$InfixApp)
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(InfixApp(Tup(List()),keyword '=>',IfLike(keyword 'while',None,BoolLit(true))),keyword 'then',IntLit(0)) (of class hkmc2.syntax.Tree$InfixApp)

:fixme
while log("Hello World"); false
Expand All @@ -256,14 +256,14 @@ while log("Hello World"); false
while { log("Hello World"), false }
then 0(0)
else 1
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(IfLike(keyword 'while',Block(List(App(Ident(log),Tup(List(StrLit(Hello World)))), BoolLit(false)))),keyword 'then',App(IntLit(0),Tup(List(IntLit(0))))) (of class hkmc2.syntax.Tree$InfixApp)
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(IfLike(keyword 'while',None,Block(List(App(Ident(log),Tup(List(StrLit(Hello World)))), BoolLit(false)))),keyword 'then',App(IntLit(0),Tup(List(IntLit(0))))) (of class hkmc2.syntax.Tree$InfixApp)

:fixme
while
log("Hello World")
false
then 0(0)
else 1
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(IfLike(keyword 'while',Block(List(App(Ident(log),Tup(List(StrLit(Hello World)))), BoolLit(false)))),keyword 'then',App(IntLit(0),Tup(List(IntLit(0))))) (of class hkmc2.syntax.Tree$InfixApp)
//│ /!!!\ Uncaught error: scala.MatchError: InfixApp(IfLike(keyword 'while',None,Block(List(App(Ident(log),Tup(List(StrLit(Hello World)))), BoolLit(false)))),keyword 'then',App(IntLit(0),Tup(List(IntLit(0))))) (of class hkmc2.syntax.Tree$InfixApp)


Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fun example(args) =
//│ rhs = S of Block of Ls of
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = App:
//│ lhs = App:
//│ lhs = Ident of "foo"
Expand Down
7 changes: 7 additions & 0 deletions hkmc2/shared/src/test/mlscript/ucs/syntax/And.mls
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if x
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = InfixApp:
//│ lhs = Ident of "x"
Expand All @@ -36,6 +37,7 @@ if x
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = Block of Ls of
//│ InfixApp:
//│ lhs = InfixApp:
Expand All @@ -54,6 +56,7 @@ if x is
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = Ident of "x"
//│ kw = keyword 'is'
Expand All @@ -73,6 +76,7 @@ if x is
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = Ident of "x"
//│ kw = keyword 'is'
Expand Down Expand Up @@ -102,6 +106,7 @@ if x is
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = Ident of "x"
//│ kw = keyword 'is'
Expand Down Expand Up @@ -143,6 +148,7 @@ if x is
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = Ident of "x"
//│ kw = keyword 'is'
Expand Down Expand Up @@ -181,6 +187,7 @@ if x is
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = InfixApp:
//│ lhs = Ident of "x"
//│ kw = keyword 'is'
Expand Down
2 changes: 2 additions & 0 deletions hkmc2/shared/src/test/mlscript/ucs/syntax/ConjunctMatches.mls
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = Block of Ls of
//│ InfixApp:
//│ lhs = InfixApp:
Expand Down Expand Up @@ -46,6 +47,7 @@ if
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = Block of Ls of
//│ InfixApp:
//│ lhs = InfixApp:
Expand Down
3 changes: 2 additions & 1 deletion hkmc2/shared/src/test/mlscript/ucs/syntax/Else.mls
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fun f(x, y, z) = if x then y else z
//│ Ident of "z"
//│ rhs = S of IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = Block of Ls of
//│ InfixApp:
//│ lhs = Ident of "x"
Expand Down Expand Up @@ -74,7 +75,7 @@ fun f(x, y, z) =
if
x then y else z
//│ ╔══[PARSE ERROR] Unexpected 'else' keyword here
//│ ║ l.75: x then y else z
//│ ║ l.76: x then y else z
//│ ╙── ^^^^


Expand Down
2 changes: 2 additions & 0 deletions hkmc2/shared/src/test/mlscript/ucs/syntax/Split.mls
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if f(x) ==
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = App:
//│ lhs = Ident of "=="
//│ rhs = Tup of Ls of
Expand Down Expand Up @@ -54,6 +55,7 @@ if x +
//│ Parsed tree:
//│ IfLike:
//│ kw = keyword 'if'
//│ kwLoc = N
//│ split = App:
//│ lhs = Ident of "+"
//│ rhs = Tup of Ls of
Expand Down

0 comments on commit 2c9be33

Please sign in to comment.