(
cls,
*,
field_name: str,
field_regex: str,
content_regex: Optional[str],
)
| 4685 | |
| 4686 | @classmethod |
| 4687 | def _regex_leading_capture( |
| 4688 | cls, |
| 4689 | *, |
| 4690 | field_name: str, |
| 4691 | field_regex: str, |
| 4692 | content_regex: Optional[str], |
| 4693 | ) -> Optional[Dict[str, Any]]: |
| 4694 | capture_parts = cls._regex_capture_parts(field_regex) |
| 4695 | if capture_parts is None: |
| 4696 | return None |
| 4697 | prefix_pattern, _ = capture_parts |
| 4698 | prefix_pattern = prefix_pattern.lstrip("^") |
| 4699 | optional_prefix = cls._consume_optional_literal_prefix(prefix_pattern) |
| 4700 | if optional_prefix is not None: |
| 4701 | prefix_pattern = optional_prefix[1] |
| 4702 | implicit_at_start = False |
| 4703 | optional_capture_start = cls._consume_optional_literal_prefix(prefix_pattern) |
| 4704 | if optional_capture_start is not None: |
| 4705 | capture_start, prefix_pattern = optional_capture_start |
| 4706 | implicit_at_start = True |
| 4707 | else: |
| 4708 | capture_start, prefix_pattern = cls._regex_literal_prefix_and_remainder(prefix_pattern) |
| 4709 | if not capture_start or prefix_pattern: |
| 4710 | return None |
| 4711 | end_literals = cls._regex_capture_end_literals(field_regex) |
| 4712 | if not end_literals: |
| 4713 | return None |
| 4714 | capture_end = end_literals[0] |
| 4715 | strip_after = False |
| 4716 | if isinstance(content_regex, str): |
| 4717 | escaped_end = re.escape(capture_end) |
| 4718 | strip_after = bool(re.search(escaped_end + r"\\s\*", content_regex)) |
| 4719 | return { |
| 4720 | "field": field_name, |
| 4721 | "start": capture_start, |
| 4722 | "end": capture_end, |
| 4723 | "strip_after": strip_after, |
| 4724 | "implicit_at_start": implicit_at_start, |
| 4725 | } |
| 4726 | |
| 4727 | @staticmethod |
| 4728 | def _literal_suffix_prefix_length(text: str, literal: str) -> int: |
no test coverage detected