{"record":{"id":"d01a138bc4dc2126","repo":"apple/pkl","slug":"unexpectedendoffile","errorCode":"unexpectedEndOfFile","errorMessage":"Unexpected end of file.","messagePattern":"Unexpected end of file\\.","errorType":"error_code","errorClass":"ParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/ParserImpl.java","lineNumber":1040,"sourceCode":"            var tk = next();\n            yield new FloatLiteralExpr(tk.text(lexer), tk.span);\n          }\n          case STRING_START -> parseSingleLineStringLiteralExpr();\n          case STRING_MULTI_START -> parseMultiLineStringLiteralExpr();\n          case IDENTIFIER -> {\n            var identifier = parseIdentifier();\n            if (lookahead == Token.LPAREN\n                && !precededBySemicolon\n                && _lookahead.newLinesBetween == 0) {\n              var args = parseArgumentList();\n              yield new UnqualifiedAccessExpr(\n                  identifier, args, identifier.span().endWith(args.span()));\n            } else {\n              yield new UnqualifiedAccessExpr(identifier, null, identifier.span());\n            }\n          }\n          case EOF ->\n              throw new ParserError(\n                  ErrorMessages.create(\"unexpectedEndOfFile\"), prev.span.stopSpan().move(1));\n          default -> {\n            var text = _lookahead.text(lexer);\n            if (expectation != null) {\n              throw parserError(\"unexpectedToken\", text, expectation);\n            }\n            throw parserError(\"unexpectedTokenForExpression\", text);\n          }\n        };\n    return parseExprRest(expr);\n  }\n\n  @SuppressWarnings(\"DuplicatedCode\")\n  private Expr parseExprRest(Expr expr) {\n    // non-null\n    if (lookahead == Token.NON_NULL) {\n      var end = next().span;\n      var res = new NonNullExpr(expr, expr.span().endWith(end));","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/ParserImpl.java#L1022-L1058","documentation":"The Pkl parser reached the end of the input file while it still expected more tokens — for example in the middle of an expression, argument list, or identifier reference. The parser throws this instead of a generic unexpected-token error when the lookahead token is EOF, because the real problem is missing input, not wrong input. It points at the position one past the last parsed token.","triggerScenarios":"Calling the parser (e.g. via pkl.evaluateSource / ParserImpl.parse) on source that ends prematurely: an unclosed `{`, `(`, `[`, or string literal, a trailing operator like `1 +`, a dangling `->` in a type, or a truncated file passed in.","commonSituations":"Files cut off by an incomplete download or failed save; copy-pasting a snippet and dropping the closing brace; generating Pkl code programmatically and emitting an unbalanced delimiter; heredoc/template tooling swallowing the final lines.","solutions":["Scan the source at the reported stop position and close the nearest unclosed bracket, paren, or quote above it","Check for a trailing incomplete expression (e.g. a dangling operator or arrow) and complete or remove it","Verify the file was fully written/transferred — compare byte size or re-save the source","If generating Pkl programmatically, assert balanced delimiters before invoking the parser"],"exampleFix":"// before (truncated)\nx = foo(\n// after\nx = foo(1, 2)","handlingStrategy":"try-catch","validationCode":"function checkBalancedDelimiters(src) {\n  const pairs = {'{':'}','(':')','[':']'};\n  const stack = [];\n  let inStr = false, esc = false;\n  for (const ch of src) {\n    if (esc) { esc = false; continue; }\n    if (ch === '\\\\') { esc = true; continue; }\n    if (ch === '\"') { inStr = !inStr; continue; }\n    if (inStr) continue;\n    if (pairs[ch]) stack.push(pairs[ch]);\n    else if (Object.values(pairs).includes(ch) && stack.pop() !== ch) return false;\n  }\n  return !inStr && stack.length === 0;\n}\n// run before invoking the parser; abort if false","typeGuard":"null","tryCatchPattern":"try {\n  const result = pkl.evaluateSource(src);\n} catch (e) {\n  if (e instanceof ParserError && e.errorId === 'unexpectedEndOfFile') {\n    // append missing closers or report position e.span.start\n  } else { throw e; }\n}","preventionTips":["Lint source for balanced brackets/quotes before parsing","Never truncate generated Pkl output — write files atomically","Use an editor with Pkl syntax highlighting to catch unclosed delimiters early"],"tags":["parser","syntax-error","pkl","eof"],"backgroundTag":"unexpected-end-of-input","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}