| 638 | } |
| 639 | |
| 640 | const 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 | |
| 664 | bool llama_grammar_parser::parse(const char * src) { |
| 665 | try { |
nothing calls this directly
no test coverage detected