Skip to content

Commit dc166a4

Browse files
Generalize TermDef for multiple parameter lists
The member `params` is renamed to `paramLists` to reflect its new behavior. The type of `paramLists` is changed from `Opt[Ls[Tree]]` to `Ls[Tup]` to reflect its new behavior. It now returns a list of parameter tuples instead of a list of parameters.
1 parent e240898 commit dc166a4

File tree

1 file changed

+25
-23
lines changed
  • hkmc2/shared/src/main/scala/hkmc2/syntax

1 file changed

+25
-23
lines changed

hkmc2/shared/src/main/scala/hkmc2/syntax/Tree.scala

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,33 @@ private def getName(t: Tree, symNme: Opt[Tree]): (Opt[Tree], Diagnostic \/ Ident
204204

205205
trait TermDefImpl:
206206
this: TermDef =>
207-
lazy val (symName, name, params, typeParams, signature): (Opt[Tree], Diagnostic \/ Ident, Opt[Ls[Tree]], Opt[Tree], Opt[Tree]) =
208-
def rec(t: Tree, symName: Opt[Tree]):
209-
(Opt[Tree], Diagnostic \/ Ident, Opt[Ls[Tree]], Opt[Tree], Opt[Tree]) =
210-
t match
211-
case InfixApp(id: Ident, Keyword.`:`, sign) =>
212-
(symName, R(id), N, N, S(sign))
213-
// show(t: Tree): Str
214-
case InfixApp(App(id: Ident, args), Keyword.`:`, ret) =>
215-
(symName, R(id), S(args :: Nil), N, N)
216-
// show[A](t: Tree[A]): Str
217-
case InfixApp(App(App(id: Ident, typeParams: TyTup), args), Keyword.`:`, ret) =>
218-
// val sign = S(InfixApp(typeParams, Keyword.`->`, InfixApp(args, Keyword.`->`, ret)))
219-
(symName, R(id), S(args :: Nil), S(typeParams), N)
207+
lazy val (symName, name, paramLists, typeParams, signature): (Opt[Tree], Diagnostic \/ Ident, Ls[Tup], Opt[Tree], Opt[Tree]) =
208+
def rec(t: Tree, symName: Opt[Tree]): (Opt[Tree], Diagnostic \/ Ident, Ls[Tup], Opt[Tree], Opt[Tree]) = t match
209+
// fun f: Int
210+
// fun f(n1: Int): Int
211+
// fun f(n1: Int)(nn: Int): Int
212+
case InfixApp(Apps(id: Ident, paramLists), Keyword.`:`, sign) =>
213+
(symName, R(id), paramLists, N, S(sign))
214+
// fun f[T]: Int
215+
// fun f[T](n1: Int): Int
216+
// fun f[T](n1: Int)(nn: Int): Int
217+
case InfixApp(Apps(App(id: Ident, typeParams: TyTup), paramLists), Keyword.`:`, ret) =>
218+
(symName, R(id), paramLists, S(typeParams), N)
219+
220220
case InfixApp(Jux(lhs, rhs), Keyword.`:`, ret) =>
221221
rec(InfixApp(rhs, Keyword.`:`, ret), S(lhs))
222-
case id: Ident =>
223-
(symName, R(id), N, N, N)
224-
case App(id: Ident, typeParams: TyTup) =>
225-
(symName, R(id), N, S(typeParams), N)
226-
case App(id: Ident, args) =>
227-
(symName, R(id), S(args :: Nil), N, N)
228-
case App(primary: App, second) =>
229-
// TODO: handle the second parameter list
230-
val (sn, id, first, tps, sig) = rec(primary, symName)
231-
(sn, id, S(first.fold(Ls(second))(_ :+ second)), tps, sig)
222+
223+
// fun f
224+
// fun f(n1: Int)
225+
// fun f(n1: Int)(nn: Int)
226+
case Apps(id: Ident, paramLists) =>
227+
(symName, R(id), paramLists, N, N)
228+
// fun f[T]
229+
// fun f[T](n1: Int)
230+
// fun f[T](n1: Int)(nn: Int)
231+
case Apps(App(id: Ident, typeParams: TyTup), paramLists) =>
232+
(symName, R(id), paramLists, S(typeParams), N)
233+
232234
case Jux(lhs, rhs) => // happens in `fun (op) nme` form
233235
require(symName.isEmpty) // TOOD
234236
rec(rhs, S(lhs))

0 commit comments

Comments
 (0)