{"record":{"id":"8b492acb3cba8520","repo":"stanfordnlp/CoreNLP","slug":"use-of-in-semgrex-patterns-is-now-illegal-it-i-8b492a","errorCode":null,"errorMessage":"Use of & in semgrex patterns is now illegal.  It is equivalent to the same expression without the &.  Offending expression: ","messagePattern":"Use of & in semgrex patterns is now illegal\\.  It is equivalent to the same expression without the &\\.  Offending expression: ","errorType":"exception","errorClass":"SemgrexParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj","lineNumber":106,"sourceCode":"  // a local variable\n} {\n  {\n    // start from 1 since we haven't parsed anything yet\n    startToken = getToken(1);\n  }\n  (\n    (\n      (reverse = <ALIGNRELN> node = SubNode(GraphRelation.ALIGNED_ROOT))\n      |\n      ( node = SubNode(GraphRelation.ROOT) { children.add(node); }\n        ( \":\" node = SubNode(GraphRelation.ITERATOR) { children.add(node); } )*\n      )\n    )\n    {\n      if (children.size() > 1)\n        node = new CoordinationPattern(true, children, true, true);\n      if (deprecatedAmp) {\n        throw new SemgrexParseException(\"Use of & in semgrex patterns is now illegal.  It is equivalent to the same expression without the &.  Offending expression: \" + startToken);\n      }\n      if (deprecatedNodeConj) {\n        throw new SemgrexParseException(\"Use of node conjugation (expressions such as '< [foo bar]' or '< [foo & bar]') is now illegal.  The issue is that expressions such as '[foo bar] < zzz' may intuitively mean that foo < zzz, bar < zzz, zzz the same for both cases, but that is not the way the parser interpreted this expression.  Changing the functionality might break existing expressions, and anyway this can be rewritten in various ways such as 'zzz > foo > bar' or 'foo < zzz=a : bar < zzz=a'.  Offending expression: \" + startToken);\n      }\n    }\n  )\n  (\n    (\n      \"::\" <UNIQ> { uniqKeys = new ArrayList<>(); }  (nextIdentifier = identifier() { uniqKeys.add(nextIdentifier.image); })*\n      {\n        for (String key : uniqKeys) {\n          if (!knownVariables.contains(key)) {\n            throw new SemgrexParseException(\"Semgrex pattern asked for uniq of node \" + key + \" which does not exist in the pattern\");\n          }\n        }\n        // TODO: can error check that the keys are unique between node and edge names\n        // that might require keeping edge names in a known set\n        // TODO: edge names might need some upgrades anyway - shouldn't name them under negation, for example","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj#L88-L124","documentation":"SemgrexParser no longer permits '&' inside semgrex coordination/negation expressions. Since '&' was equivalent to plain juxtaposition (conjunction within brackets), its use is rejected outright with SemgrexParseException naming the offending token. This enforces the deprecation of ambiguous legacy syntax.","triggerScenarios":"Parsing a semgrex pattern containing '&' as a conjunction operator between node expressions, e.g. '{tag:NN} < [foo & bar]', or legacy patterns with '&' carried over from older CoreNLP.","commonSituations":"Running old semgrex strings from published papers or scripts against a newer CoreNLP; hand-writing patterns that mimic tregex syntax.","solutions":["Remove the '&' and keep the plain juxtaposed expressions inside the brackets","Split the pattern into simpler sub-patterns or use named edges (e.g. 'zzz > foo > bar')","Rewrite coordinated semantics explicitly, e.g. 'foo < zzz=a : bar < zzz=a'"],"exampleFix":"// before\nSemgrexPattern p = SemgrexPattern.compile(\"{} < [foo & bar]\");\n// after\nSemgrexPattern p = SemgrexPattern.compile(\"{} < [foo bar]\");","handlingStrategy":"validation","validationCode":"if (pattern.contains(\"&\")) throw new IllegalArgumentException(\"'&' is illegal in semgrex since 3.6.0; remove it: \" + pattern);","typeGuard":null,"tryCatchPattern":"try {\n  p = SemgrexPattern.compile(pattern);\n} catch (SemgrexParseException e) {\n  if (e.getMessage().startsWith(\"Use of &\")) { p = SemgrexPattern.compile(pattern.replace(\"&\", \" \")); }\n  else throw e;\n}","preventionTips":["Strip '&' from legacy semgrex patterns when upgrading CoreNLP","Grep your pattern stores/configs for '&' before dependency upgrades","Pin CoreNLP docs version to the version you depend on"],"tags":["semgrex","parser","deprecated-syntax"],"backgroundTag":"deprecated-api-usage","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"}