MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / _compile_capture_pattern

Method _compile_capture_pattern

examples/server/server.py:4817–4850  ·  view source on GitHub ↗
(
        cls,
        pattern: str,
    )

Source from the content-addressed store, hash-verified

4815
4816 @classmethod
4817 def _compile_capture_pattern(
4818 cls,
4819 pattern: str,
4820 ) -> Optional[Dict[str, Any]]:
4821 normalized = pattern.lstrip("^")
4822 if "(.*?)" in normalized:
4823 prefix_pattern, suffix_pattern = normalized.split("(.*?)", 1)
4824 start = cls._regex_literal_prefix(prefix_pattern)
4825 if not start:
4826 return None
4827 if suffix_pattern == "":
4828 return {"start": start, "end": "", "allow_eof": True}
4829 eof_variant = suffix_pattern.endswith("|$)") and suffix_pattern.startswith("(?:")
4830 if eof_variant:
4831 suffix_pattern = suffix_pattern[3:-3]
4832 end = cls._regex_literal_prefix(suffix_pattern)
4833 if not end:
4834 return None
4835 return {"start": start, "end": end, "allow_eof": eof_variant}
4836 if "(.*)" in normalized:
4837 prefix_pattern, suffix_pattern = normalized.split("(.*)", 1)
4838 start = cls._regex_literal_prefix(prefix_pattern)
4839 if not start:
4840 return None
4841 if suffix_pattern == "":
4842 return {"start": start, "end": "", "allow_eof": True}
4843 eof_variant = suffix_pattern.endswith("|$)") and suffix_pattern.startswith("(?:")
4844 if eof_variant:
4845 suffix_pattern = suffix_pattern[3:-3]
4846 end = cls._regex_literal_prefix(suffix_pattern)
4847 if not end:
4848 return None
4849 return {"start": start, "end": end, "allow_eof": eof_variant}
4850 return None
4851
4852 @classmethod
4853 def _compile_word_capture_pattern(

Calls 1

_regex_literal_prefixMethod · 0.80

Tested by

no test coverage detected