Skip to content

Commit 92ee631

Browse files
committed
Adding missing symbol validation to grammar parser.
1 parent c2101a2 commit 92ee631

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

common/grammar-parser.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,20 @@ namespace grammar_parser {
416416
std::vector<const llama_grammar_element *> parse_state::c_rules() {
417417
std::vector<const llama_grammar_element *> ret;
418418
ret.reserve(rules.size());
419+
unsigned int cnt = 0;
419420
for (const auto & rule : rules) {
420-
ret.push_back(rule.data());
421+
// Ensure it's not empty
422+
if (rule.data() != nullptr) {
423+
ret.push_back(rule.data());
424+
} else {
425+
// Find the symbol ID for this rule ID
426+
for (const auto & kv : symbol_ids) {
427+
if (kv.second == cnt) {
428+
throw std::runtime_error("Undefined rule identifier '" + kv.first + "'");
429+
}
430+
}
431+
}
432+
cnt++;
421433
}
422434
return ret;
423435
}

0 commit comments

Comments
 (0)