Skip to content

Commit dfffe67

Browse files
committed
llama : add support for ACCENT_MARK (\\p{M}) and SYMBOL (\\p{S}) unicode categories in pre-tokenization regex
1 parent 5b4673b commit dfffe67

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/unicode.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,24 @@ std::vector<std::string> unicode_regex_split(const std::string & text, const std
667667
{ "\\p{N}", unicode_cpt_flags::NUMBER },
668668
{ "\\p{L}", unicode_cpt_flags::LETTER },
669669
{ "\\p{P}", unicode_cpt_flags::PUNCTUATION },
670+
{ "\\p{M}", unicode_cpt_flags::ACCENT_MARK },
671+
{ "\\p{S}", unicode_cpt_flags::SYMBOL },
670672
};
671673

672674
static const std::map<int, int> k_ucat_cpt = {
673675
{ unicode_cpt_flags::NUMBER, 0xD1 },
674676
{ unicode_cpt_flags::LETTER, 0xD2 },
675677
{ unicode_cpt_flags::PUNCTUATION, 0xD3 },
678+
{ unicode_cpt_flags::ACCENT_MARK, 0xD4 },
679+
{ unicode_cpt_flags::SYMBOL, 0xD5 },
676680
};
677681

678682
static const std::map<int, std::string> k_ucat_map = {
679683
{ unicode_cpt_flags::NUMBER, "\x30-\x39" }, // 0-9
680684
{ unicode_cpt_flags::LETTER, "\x41-\x5A\x61-\x7A" }, // A-Za-z
681685
{ unicode_cpt_flags::PUNCTUATION, "\x21-\x23\x25-\x2A\x2C-\x2F\x3A-\x3B\x3F-\x40\\\x5B-\\\x5D\x5F\\\x7B\\\x7D" }, // !-#%-*,-/:-;?-@\[-\]_\{\}
686+
{ unicode_cpt_flags::ACCENT_MARK, "" }, // no sub-128 codepoints
687+
{ unicode_cpt_flags::SYMBOL, "\\\x24\\\x2B\x3C-\x3E\x5E\x60\\\x7C" }, // $+<=>^`|
682688
};
683689

684690
// compute collapsed codepoints only if needed by at least one regex

0 commit comments

Comments
 (0)