{"record":{"id":"48b9b4d1de518a4f","repo":"apple/pkl","slug":"unexpected-token-0-expected-1","errorCode":null,"errorMessage":"Unexpected token `{0}`. Expected `{1}`.","messagePattern":"Unexpected token `(.+?)`\\. Expected `(.+?)`\\.","errorType":"exception","errorClass":"GenericParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java","lineNumber":1418,"sourceCode":"    }\n    children.add(makeTerminal(next())); // string end\n    return new Node(NodeType.STRING_CHARS, children);\n  }\n\n  private FullToken expect(Token type, String errorKey, Object... messageArgs) {\n    if (lookahead != type) {\n      var span = spanLookahead;\n      if (lookahead == Token.EOF || _lookahead.newLinesBetween > 0) {\n        // don't point at the EOF or the next line, but at the end of the last token\n        span = prev().span.stopSpan();\n      }\n      var args = messageArgs;\n      if (errorKey.startsWith(\"unexpectedToken\")) {\n        args = new Object[messageArgs.length + 1];\n        args[0] = lookahead == Token.EOF ? \"EOF\" : _lookahead.text(lexer);\n        System.arraycopy(messageArgs, 0, args, 1, messageArgs.length);\n      }\n      throw parserError(ErrorMessages.create(errorKey, args), span);\n    }\n    return next();\n  }\n\n  private void expect(Token type, List<Node> children, String errorKey, Object... messageArgs) {\n    var tk = expect(type, errorKey, messageArgs);\n    children.add(makeTerminal(tk));\n  }\n\n  private void parseListOf(Token terminator, List<Node> children, Supplier<Node> parser) {\n    children.add(parser.get());\n    ff(children);\n    while (lookahead == Token.COMMA) {\n      // don't store the last comma\n      var comma = makeTerminal(next());\n      if (lookahead() == terminator) break;\n      children.add(comma);\n      ff(children);","sourceCodeStart":1400,"sourceCodeEnd":1436,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java#L1400-L1436","documentation":"This is the expect() fast-fail path in GenericParserImpl: when a specific token type is required but absent, the parser throws an unexpectedToken error. For keys starting with \"unexpectedToken\", the actual lookahead text (or \"EOF\") is prepended to the message args, so the developer sees what was found versus what was expected.","triggerScenarios":"Any grammar production calling expect(Token, ...) where the input deviates — e.g. a missing `=`, `}`, `)`, or `,` at the reported position; or the input ends prematurely (lookahead == EOF).","commonSituations":"Hand-edited Pkl files with a dropped operator or bracket; merging conflicts resolved incorrectly; generated Pkl missing a separator between members.","solutions":["Inspect the reported token and insert or replace it with the expected token listed in the message.","Check the line above the error position — mismatches are often caused by the preceding construct not being closed.","Format the file with the Pkl formatter to normalize punctuation and reveal the structural break."],"exampleFix":"// before (missing '=')\nx 1\n\n// after\nx = 1","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  pklEval(sourceFile);\n} catch (PklParseError e) {\n  if (e.code === \"unexpectedToken\") {\n    // e.message looks like: Unexpected token `X`. Expected `Y`.\n    console.error(`Syntax fix needed near ${e.span}: ${e.message}`);\n  } else throw e;\n}","preventionTips":["Format Pkl files with `pkl format` after every manual edit.","Resolve merge conflicts in .pkl files by re-running the generator, not by hand.","Adopt editor Pkl plugins that underline missing separators in real time."],"tags":["parser","syntax-error","unexpected-token"],"backgroundTag":"schema-validation-failed","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}