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

Function parse_char_classes

subprojects/llama.cpp/common/peg-parser.cpp:207–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207static std::pair<std::vector<common_peg_chars_parser::char_range>, bool> parse_char_classes(const std::string & classes) {
208 std::vector<common_peg_chars_parser::char_range> ranges;
209 bool negated = false;
210
211 std::string content = classes;
212 if (content.front() == '[') {
213 content = content.substr(1);
214 }
215
216 if (content.back() == ']') {
217 content.pop_back();
218 }
219
220 // Check for negation
221 if (!content.empty() && content.front() == '^') {
222 negated = true;
223 content = content.substr(1);
224 }
225
226 size_t i = 0;
227 while (i < content.length()) {
228 auto [start, start_len] = parse_char_class_char(content, i);
229 i += start_len;
230
231 if (i + 1 < content.length() && content[i] == '-') {
232 // Range detected
233 auto [end, end_len] = parse_char_class_char(content, i + 1);
234 ranges.push_back(common_peg_chars_parser::char_range{start, end});
235 i += 1 + end_len;
236 } else {
237 ranges.push_back(common_peg_chars_parser::char_range{start, start});
238 }
239 }
240
241 return {ranges, negated};
242}
243
244void common_peg_ast_arena::visit(common_peg_ast_id id, const common_peg_ast_visitor & visitor) const {
245 if (id == COMMON_PEG_INVALID_AST_ID) {

Callers 1

charsMethod · 0.85

Calls 4

parse_char_class_charFunction · 0.85
emptyMethod · 0.65
lengthMethod · 0.65
push_backMethod · 0.45

Tested by

no test coverage detected