(self, lexicon, flags=0)
| 392 | |
| 393 | class Scanner: |
| 394 | def __init__(self, lexicon, flags=0): |
| 395 | from ._constants import BRANCH, SUBPATTERN |
| 396 | if isinstance(flags, RegexFlag): |
| 397 | flags = flags.value |
| 398 | self.lexicon = lexicon |
| 399 | # combine phrases into a compound pattern |
| 400 | p = [] |
| 401 | s = _parser.State() |
| 402 | s.flags = flags |
| 403 | for phrase, action in lexicon: |
| 404 | sub_pattern = _parser.parse(phrase, flags) |
| 405 | if sub_pattern.state.groups != 1: |
| 406 | raise ValueError("Cannot use capturing groups in re.Scanner") |
| 407 | gid = s.opengroup() |
| 408 | p.append(_parser.SubPattern(s, [ |
| 409 | (SUBPATTERN, (gid, 0, 0, sub_pattern)), |
| 410 | ])) |
| 411 | s.closegroup(gid, p[-1]) |
| 412 | p = _parser.SubPattern(s, [(BRANCH, (None, p))]) |
| 413 | self.scanner = _compiler.compile(p) |
| 414 | def scan(self, string): |
| 415 | result = [] |
| 416 | append = result.append |
nothing calls this directly
no test coverage detected