Parse a filter expression and return the compiled filter function. If the filter syntax is invalid, `ValueError` is raised.
(s: str)
| 654 | |
| 655 | |
| 656 | def parse(s: str) -> TFilter: |
| 657 | """ |
| 658 | Parse a filter expression and return the compiled filter function. |
| 659 | If the filter syntax is invalid, `ValueError` is raised. |
| 660 | """ |
| 661 | if not s: |
| 662 | raise ValueError("Empty filter expression") |
| 663 | try: |
| 664 | flt = bnf.parseString(s, parseAll=True)[0] |
| 665 | flt.pattern = s |
| 666 | return flt |
| 667 | except (pp.ParseException, ValueError) as e: |
| 668 | raise ValueError(f"Invalid filter expression: {s!r}") from e |
| 669 | |
| 670 | |
| 671 | def match(flt: str | TFilter, flow: flow.Flow) -> bool: |
no outgoing calls
no test coverage detected
searching dependent graphs…