Skip to content

Commit cc02b6b

Browse files
authored
Fix newline checks in parser (#1328)
1 parent f4938dc commit cc02b6b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
binop_result: Int = 1
2+
3+
/*comment*/-
4+
5+
/*comment*/ 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
–– Pkl Error ––
2+
Invalid token at position. Expected a class, typealias, method, or property.
3+
4+
x | /*comment*/-
5+
^
6+
at binopDifferentLine (file:///$snippetsDir/input/errors/binopDifferentLine.pkl)

pkl-parser/src/main/java/org/pkl/parser/Parser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,11 +1811,13 @@ private FullToken next() {
18111811
private FullToken forceNext() {
18121812
var tk = lexer.next();
18131813
precededBySemicolon = false;
1814+
var newLines = lexer.newLinesBetween;
18141815
while (tk.isAffix()) {
18151816
precededBySemicolon = precededBySemicolon || tk == Token.SEMICOLON;
18161817
tk = lexer.next();
1818+
newLines += lexer.newLinesBetween;
18171819
}
1818-
return new FullToken(tk, lexer.span(), lexer.newLinesBetween);
1820+
return new FullToken(tk, lexer.span(), newLines);
18191821
}
18201822

18211823
// Like next, but don't ignore comments

pkl-parser/src/test/kotlin/org/pkl/parser/ParserComparisonTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class ParserComparisonTest {
9393
"stringError1.pkl",
9494
"annotationIsNotExpression2.pkl",
9595
"amendsRequiresParens.pkl",
96+
"errors/binopDifferentLine.pkl",
9697
"errors/parser18.pkl",
9798
"errors/nested1.pkl",
9899
"errors/invalidCharacterEscape.pkl",

0 commit comments

Comments
 (0)