mirror of
https://github.com/apple/pkl.git
synced 2026-06-04 13:00:40 +02:00
Improve error message when parsing truncated let expressions (#1639)
This previously yielded ``` Unexpected token `}`. Expected `}`. ``` Pretty confusing, no? Now it's just ``` Unexpected token `}`. ``` Resolves #1638
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
foo {
|
||||
bar = let (qux = 1)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
–– Pkl Error ––
|
||||
Unexpected token `}`.
|
||||
|
||||
x | }
|
||||
^
|
||||
at letExpressionError3 (file:///$snippetsDir/input/errors/letExpressionError3.pkl)
|
||||
@@ -888,7 +888,7 @@ class GenericParserImpl {
|
||||
expect(Token.RPAREN, paramDef, "unexpectedToken", ")");
|
||||
children.add(new Node(NodeType.LET_PARAMETER_DEFINITION, paramDef));
|
||||
ff(children);
|
||||
children.add(parseExpr(expectation));
|
||||
children.add(parseExpr());
|
||||
yield new Node(NodeType.LET_EXPR, children);
|
||||
}
|
||||
case TRUE, FALSE -> new Node(NodeType.BOOL_LITERAL_EXPR, next().span);
|
||||
|
||||
@@ -1009,7 +1009,7 @@ final class ParserImpl {
|
||||
expect(Token.ASSIGN, "unexpectedToken", "=");
|
||||
var bindExpr = parseExpr(")");
|
||||
expect(Token.RPAREN, "unexpectedToken", ")");
|
||||
var exp = parseExpr(expectation);
|
||||
var exp = parseExpr();
|
||||
yield new LetExpr(param, bindExpr, exp, start.endWith(exp.span()));
|
||||
}
|
||||
case TRUE -> new BoolLiteralExpr(true, next().span);
|
||||
|
||||
@@ -99,6 +99,7 @@ class ParserComparisonTest {
|
||||
"errors/invalidCharacterEscape.pkl",
|
||||
"errors/invalidCharacterEscape2.pkl",
|
||||
"errors/invalidUnicodeEscape.pkl",
|
||||
"errors/letExpressionError3.pkl",
|
||||
"errors/unterminatedUnicodeEscape.pkl",
|
||||
"errors/keywordNotAllowedHere1.pkl",
|
||||
"errors/keywordNotAllowedHere2.pkl",
|
||||
|
||||
Reference in New Issue
Block a user