{"record":{"id":"49256e25a8ba3758","repo":"stanfordnlp/CoreNLP","slug":"error-parsing-to-node-pattern","errorCode":null,"errorMessage":"Error parsing  to node pattern","messagePattern":"Error parsing  to node pattern","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/Env.java","lineNumber":347,"sourceCode":"    if (obj != null) {\n      if (obj instanceof SequencePattern) {\n        SequencePattern seqPattern = (SequencePattern) obj;\n        if (seqPattern.getPatternExpr() instanceof SequencePattern.NodePatternExpr) {\n          return ((SequencePattern.NodePatternExpr) seqPattern.getPatternExpr()).nodePattern;\n        } else {\n          throw new Error(\"Invalid node pattern class: \" + seqPattern.getPatternExpr().getClass() + \" for variable \" + name);\n        }\n      } else if (obj instanceof SequencePattern.NodePatternExpr) {\n        SequencePattern.NodePatternExpr pe = (SequencePattern.NodePatternExpr) obj;\n        return pe.nodePattern;\n      } else if (obj instanceof NodePattern) {\n        return (NodePattern) obj;\n      } else if (obj instanceof String) {\n        try {\n          SequencePattern.NodePatternExpr pe = (SequencePattern.NodePatternExpr) parser.parseNode(this, (String) obj);\n          return pe.nodePattern;\n        } catch (Exception pex) {\n          throw new RuntimeException(\"Error parsing \" + obj + \" to node pattern\", pex);\n        }\n      } else {\n        throw new Error(\"Invalid node pattern variable class: \" + obj.getClass() + \" for variable \" + name);\n      }\n    }\n    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) {","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/Env.java#L329-L365","documentation":"When a variable bound in the environment is a String, getNodePattern parses it as a TokensRegex node expression. If TokenSequenceParser.parseNode fails, the exception is wrapped in a RuntimeException 'Error parsing <obj> to node pattern'.","triggerScenarios":"env.bind(name, \"some string\") where the string is not valid node-pattern syntax, then referencing $name in node position.","commonSituations":"Hand-written rule strings with syntax errors, quoting mistakes (unbalanced / or \"), or passing plain words containing characters the node grammar rejects.","solutions":["Fix the string so it is valid node-pattern TokensRegex syntax; inspect the wrapped cause (pex) for position info","Bind a NodePattern object directly (e.g. new Env(...) with CoreMapNodePattern) instead of a string to skip parsing","Test the expression standalone in a rule before binding"],"exampleFix":"// before\nenv.bind(\"$num\", \"[0-9]+\");\n// after\nenv.bind(\"$num\", \"/[0-9]+/\");","handlingStrategy":"try-catch","validationCode":"// pre-validate by attempting a parse before binding\ntry { new TokenSequenceParser().parseNode(env, exprString); } catch (Exception e) { throw new IllegalArgumentException(\"Not valid node syntax: \" + exprString, e); }\nenv.bind(name, exprString);","typeGuard":null,"tryCatchPattern":"try { NodePattern np = env.getNodePattern(name); } catch (RuntimeException e) { log.error(\"Bad node-pattern string for {}: {}\", name, e.getMessage()); throw new IllegalArgumentException(\"Fix bound string: \" + name, e.getCause()); }","preventionTips":["Prefer binding NodePattern objects over strings when possible","Test each string expression standalone before binding","Keep regex quoting consistent (/.../ for patterns)"],"tags":["tokensregex","parsing","node-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"}