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

Function parse_rule

common/grammar-parser.cpp:250–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248 }
249
250 static const char * parse_rule(parse_state & state, const char * src) {
251 const char * name_end = parse_name(src);
252 const char * pos = parse_space(name_end, false);
253 size_t name_len = name_end - src;
254 uint32_t rule_id = get_symbol_id(state, src, name_len);
255 const std::string name(src, name_len);
256
257 if (!(pos[0] == ':' && pos[1] == ':' && pos[2] == '=')) {
258 throw std::runtime_error(std::string("expecting ::= at ") + pos);
259 }
260 pos = parse_space(pos + 3, true);
261
262 pos = parse_alternates(state, pos, name, rule_id, false);
263
264 if (*pos == '\r') {
265 pos += pos[1] == '\n' ? 2 : 1;
266 } else if (*pos == '\n') {
267 pos++;
268 } else if (*pos) {
269 throw std::runtime_error(std::string("expecting newline or end at ") + pos);
270 }
271 return parse_space(pos, true);
272 }
273
274 parse_state parse(const char * src) {
275 try {

Callers 2

parseMethod · 0.85
parseFunction · 0.85

Calls 5

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

Tested by

no test coverage detected