apple/pkl · error · ParserError

invalidLineContinuationEscapeSequence

invalidLineContinuationEscapeSequence

Error message

Invalid line continuation escape sequence.

Line continuations are only allowed in multi-line strings.

What it means

Pkl string literals do not support the `\` line-continuation escape sequence inside single-line strings; it is only meaningful in multi-line (`"""`) strings, where a backslash at end of line suppresses the newline. The parser throws this error when it encounters STRING_ESCAPE_CONTINUATION while parsing a single-line string. It is a hard syntax error at parse time.

Source

Thrown at pkl-parser/src/main/java/org/pkl/parser/ParserImpl.java:1135

        case STRING_ESCAPE_QUOTE -> {
          end = next().span;
          builder.append('"');
        }
        case STRING_ESCAPE_BACKSLASH -> {
          end = next().span;
          builder.append('\\');
        }
        case STRING_ESCAPE_RETURN -> {
          end = next().span;
          builder.append('\r');
        }
        case STRING_ESCAPE_UNICODE -> {
          var tk = next();
          end = tk.span;
          builder.append(parseUnicodeEscape(tk));
        }
        case STRING_ESCAPE_CONTINUATION ->
            throw parserError("invalidLineContinuationEscapeSequence");
        case INTERPOLATION_START -> {
          var istart = next().span;
          if (!builder.isEmpty()) {
            parts.add(new StringChars(builder.toString(), startSpan.endWith(end)));
            builder = new StringBuilder();
          }
          var exp = parseExpr(")");
          end = expect(Token.RPAREN, "unexpectedToken", ")").span;
          parts.add(new StringPart.StringInterpolation(exp, istart.endWith(end)));
          startSpan = spanLookahead;
        }
        case EOF -> {
          var delimiter = new StringBuilder(start.text(lexer)).reverse().toString();
          throw parserError("missingDelimiter", delimiter);
        }
      }
    }
    if (!builder.isEmpty()) {

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Remove the trailing backslash from the single-line string
  2. Use a multi-line string (triple-quoted `"""..."""`) if the continuation was intended
  3. Join the text onto one line, or use string concatenation/interpolation instead

Example fix

// before
greeting = "hello \
  world"
// after
greeting = """
hello \
  world
"""
Defensive patterns

Strategy: validation

Validate before calling

function hasStrayLineContinuation(src) {
  return /[^\\](\\\\)*\\$/.test(src.split('\n').filter(l => !l.trim().startsWith('"""')).join('\n'));
}

Try / catch

try { pklEval(source) } catch (e) {
  if (String(e.message).includes('Invalid line continuation escape sequence')) {
    throw new Error('Use triple-quoted """ strings for line continuations in Pkl');
  }
  throw e;
}

Prevention

When it happens

Trigger: Parsing a Pkl file that contains a single-line string ending in a backslash (e.g. `"foo \` followed by a newline), e.g. via pkl CLI eval, codegen, or `ParserImpl` direct use.

Common situations: Copy-pasting shell/JS-style line continuations into Pkl config files; hand-splitting long string values across lines in property values or module documentation.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/5c5c6eec5ec19629. Report an issue: GitHub.