/** AUTO-GENERATED by scripts/gen-delimiter-oracle.ts — DO NOT EDIT. */
export type DelimiterOracleKind = 'parse-fail' | 'eval-crash';

export interface DelimiterOracleEntry {
  id: string;
  kind: DelimiterOracleKind;
  /** Regex applied to a parse OR eval error message. */
  detectPattern: string;
  /** Human-readable list of mechanical edits the runtime tries. */
  candidateEdits: string;
  fixtureBefore: string;
  fixtureAfter: string;
  /** Populated only when the crash surfaces at eval time (parse-clean before). */
  evalErrorSample?: string;
}

export const DELIMITER_ORACLE: DelimiterOracleEntry[] = [
  {
    "id": "regex-literal",
    "kind": "eval-crash",
    "detectPattern": "Invalid regular expression|Unterminated regular expression",
    "candidateEdits": "heal unterminated /…/: append trailing / on lines with odd unescaped slash count; close char-class ] before the final /; escape intentional slashes",
    "fixtureBefore": "const re = /[a-z+;\n",
    "fixtureAfter": "const re = /[a-z+;]/;\n",
    "evalErrorSample": "Invalid regular expression: missing /"
  },
  {
    "id": "quote-single",
    "kind": "parse-fail",
    "detectPattern": "Unterminated string|Unexpected token",
    "candidateEdits": "close unterminated single-quoted string with matching '; strip stray leading/trailing quote when the run is un-paired",
    "fixtureBefore": "const x = 'hello\n",
    "fixtureAfter": "const x = 'hello';\n"
  },
  {
    "id": "quote-double",
    "kind": "parse-fail",
    "detectPattern": "Unterminated string|Unexpected token",
    "candidateEdits": "close unterminated double-quoted string with matching \"; strip stray leading/trailing quote when the run is un-paired",
    "fixtureBefore": "const x = \"hello\n",
    "fixtureAfter": "const x = \"hello\";\n"
  },
  {
    "id": "template-backtick",
    "kind": "parse-fail",
    "detectPattern": "Unterminated (?:template|string)|Unexpected token",
    "candidateEdits": "close unterminated template literal with matching `; balance `${…}` interpolation braces before closing",
    "fixtureBefore": "const x = `hello\n",
    "fixtureAfter": "const x = `hello`;\n"
  },
  {
    "id": "brace",
    "kind": "parse-fail",
    "detectPattern": "Unexpected token|Unexpected end of input|expected .?\\}.?",
    "candidateEdits": "append missing } for unclosed block; strip surplus } via parser-guided delete",
    "fixtureBefore": "function f() { return 1;\n",
    "fixtureAfter": "function f() { return 1; }\n"
  },
  {
    "id": "bracket",
    "kind": "parse-fail",
    "detectPattern": "Unexpected token|Unexpected end of input|expected .?\\].?",
    "candidateEdits": "append missing ] for unclosed array/index; balance closer stack against ] openers",
    "fixtureBefore": "const a = [1, 2, 3\n",
    "fixtureAfter": "const a = [1, 2, 3];\n"
  },
  {
    "id": "paren",
    "kind": "parse-fail",
    "detectPattern": "Unexpected token|Unexpected end of input|expected .?\\).?",
    "candidateEdits": "append missing ) for unclosed call/group; insert ) before .prop when depth > 0 (missing-closer-before-dot)",
    "fixtureBefore": "const x = Math.max(1, 2\n",
    "fixtureAfter": "const x = Math.max(1, 2);\n"
  },
  {
    "id": "comma",
    "kind": "parse-fail",
    "detectPattern": "Unexpected (?:token|number)|expected .?,.?",
    "candidateEdits": "insert missing , between call args / array/object elements at the error offset; strip trailing , before closers",
    "fixtureBefore": "const x = Math.max(1 2);\n",
    "fixtureAfter": "const x = Math.max(1, 2);\n"
  },
  {
    "id": "colon-object",
    "kind": "parse-fail",
    "detectPattern": "Unexpected token|expected .?:.?",
    "candidateEdits": "insert missing : between object property key and value at the error offset",
    "fixtureBefore": "const obj = { a 1 };\n",
    "fixtureAfter": "const obj = { a: 1 };\n"
  },
  {
    "id": "arrow",
    "kind": "parse-fail",
    "detectPattern": "Unexpected token|expected .?=>.?",
    "candidateEdits": "insert missing => between arrow parameter list and body block",
    "fixtureBefore": "const f = () { return 1; };\n",
    "fixtureAfter": "const f = () => { return 1; };\n"
  },
  {
    "id": "block-comment",
    "kind": "parse-fail",
    "detectPattern": "Unterminated comment|Unexpected end of input",
    "candidateEdits": "append */ to unclosed /* comment when it runs to EOF",
    "fixtureBefore": "/* hello\nconst x = 1;\n",
    "fixtureAfter": "/* hello */\nconst x = 1;\n"
  }
];

/** Match an error message to the first delimiter-oracle entry, or null. */
export function lookupDelimiterOracle(errorMessage: string | undefined | null): DelimiterOracleEntry | null {
  if (!errorMessage) return null;
  for (const e of DELIMITER_ORACLE) {
    if (new RegExp(e.detectPattern).test(errorMessage)) return e;
  }
  return null;
}
