{"record":{"id":"18f7c4580c4f7000","repo":"stanfordnlp/CoreNLP","slug":"warning-n-fullexpression-starttoken-n","errorCode":null,"errorMessage":"${warning}\\n    ${fullExpression(startToken)}\\n    Current stack: ${trace}","messagePattern":"(.+?)\\\\n    (.+?)\\\\n    Current stack: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj","lineNumber":52,"sourceCode":"  private String fullExpression(Token startToken) {\n    StringBuilder result = new StringBuilder();\n    for (Token p = startToken; p != null; p = p.next) {\n      if (p.specialToken != null) {\n        result.append(p.specialToken.image);\n      }\n      result.append(p.image);\n    }\n    return result.toString();\n  }\n\n  private void warnDeprecated(String warning, Token startToken) {\n    StringWriter sw = new StringWriter();\n    PrintWriter pw = new PrintWriter(sw);\n    (new RuntimeException()).printStackTrace(pw);\n    String trace = sw.toString();\n    trace = trace.substring(trace.lastIndexOf(\"SemgrexParser\"));\n    trace = trace.substring(trace.indexOf(\"at \"));\n    log.warn(warning + \"\\n    \" + fullExpression(startToken) + \"\\n    Current stack: \" + trace);\n  }\n}\n\nPARSER_END(SemgrexParser)\n\nSPECIAL_TOKEN:\n{\n\t< WHITESPACE: (\" \" | \"\\r\" | \"\\t\")+ >\n}\n\nTOKEN:\n{\n        < UNIQ: \"uniq\" >\n}\n\nTOKEN:\n{\n\t< RELATION: \"<\" | \">\" | \">>\" | \"<<\" | \"<>\" | \"==\" | \"$+\" | \"$-\" | \"$++\" | \"$--\" | \".\" | \"..\" | \"-\" | \"--\" | \">++\" | \">--\" | \"<++\" | \"<--\" >","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj#L34-L70","documentation":"SemgrexParser.jj (JavaCC-generated parser) has a helper that logs a warning containing the offending semgrex expression (fullExpression(startToken)) and the current parser stack trace. When semantic warnings occur during pattern parsing, this builds \"<warning>\\n <expr>\\n Current stack: <trace>\" and logs it — the pattern may still parse or may be subtly wrong.","triggerScenarios":"Parsing a semgrex pattern string via SemgrexPattern.compile that triggers a parser warning hook — e.g., deprecated or suspicious syntax the grammar recognizes but flags.","commonSituations":"Migrating old semgrex syntax to a newer parser version; typos in relation patterns like {} node specs; copy-pasted patterns from older papers/code.","solutions":["Read the logged warning text and the echoed expression to see which part of the pattern is flagged","Update the pattern to current semgrex syntax (check SemgrexPattern documentation for the relation you used)","Test the pattern with a small SemanticGraph to confirm intended matches after fixing","Keep patterns under version control and re-validate them when upgrading the Stanford CoreNLP version"],"exampleFix":"// before\nSemgrexPattern p = SemgrexPattern.compile(\"{} >nsubj {}<<deprecated-syntax\");\n// after\nSemgrexPattern p = SemgrexPattern.compile(\"{}=src >nsubj {}\"); // current syntax","handlingStrategy":"validation","validationCode":"// Java: pre-check pattern for balanced delimiters before compiling\nstatic boolean balanced(String p) {\n  int d = 0;\n  for (char c : p.toCharArray()) {\n    if (c == '[' || c == '{' || c == '(') d++;\n    if (c == ']' || c == '}' || c == ')') d--;\n    if (d < 0) return false;\n  }\n  return d == 0;\n}","typeGuard":null,"tryCatchPattern":"// Compile may still warn; catch parse failures to fail fast\ntry {\n  SemgrexPattern p = SemgrexPattern.compile(expr);\n} catch (RuntimeException e) {\n  throw new IllegalArgumentException(\"Bad semgrex: \" + expr, e);\n}","preventionTips":["Keep semgrex patterns in reviewed version-controlled files","Re-validate all stored patterns after upgrading CoreNLP versions","Read the logged expression + stack to pinpoint the offending fragment","Test patterns against a small sample SemanticGraph"],"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"}