|
1 | 1 | from .flags import PatternFlag |
2 | 2 | from .match import Match |
3 | | -from regex_automata.automata.nfa_evaluator import NFAEvaluator |
| 3 | +from regex_automata.regex.nfa_evaluator import NFAEvaluator |
4 | 4 | from ..errors import ParserError, PatternError, TokenizerError |
5 | 5 | from ..parser.ast_processor import ASTProcessor |
6 | 6 | from ..parser.ast_visualizer import ASTVisualizer |
@@ -52,15 +52,22 @@ def render_ast(self, output_path: str = "ast.png", raw: bool = False) -> None: |
52 | 52 | ast = self.ast if not raw else self.raw_ast |
53 | 53 | ASTVisualizer(ast).render(output_path) |
54 | 54 |
|
55 | | - def fullmatch(self, s: str) -> Match | None: |
56 | | - evaluator = NFAEvaluator(self.nfa, self.flags) |
57 | | - if evaluator.accepts(s): |
58 | | - return Match() |
59 | | - else: |
60 | | - return None |
| 55 | + def fullmatch(self, text: str, start: int = 0, end: int | None = None) -> Match | None: |
| 56 | + end_ = end if end is not None else len(text) |
| 57 | + m = self.match(text, start, end) |
| 58 | + if m is not None and m.span[-1] != end_: |
| 59 | + m = None |
| 60 | + return m |
61 | 61 |
|
62 | | - def match(self, s: str) -> Match | None: |
63 | | - raise NotImplementedError # TODO |
| 62 | + def match(self, text: str, start: int = 0, end: int | None = None) -> Match | None: |
| 63 | + evaluator = NFAEvaluator(self.nfa, self.flags) |
| 64 | + return evaluator.match(text, start, end) |
64 | 65 |
|
65 | | - def search(self, s: str) -> Match | None: |
66 | | - raise NotImplementedError # TODO |
| 66 | + def search(self, text: str, start: int = 0, end: int | None = None) -> Match | None: |
| 67 | + # TODO implement this properly via automaton |
| 68 | + end_ = end if end is not None else len(text) |
| 69 | + for i in range(start, end_): |
| 70 | + m = self.match(text, i, end) |
| 71 | + if m is not None: |
| 72 | + return m |
| 73 | + return None |
0 commit comments