MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/re/__init__.py:394–413  ·  view source on GitHub ↗
(self, lexicon, flags=0)

Source from the content-addressed store, hash-verified

392
393class 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

Callers

nothing calls this directly

Calls 5

opengroupMethod · 0.95
appendMethod · 0.95
closegroupMethod · 0.95
parseMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected