- n=4, no sep: '(a (a (a (a)?)?)?)?' - n=4, sep=',', prefix: '("," a ("," a ("," a ("," a)?)?)?)?' - n=4, sep=',', no prefix: '(a ("," a ("," a ("," a)?)?)?)?'
(up_to_n, prefix_with_sep=False)
| 271 | ) |
| 272 | |
| 273 | def opt_repetitions(up_to_n, prefix_with_sep=False): |
| 274 | """ |
| 275 | - n=4, no sep: '(a (a (a (a)?)?)?)?' |
| 276 | - n=4, sep=',', prefix: '("," a ("," a ("," a ("," a)?)?)?)?' |
| 277 | - n=4, sep=',', no prefix: '(a ("," a ("," a ("," a)?)?)?)?' |
| 278 | """ |
| 279 | |
| 280 | content = ( |
| 281 | f"{separator_rule} {item_rule}" |
| 282 | if prefix_with_sep and separator_rule |
| 283 | else item_rule |
| 284 | ) |
| 285 | if up_to_n == 0: |
| 286 | return "" |
| 287 | elif up_to_n == 1: |
| 288 | return f"({content})?" |
| 289 | elif separator_rule and not prefix_with_sep: |
| 290 | return f"({content} {opt_repetitions(up_to_n - 1, prefix_with_sep=True)})?" |
| 291 | else: |
| 292 | return (f"({content} " * up_to_n).rstrip() + (")?" * up_to_n) |
| 293 | |
| 294 | if min_items > 0 and max_items != min_items: |
| 295 | result += " " |
no outgoing calls
no test coverage detected
searching dependent graphs…