{"record":{"id":"65836bf2d74c7cc3","repo":"stanfordnlp/CoreNLP","slug":"error-parsing-to-sequence-pattern","errorCode":null,"errorMessage":"Error parsing  to sequence pattern","messagePattern":"Error parsing  to sequence pattern","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/Env.java","lineNumber":371,"sourceCode":"    return null;\n  }\n\n  public SequencePattern.PatternExpr getSequencePatternExpr(String name, boolean copy) {\n    Object obj = variables.get(name);\n    if (obj != null) {\n      if (obj instanceof SequencePattern) {\n        SequencePattern seqPattern = (SequencePattern) obj;\n        return seqPattern.getPatternExpr();\n      } else if (obj instanceof SequencePattern.PatternExpr) {\n        SequencePattern.PatternExpr pe = (SequencePattern.PatternExpr) obj;\n        return (copy)? pe.copy():pe;\n      } else if (obj instanceof NodePattern) {\n        return new SequencePattern.NodePatternExpr( (NodePattern) obj);\n      } else if (obj instanceof String) {\n        try {\n          return parser.parseSequence(this, (String) obj);\n        } catch (Exception pex) {\n          throw new RuntimeException(\"Error parsing \" + obj + \" to sequence pattern\", pex);\n        }\n      } else {\n        throw new Error(\"Invalid sequence pattern variable class: \" + obj.getClass());\n      }\n    }\n    return null;\n  }\n\n  public Object get(String name)\n  {\n      return variables.get(name);\n  }\n\n  // Functions for storing temporary thread specific variables\n  //  that are used when running tokensregex\n\n  public void push(String name, Object value) {\n    Map<String,Object> vars = threadLocalVariables.get();","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/Env.java#L353-L389","documentation":"Env.getSequencePatternExpr resolves a variable to a sequence pattern expression; when the bound object is a String it parses it via TokenSequenceParser.parseSequence, and any parse failure is wrapped in a RuntimeException 'Error parsing <obj> to sequence pattern'.","triggerScenarios":"env.bind(name, \"...\") with a string that is not valid TokensRegex sequence syntax, then using the variable in sequence position (getSequencePatternExpr / SeqVar evaluation).","commonSituations":"Rule strings with grammar errors (bad nesting, unbalanced brackets, invalid operators) bound programmatically; strings intended as literals not quoted/regex-escaped.","solutions":["Inspect the wrapped cause for the parser's error location and fix the sequence syntax","Bind a SequencePattern/PatternExpr object directly instead of a string","Validate the expression in a standalone rule file before binding programmatically"],"exampleFix":"// before\nenv.bind(\"$pat\", \"{ word:/foo/ } { \");\n// after\nenv.bind(\"$pat\", \"{ word:/foo/ }\");","handlingStrategy":"try-catch","validationCode":"try { new TokenSequenceParser().parseSequence(env, seqString); } catch (Exception e) { throw new IllegalArgumentException(\"Not valid sequence syntax: \" + seqString, e); }\nenv.bind(name, seqString);","typeGuard":null,"tryCatchPattern":"try { PatternExpr pe = env.getSequencePatternExpr(name, true); } catch (RuntimeException e) { log.error(\"Bad sequence string for {}: {}\", name, e.getMessage()); throw new IllegalArgumentException(\"Fix bound sequence: \" + name, e.getCause()); }","preventionTips":["Bind compiled SequencePattern objects instead of strings where feasible","Validate strings by parsing once at startup","Keep bracket/operator nesting simple and tested"],"tags":["tokensregex","parsing","sequence-pattern"],"backgroundTag":"invalid-regex-pattern","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"}