{"record":{"id":"e6fc7b8f32e3bf48","repo":"stanfordnlp/CoreNLP","slug":"grammar-format-error-expected-bar-in-state-name","errorCode":null,"errorMessage":"Grammar format error. Expected bar in state name: ","messagePattern":"Grammar format error\\. Expected bar in state name: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/GrammarCompactor.java","lineNumber":211,"sourceCode":"  }\n\n  protected static TransducerGraph getGraphFromMap(Map<String, TransducerGraph> m, String o) {\n    TransducerGraph graph = m.get(o);\n    if (graph == null) {\n      graph = new TransducerGraph();\n      graph.setEndNode(o);\n      m.put(o, graph);\n    }\n    return graph;\n  }\n\n  protected static String getTopCategoryOfSyntheticState(String s) {\n    if (s.charAt(0) != '@') {\n      return null;\n    }\n    int bar = s.indexOf('|');\n    if (bar < 0) {\n      throw new RuntimeException(\"Grammar format error. Expected bar in state name: \" + s);\n    }\n    String topcat = s.substring(1, bar);\n    return topcat;\n  }\n\n  protected boolean addOneUnaryRule(UnaryRule rule, Map<String, TransducerGraph> graphs) {\n    String parentString = stateIndex.get(rule.parent);\n    String childString = stateIndex.get(rule.child);\n    if (isSyntheticState(parentString)) {\n      String topcat = getTopCategoryOfSyntheticState(parentString);\n      TransducerGraph graph = getGraphFromMap(graphs, topcat);\n      Double output = Double.valueOf(smartNegate(rule.score()));\n      graph.addArc(graph.getStartNode(), parentString, childString, output);\n      return true;\n    } else if (isSyntheticState(childString)) {\n      // need to add Arc from synthetic state to endState\n      TransducerGraph graph = getGraphFromMap(graphs, parentString);\n      Double output = Double.valueOf(smartNegate(rule.score()));","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/GrammarCompactor.java#L193-L229","documentation":"getTopCategoryOfSyntheticState parses synthetic (machine-generated) grammar state names, which must have the form '@<topcat>|<rest>'. If the string starts with '@' but contains no '|' separator, the state name is malformed and this RuntimeException identifies the offending name.","triggerScenarios":"Deserializing or compacting a grammar whose split-state names (from splitTraining or a serialized grammar file) lack the expected '|', e.g. when reading a grammar produced by a different/older format.","commonSituations":"Loading a text- or serialized-format grammar written by another version of the parser, or hand-edited grammar files, into GrammarCompactor's transducer-graph conversion.","solutions":["Regenerate or re-save the grammar with the same parser version that created it.","Inspect the offending state name and fix the missing '|' separator if the grammar file was hand-edited.","Skip compaction (compactGrammar = 0) when processing grammars from incompatible sources."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (state.startsWith(\"@\") && !state.contains(\"|\"))\n    throw new IllegalArgumentException(\"Malformed synthetic state: \" + state);","typeGuard":null,"tryCatchPattern":"try { compact(grammar); } catch (RuntimeException e) { log.error(\"Grammar format mismatch: \" + e.getMessage()); }","preventionTips":["Only compact grammars saved by the same parser version","Never hand-edit synthetic state names in grammar files"],"tags":["grammar-format","state-name","parser","malformed-input"],"backgroundTag":"invalid-argument-format","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"}