{"record":{"id":"39c9cb5840690e43","repo":"stanfordnlp/CoreNLP","slug":"no-named-tregex-nodes-allowed-in-the-scope-of-nega","errorCode":null,"errorMessage":"No named tregex nodes allowed in the scope of negation.","messagePattern":"No named tregex nodes allowed in the scope of negation\\.","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/tregex/TregexParser.java","lineNumber":258,"sourceCode":"          break label_2;\n        }\n        jj_consume_token(19);\n        groupNum = jj_consume_token(NUMBER);\n        jj_consume_token(20);\n        groupVar = jj_consume_token(IDENTIFIER);\nvarGroups.add(new Pair<Integer,String>(Integer.parseInt(groupNum.image),groupVar.image));\n      }\n      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {\n      case 21:{\n        jj_consume_token(21);\n        name = jj_consume_token(IDENTIFIER);\nif (knownVariables.contains(name.image)) {\n            {if (true) throw new ParseException(\"Variable \" + name.image + \" has been declared twice, which makes no sense\");}\n          } else {\n            knownVariables.add(name.image);\n          }\n          if (underNegation)\n            {if (true) throw new ParseException(\"No named tregex nodes allowed in the scope of negation.\");}\n        break;\n        }\n      default:\n        jj_la1[8] = jj_gen;\n        ;\n      }\n      break;\n      }\n    case 22:{\n      jj_consume_token(22);\n      linkedName = jj_consume_token(IDENTIFIER);\n      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {\n      case 21:{\n        jj_consume_token(21);\n        name = jj_consume_token(IDENTIFIER);\n        break;\n        }\n      default:","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/TregexParser.java#L240-L276","documentation":"Tregex forbids declaring a named node (a variable binding) inside the scope of a negation, because a binding created in a negated subexpression can never be reliably bound (the subexpression is required to fail). The parser throws ParseException when it sees =name while underNegation is true.","triggerScenarios":"Compiling a pattern like \"!A=${name}\" or any named node appearing within !(...) negation scope.","commonSituations":"Users trying to capture what did NOT match; converting positive queries to negated ones without removing capture names; misunderstanding that negated nodes cannot produce bindings.","solutions":["Remove the =name binding from inside the negation","Restructure the query: negate a subpattern that references an externally named node instead","Match positively, then filter results in Java code after matching"],"exampleFix":"// before\nString pattern = \"NP < !(NNS=${name})\";\n// after\nString pattern = \"NP < !NNS\"; // filter/extract in code instead","handlingStrategy":"validation","validationCode":"// reject named nodes inside negation before compiling\nif (pattern.matches(\".*!.*=\\\\w+.*\")) throw new IllegalArgumentException(\"named node inside negation: \" + pattern);","typeGuard":null,"tryCatchPattern":"try { TregexPattern.compile(pattern); } catch (ParseException e) { /* named node under negation; rewrite query */ }","preventionTips":["Never use =name on nodes inside ! or negation scope","Capture positively and filter results in code instead","Learn tregex negation scoping rules before adding bindings"],"tags":["tregex","parse-error","negation"],"backgroundTag":"invalid-argument-value","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"}