{"record":{"id":"96f2b992eda891f7","repo":"stanfordnlp/CoreNLP","slug":"unknown-sequence-pattern-variable-96f2b9","errorCode":null,"errorMessage":"Unknown sequence pattern variable ","messagePattern":"Unknown sequence pattern variable ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj","lineNumber":797,"sourceCode":"    |\n    \"[\"\n    (  node = NodeDisjConj(env)  )\n    \"]\"\n  )\n  { return node; }\n\n}\n\nSequencePattern.PatternExpr SeqVar(Env env) : {\n  SequencePattern.PatternExpr expr;\n  Token name;\n} {\n  (\n    name = <REGEXVAR>\n    {\n        expr = env.getSequencePatternExpr(name.image, true);\n        if (expr == null) {\n            throw new Error(\"Unknown sequence pattern variable \" + name.image);\n        }\n    }\n  )\n  { return expr; }\n\n}\n\nSequencePattern.PatternExpr SeqBackRef(Env env) : {\n  Token name;\n} {\n    name = <BACKREF>\n    {\n        int v = Integer.parseInt(name.image.substring(1));\n        return new SequencePattern.BackRefPatternExpr(CoreMapNodePattern.TEXT_ATTR_EQUAL_CHECKER, v);\n    }\n}\n\n","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj#L779-L815","documentation":"A plain java.lang.Error thrown by the grammar's sequence-variable production when a REGEXVAR token references a name not registered in the parsing Env (env.getSequencePatternExpr(name, true) returns null). Variables must be defined in the environment (via Env setResult/ bind) before they can be referenced in a pattern. It is thrown as an Error, not a ParseException.","triggerScenarios":"Parsing a sequence pattern containing $VAR (REGEXVAR) where $VAR was never bound in the Env, e.g. SequencePattern.compile(env, \"$MYVAR\") without env.bind or a prior rule defining MYVAR.","commonSituations":"Rules files referencing variables defined in other files that were not loaded; typos in variable names ($Date vs $DATE); loading a rule file out of order so the variable definition rule hasn't run yet.","solutions":["Define the variable before use, either with env.bind(name, value) or by loading the rule file that defines it first.","Check the variable name spelling and case against the definition in the rules file.","Load all dependent rule files into the same Env in dependency order.","Pre-validate by calling env.getSequencePatternExpr(name, false) yourself and reporting missing names with a friendly message."],"exampleFix":"// before\nSequencePattern<CoreMap> p = SequencePattern.compile(env, \"$DATE\"); // Error: Unknown sequence pattern variable $DATE\n// after\nenv.bind(\"$DATE\", SequencePattern.compile(env, \"[ { ner:DATE } ]+\"));\nSequencePattern<CoreMap> p = SequencePattern.compile(env, \"$DATE\");","handlingStrategy":"validation","validationCode":"// Pre-check: every $VAR referenced must be defined in the Env\nstatic void checkVarsDefined(Env env, String pattern) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"\\\\$[A-Za-z_][A-Za-z0-9_]*\").matcher(pattern);\n  while (m.find()) {\n    if (env.getSequencePatternExpr(m.group(), false) == null)\n      throw new IllegalArgumentException(\"Undefined variable in pattern: \" + m.group());\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  SequencePattern<CoreMap> p = SequencePattern.compile(env, pattern);\n} catch (Error e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unknown sequence pattern variable\")) {\n    throw new IllegalArgumentException(\"Define the variable with env.bind() before compiling: \" + pattern, e);\n  }\n  throw e;\n}","preventionTips":["Bind all variables (env.bind) before compiling patterns that reference them","Load defining rule files before dependent ones","Check $VAR name spelling and case","Enumerate available variables with env for diagnostics"],"tags":["parser","tokensregex","java","undefined-variable","environment"],"backgroundTag":"undefined-variable","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}