MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / parse_rule

Method parse_rule

smallthinker/src/llama-grammar.cpp:513–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511}
512
513const char * llama_grammar_parser::parse_rule(const char * src) {
514 const char * name_end = parse_name(src);
515 const char * pos = parse_space(name_end, false);
516 size_t name_len = name_end - src;
517 uint32_t rule_id = get_symbol_id(src, name_len);
518 const std::string name(src, name_len);
519
520 if (!(pos[0] == ':' && pos[1] == ':' && pos[2] == '=')) {
521 throw std::runtime_error(std::string("expecting ::= at ") + pos);
522 }
523 pos = parse_space(pos + 3, true);
524
525 pos = parse_alternates(pos, name, rule_id, false);
526
527 if (*pos == '\r') {
528 pos += pos[1] == '\n' ? 2 : 1;
529 } else if (*pos == '\n') {
530 pos++;
531 } else if (*pos) {
532 throw std::runtime_error(std::string("expecting newline or end at ") + pos);
533 }
534 return parse_space(pos, true);
535}
536
537bool llama_grammar_parser::parse(const char * src) {
538 try {

Callers

nothing calls this directly

Calls 5

get_symbol_idFunction · 0.85
parse_alternatesFunction · 0.85
parse_nameFunction · 0.70
parse_spaceFunction · 0.70
stringClass · 0.50

Tested by

no test coverage detected