Skip to content

Commit bfcf545

Browse files
committed
Resolves ggml-org#3878 by enforcing existence of root node before returning valid grammar structure.
1 parent 5cdb371 commit bfcf545

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/grammar-parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ namespace grammar_parser {
294294
}
295295
}
296296
}
297+
// Ensure that the "root" node is defined
298+
if (state.symbol_ids.find("root") == state.symbol_ids.end()) {
299+
throw std::runtime_error("Undefined rule identifier 'root'");
300+
}
297301
return state;
298302
} catch (const std::exception & err) {
299303
fprintf(stderr, "%s: error parsing grammar: %s\n", __func__, err.what());

0 commit comments

Comments
 (0)