apple/pkl · error · GenericParserError
invalidLineContinuationEscapeSequence
invalidLineContinuationEscapeSequence
Error message
Invalid line continuation escape sequence.
What it means
A `\` line-continuation escape was found inside a string literal in an invalid position (e.g. not at end-of-line), so the parser rejects it. Pkl only allows the continuation escape immediately before a line break.
Source
Thrown at pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java:982
var start = next();
children.add(makeTerminal(start)); // string start
while (lookahead != Token.STRING_END) {
switch (lookahead) {
case STRING_PART -> {
var tk = next();
if (!tk.text(lexer).isEmpty()) {
children.add(make(NodeType.STRING_CHARS, tk.span));
}
}
case STRING_ESCAPE_NEWLINE,
STRING_ESCAPE_TAB,
STRING_ESCAPE_QUOTE,
STRING_ESCAPE_BACKSLASH,
STRING_ESCAPE_RETURN,
STRING_ESCAPE_UNICODE ->
children.add(make(NodeType.STRING_ESCAPE, next().span));
case STRING_ESCAPE_CONTINUATION ->
throw parserError("invalidLineContinuationEscapeSequence");
case INTERPOLATION_START -> {
children.add(makeTerminal(next()));
ff(children);
children.add(parseExpr(")"));
ff(children);
expect(Token.RPAREN, children, "unexpectedToken", ")");
}
case EOF -> {
var delimiter = new StringBuilder(start.text(lexer)).reverse().toString();
throw parserError("missingDelimiter", delimiter);
}
}
}
children.add(makeTerminal(next())); // string end
return new Node(NodeType.SINGLE_LINE_STRING_LITERAL_EXPR, children);
}
private Node parseMultiLineStringLiteralExpr() {View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the stray `\` if no escape was intended
- Place the `\` immediately before the newline to continue the string, with no trailing spaces
- Escape backslashes properly: write `"C:\\temp"` for a literal backslash
Example fix
// before val p = "C:\temp" // after val p = "C:\\temp" // or a real continuation: val s = "first \ second"
Defensive patterns
Strategy: validation
Validate before calling
/\\[^\n]/.test(src) // a backslash followed by something other than newline inside string content — likely an invalid continuation or needs doubling
Prevention
- Double backslashes in Windows paths and regexes inside Pkl strings
- Only use `\` at the very end of a line for continuations
- Check pasted content for stray trailing backslashes
When it happens
Trigger: The lexer produced a STRING_ESCAPE_CONTINUATION token where it is not a valid line continuation — e.g. `\` followed by characters on the same line inside a string.
Common situations: Escaping a trailing backslash unintentionally (Windows paths like "C:\temp" pasted into Pkl strings); a regex or path written without doubling backslashes; stray `\` before a non-newline character.
Related errors
- invalidUnicodeEscapeSequence
- missingDelimiter
- unexpectedEndOfFile
- stringContentMustBeginOnNewLine
- notAUnion
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/46dcd0f0b746d767.
Report an issue: GitHub.