MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / parse_rule

Method parse_rule

subprojects/llama.cpp/src/llama-grammar.cpp:640–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640const char * llama_grammar_parser::parse_rule(const char * src) {
641 const char * name_end = parse_name(src);
642 const char * pos = parse_space(name_end, false);
643 size_t name_len = name_end - src;
644 uint32_t rule_id = get_symbol_id(src, name_len);
645 const std::string name(src, name_len);
646
647 if (!(pos[0] == ':' && pos[1] == ':' && pos[2] == '=')) {
648 throw std::runtime_error(std::string("expecting ::= at ") + pos);
649 }
650 pos = parse_space(pos + 3, true);
651
652 pos = parse_alternates(pos, name, rule_id, false);
653
654 if (*pos == '\r') {
655 pos += pos[1] == '\n' ? 2 : 1;
656 } else if (*pos == '\n') {
657 pos++;
658 } else if (*pos) {
659 throw std::runtime_error(std::string("expecting newline or end at ") + pos);
660 }
661 return parse_space(pos, true);
662}
663
664bool llama_grammar_parser::parse(const char * src) {
665 try {

Callers

nothing calls this directly

Calls 3

parse_nameFunction · 0.85
parse_spaceFunction · 0.85
stringClass · 0.85

Tested by

no test coverage detected