Skip to content

Commit

Permalink
Remove inRecord from NewParser and mark related test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chengluyu committed Nov 22, 2023
1 parent 0c65802 commit 8a8242a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
24 changes: 12 additions & 12 deletions shared/src/main/scala/mlscript/NewParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
case Nil => Nil
case (KEYWORD("of"), _) :: _ =>
consume
Tup(args(false, false) // TODO
Tup(args(false) // TODO
) :: funParams
case (br @ BRACKETS(Round, toks), loc) :: _ =>
consume
Expand Down Expand Up @@ -614,7 +614,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
exprCont(Var(opStr).withLoc(S(l1)), prec, allowNewlines = false)
case (br @ BRACKETS(bk @ (Round | Square | Curly), toks), loc) :: _ =>
consume
val res = rec(toks, S(br.innerLoc), br.describe).concludeWith(_.argsMaybeIndented(bk === Curly))
val res = rec(toks, S(br.innerLoc), br.describe).concludeWith(_.argsMaybeIndented())
val bra = (bk, res) match {
case (Curly, _) =>
Bra(true, Rcd(res.map {
Expand Down Expand Up @@ -1094,8 +1094,8 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
case _ => f(this, false)
}

final def argsMaybeIndented(inRecord: Bool = false)(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> Fld] =
maybeIndented(_.args(inRecord, _))
final def argsMaybeIndented()(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> Fld] =
maybeIndented(_.args(_))
// final def argsMaybeIndented()(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> Fld] =
// cur match {
// case (br @ BRACKETS(Indent, toks), _) :: _ if (toks.headOption match {
Expand All @@ -1108,9 +1108,9 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
// }

// TODO support comma-less arg blocks...?
final def args(inRecord: Bool, allowNewlines: Bool, prec: Int = NoElsePrec)(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> Fld] =
final def args(allowNewlines: Bool, prec: Int = NoElsePrec)(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> Fld] =
// argsOrIf(Nil).map{case (_, L(x))=> ???; case (n, R(x))=>n->x} // TODO
argsOrIf(Nil, Nil, inRecord, allowNewlines, prec).flatMap{case (n, L(x))=>
argsOrIf(Nil, Nil, allowNewlines, prec).flatMap{case (n, L(x))=>
err(msg"Unexpected 'then'/'else' clause" -> x.toLoc :: Nil)
n->Fld(FldFlags.empty, errExpr)::Nil
case (n, R(x))=>n->x::Nil} // TODO
Expand All @@ -1125,7 +1125,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
}
}
*/
final def argsOrIf(acc: Ls[Opt[Var] -> (IfBody \/ Fld)], seqAcc: Ls[Statement], inRecord: Bool, allowNewlines: Bool, prec: Int = NoElsePrec)
final def argsOrIf(acc: Ls[Opt[Var] -> (IfBody \/ Fld)], seqAcc: Ls[Statement], allowNewlines: Bool, prec: Int = NoElsePrec)
(implicit fe: FoundErr, et: ExpectThen): Ls[Opt[Var] -> (IfBody \/ Fld)] =
wrap(acc, seqAcc) { l =>

Expand All @@ -1139,7 +1139,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
}
case (SPACE, _) :: _ =>
consume
argsOrIf(acc, seqAcc, inRecord, allowNewlines, prec)
argsOrIf(acc, seqAcc, allowNewlines, prec)
case (NEWLINE, _) :: _ => // TODO: | ...
assert(seqAcc.isEmpty)
acc.reverse
Expand Down Expand Up @@ -1173,7 +1173,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
consume
consume
S(Var(idStr).withLoc(S(l0)))
case (LITVAL(IntLit(i)), l0) :: (KEYWORD(":"), _) :: _ if inRecord => // TODO: | ...
case (LITVAL(IntLit(i)), l0) :: (KEYWORD(":"), _) :: _ => // TODO: | ...
consume
consume
S(Var(i.toString).withLoc(S(l0)))
Expand All @@ -1192,10 +1192,10 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
case (COMMA, l0) :: (NEWLINE, l1) :: _ =>
consume
consume
argsOrIf(mkSeq :: acc, Nil, inRecord, allowNewlines)
argsOrIf(mkSeq :: acc, Nil, allowNewlines)
case (COMMA, l0) :: _ =>
consume
argsOrIf(mkSeq :: acc, Nil, inRecord, allowNewlines)
argsOrIf(mkSeq :: acc, Nil, allowNewlines)
case (NEWLINE, l1) :: _ if allowNewlines =>
consume
argName match {
Expand All @@ -1206,7 +1206,7 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
e match {
case L(_) => ???
case R(Fld(FldFlags(false, false, _), res)) =>
argsOrIf(acc, res :: seqAcc, false, allowNewlines)
argsOrIf(acc, res :: seqAcc, allowNewlines)
case R(_) => ???
}
case _ =>
Expand Down
17 changes: 15 additions & 2 deletions shared/src/test/diff/nu/Ascription.mls
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ foo(123 : Int) : Int
//│ res
//│ = 124

:e
foo(123: Int): Int
//│ ╔══[ERROR] Cannot use named arguments as the function type has untyped arguments
//│ ║ l.35: foo(123: Int): Int
//│ ╙── ^^^^^^^^^^
//│ Int
//│ Code generation encountered an error:
//│ unresolved symbol Int

:e
foo(123:Int):Int
//│ ╔══[ERROR] Cannot use named arguments as the function type has untyped arguments
//│ ║ l.44: foo(123:Int):Int
//│ ╙── ^^^^^^^^^
//│ Int
//│ res
//│ = 124
//│ Code generation encountered an error:
//│ unresolved symbol Int

2 changes: 1 addition & 1 deletion shared/src/test/diff/nu/Interfaces.mls
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ class Bc12() extends Bc1(1), Bc2(true)
//│ Code generation encountered an error:
//│ unexpected parent symbol new class Bc2.

class Bc02() extends Bc1(1:Int) {
class Bc02() extends Bc1(1 : Int) {
val foo = 2
}
//│ class Bc02() extends Bc1 {
Expand Down

0 comments on commit 8a8242a

Please sign in to comment.