MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / gbnf_excluding_pattern

Function gbnf_excluding_pattern

common/peg-parser.cpp:1510–1537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1508}
1509
1510static std::string gbnf_excluding_pattern(const std::vector<std::string> & strings) {
1511 trie matcher(strings);
1512 auto pieces = matcher.collect_prefix_and_next();
1513
1514 std::string pattern;
1515 for (size_t i = 0; i < pieces.size(); ++i) {
1516 if (i > 0) {
1517 pattern += " | ";
1518 }
1519
1520 const auto & pre = pieces[i].prefix;
1521 const auto & chars = pieces[i].next_chars;
1522
1523 std::string cls;
1524 cls.reserve(chars.size());
1525 for (uint32_t ch : chars) {
1526 cls += gbnf_escape_char_class(ch);
1527 }
1528
1529 if (!pre.empty()) {
1530 pattern += gbnf_format_literal(common_unicode_cpts_to_utf8(pre)) + " [^" + cls + "]";
1531 } else {
1532 pattern += "[^" + cls + "]";
1533 }
1534 }
1535
1536 return "(" + pattern + ")*";
1537}
1538
1539static std::unordered_set<std::string> collect_reachable_rules(
1540 const common_peg_arena & arena,

Callers 1

build_grammarMethod · 0.85

Calls 6

gbnf_escape_char_classFunction · 0.85
gbnf_format_literalFunction · 0.85
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected