| 511 | } |
| 512 | |
| 513 | const 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 | |
| 537 | bool llama_grammar_parser::parse(const char * src) { |
| 538 | try { |
nothing calls this directly
no test coverage detected