| 113 | 113 | |
| 114 | 114 | def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]: |
| 115 | 115 | """Transforms a comma separated list of regular expressions.""" |
| 116 | # Smart parser that respects regex syntax to distinguish between | |
| 117 | # commas that are part of regex patterns vs. separators between patterns | |
| 116 | 118 | patterns: list[Pattern[str]] = [] |
| 117 | for pattern in _csv_transformer(value): | |
| 118 | patterns.append(_regex_transformer(pattern)) | |
| 119 | ||
| 120 | if not value.strip(): | |
| 121 | return patterns | |
| 122 | ||
| 123 | # Parse the string character by character, respecting regex grouping | |
| 124 | current_pattern = [] | |
| 125 | brace_depth = 0 # For { } quantifiers | |
| 126 | paren_depth = 0 # For ( ) groups | |
| 127 | bracket_depth = 0 # For [ ] character classes | |
| 128 | i = 0 | |
| 129 | ||
| 130 | while i < len(value): | |
| 131 | char = value[i] | |
| 132 | ||
| 133 | if char == "\\": | |
| 134 | # Handle escape sequences - include both backslash and next char | |
| 135 | current_pattern.append(char) | |
| 136 | if i + 1 < len(value): | |
| 137 | current_pattern.append(value[i + 1]) | |
| 138 | i += 1 | |
| 139 | elif char == "{": | |
| 140 | brace_depth += 1 | |
| 141 | current_pattern.append(char) | |
| 142 | elif char == "}": | |
| 143 | brace_depth = max(0, brace_depth - 1) | |
| 144 | current_pattern.append(char) | |
| 145 | elif char == "(": | |
| 146 | paren_depth += 1 | |
| 147 | current_pattern.append(char) | |
| 148 | elif char == ")": | |
| 149 | paren_depth = max(0, paren_depth - 1) | |
| 150 | current_pattern.append(char) | |
| 151 | elif char == "[": | |
| 152 | bracket_depth += 1 | |
| 153 | current_pattern.append(char) | |
| 154 | elif char == "]": | |
| 155 | bracket_depth = max(0, bracket_depth - 1) | |
| 156 | current_pattern.append(char) | |
| 157 | elif char == "," and brace_depth == 0 and paren_depth == 0 and bracket_depth == 0: | |
| 158 | # Comma at top level - this is a pattern separator | |
| 159 | pattern_str = "".join(current_pattern).strip() | |
| 160 | if pattern_str: | |
| 161 | patterns.append(_regex_transformer(pattern_str)) | |
| 162 | current_pattern = [] | |
| 163 | else: | |
| 164 | current_pattern.append(char) | |
| 165 | ||
| 166 | i += 1 | |
| 167 | ||
| 168 | # Add the last pattern | |
| 169 | pattern_str = "".join(current_pattern).strip() | |
| 170 | if pattern_str: | |
| 171 | patterns.append(_regex_transformer(pattern_str)) | |
| 172 | ||
| 119 | 173 | return patterns |
| 120 | 174 | |
| 121 | 175 |
| Test Name | Status |
|---|---|
tests/config/test_config.py::test_csv_regex_error | Fail |
tests/config/test_config.py::test_can_read_toml_env_variable | Pass |
tests/config/test_config.py::test_unknown_message_id | Pass |
tests/config/test_config.py::test_unknown_option_name | Pass |
tests/config/test_config.py::test_unknown_short_option_name | Pass |
tests/config/test_config.py::test_unknown_confidence | Pass |
tests/config/test_config.py::test_empty_confidence | Pass |
tests/config/test_config.py::test_unknown_yes_no | Pass |
tests/config/test_config.py::test_unknown_py_version | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1] | Pass |
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo, | Pass |
tests/config/test_config.py::test_regex_error | Pass |
tests/config/test_config.py::test_short_verbose | Pass |
tests/config/test_config.py::test_argument_separator | Pass |
tests/config/test_config.py::test_clear_cache_post_run | Pass |
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive | Pass |
tests/config/test_config.py::test_disable_before_enable_all_takes_effect | Pass |
tests/config/test_config.py::test_enable_before_disable_all_takes_effect | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.