apple/pkl · error · ParserError
invalidLineContinuationEscapeSequenceWhitespace
invalidLineContinuationEscapeSequenceWhitespace
Error message
Invalid line continuation escape sequence. Whitespace between the continuation escape and following newline is not allowed.
What it means
Pkl treats `\` followed by a newline as a line continuation inside strings, but the escape sequence `\` was followed by whitespace (spaces/tabs) before the newline, which is not allowed. The lexer detects `\` + [ \t]+ + newline and reports that the whitespace between the continuation escape and the newline is invalid.
Source
Thrown at pkl-parser/src/main/java/org/pkl/parser/Lexer.java:475
var scope = interpolationStack.getFirst();
scope.parens++;
state = State.DEFAULT;
yield Token.INTERPOLATION_START;
}
case 'u' -> lexUnicodeEscape();
case '\n' -> Token.STRING_ESCAPE_CONTINUATION;
case '\r' -> {
if (lookahead == '\n') {
nextChar();
}
yield Token.STRING_ESCAPE_CONTINUATION;
}
case ' ', '\t' -> {
var c = cursor;
var next = nextChar();
while (next == ' ' || next == '\t') next = nextChar();
if (next == '\n' || next == '\r')
throw lexError(
ErrorMessages.create("invalidLineContinuationEscapeSequenceWhitespace"),
c - 2,
cursor - c + 2);
throw lexError(
ErrorMessages.create("invalidCharacterEscapeSequence", "\\" + (char) ch, "\\"),
c - 2,
2);
}
default ->
throw lexError(
ErrorMessages.create("invalidCharacterEscapeSequence", "\\" + (char) ch, "\\"),
cursor - 2,
2);
};
}
private Token lexUnicodeEscape() {View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove all spaces/tabs between the `\` and the newline so `\` is immediately followed by the line break.
- If the whitespace is meaningful, move it after the newline or into the string content of the next line.
- If no continuation was intended, escape the backslash as `\\` so the trailing spaces become ordinary characters.
Example fix
// before long = "first line \ second" // after long = "first line \ second"
Defensive patterns
Strategy: validation
Validate before calling
function badContinuation(src) { return /\\[ \t]+(\r?\n)/.test(src); }
if (badContinuation(src)) throw new Error('Whitespace after line-continuation backslash is not allowed'); Type guard
null
Try / catch
try { tokens = lexer.next(); } catch (e) { if (e.code === 'invalidLineContinuationEscapeSequenceWhitespace') { console.error('Remove spaces/tabs after \\ before newline'); } throw e; } Prevention
- Enable editor 'trim trailing whitespace on save'.
- Keep the backslash as the last character before the newline.
- Disable alignment formatting that pads after backslashes.
- Review diffs for trailing whitespace on continuation lines.
When it happens
Trigger: nextString → lexEscape, case ' ' or '\t': after a backslash, the next characters are one or more spaces/tabs and then a `\n` or `\r`. E.g. `"foo \ "` where a space slipped in between `\` and the line break.
Common situations: Editors auto-trimming... or rather auto-indenting the next line leaving trailing spaces before the newline; hand-formatting a long string and accidentally typing spaces after the `\`; copy-paste where a line continuation `\` gained trailing whitespace; lint formatters inserting alignment spaces after the backslash.
Related errors
- invalidCharacterEscapeSequence
- unexpectedCharacter
- unterminatedUnicodeEscapeSequence
- invalidUnicodeEscapeSequence
- unseparatedObjectMembers
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/fe92390545f076c4.
Report an issue: GitHub.