{"record":{"id":"fe92390545f076c4","repo":"apple/pkl","slug":"invalidlinecontinuationescapesequencewhitespace","errorCode":"invalidLineContinuationEscapeSequenceWhitespace","errorMessage":"Invalid line continuation escape sequence.\n\nWhitespace between the continuation escape and following newline is not allowed.","messagePattern":"Invalid line continuation escape sequence\\.\n\nWhitespace between the continuation escape and following newline is not allowed\\.","errorType":"exception","errorClass":"ParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/Lexer.java","lineNumber":475,"sourceCode":"        var scope = interpolationStack.getFirst();\n        scope.parens++;\n        state = State.DEFAULT;\n        yield Token.INTERPOLATION_START;\n      }\n      case 'u' -> lexUnicodeEscape();\n      case '\\n' -> Token.STRING_ESCAPE_CONTINUATION;\n      case '\\r' -> {\n        if (lookahead == '\\n') {\n          nextChar();\n        }\n        yield Token.STRING_ESCAPE_CONTINUATION;\n      }\n      case ' ', '\\t' -> {\n        var c = cursor;\n        var next = nextChar();\n        while (next == ' ' || next == '\\t') next = nextChar();\n        if (next == '\\n' || next == '\\r')\n          throw lexError(\n              ErrorMessages.create(\"invalidLineContinuationEscapeSequenceWhitespace\"),\n              c - 2,\n              cursor - c + 2);\n\n        throw lexError(\n            ErrorMessages.create(\"invalidCharacterEscapeSequence\", \"\\\\\" + (char) ch, \"\\\\\"),\n            c - 2,\n            2);\n      }\n      default ->\n          throw lexError(\n              ErrorMessages.create(\"invalidCharacterEscapeSequence\", \"\\\\\" + (char) ch, \"\\\\\"),\n              cursor - 2,\n              2);\n    };\n  }\n\n  private Token lexUnicodeEscape() {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/Lexer.java#L457-L493","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlong = \"first line \\   \nsecond\"\n// after\nlong = \"first line \\\nsecond\"","handlingStrategy":"validation","validationCode":"function badContinuation(src) { return /\\\\[ \\t]+(\\r?\\n)/.test(src); }\nif (badContinuation(src)) throw new Error('Whitespace after line-continuation backslash is not allowed');","typeGuard":"null","tryCatchPattern":"try { tokens = lexer.next(); } catch (e) { if (e.code === 'invalidLineContinuationEscapeSequenceWhitespace') { console.error('Remove spaces/tabs after \\\\ before newline'); } throw e; }","preventionTips":["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."],"tags":["lexer","pkl","escape-sequence","line-continuation","whitespace"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}