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

Class State

Lib/re/_parser.py:75–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73MAXWIDTH = 1 << 64
74
75class State:
76 # keeps track of state for parsing
77 def __init__(self):
78 self.flags = 0
79 self.groupdict = {}
80 self.groupwidths = [None] # group 0
81 self.lookbehindgroups = None
82 self.grouprefpos = {}
83 @property
84 def groups(self):
85 return len(self.groupwidths)
86 def opengroup(self, name=None):
87 gid = self.groups
88 self.groupwidths.append(None)
89 if self.groups > MAXGROUPS:
90 raise error("too many groups")
91 if name is not None:
92 ogid = self.groupdict.get(name, None)
93 if ogid is not None:
94 raise error("redefinition of group name %r as group %d; "
95 "was group %d" % (name, gid, ogid))
96 self.groupdict[name] = gid
97 return gid
98 def closegroup(self, gid, p):
99 self.groupwidths[gid] = p.getwidth()
100 def checkgroup(self, gid):
101 return gid < self.groups and self.groupwidths[gid] is not None
102
103 def checklookbehindgroup(self, gid, source):
104 if self.lookbehindgroups is not None:
105 if not self.checkgroup(gid):
106 raise source.error('cannot refer to an open group')
107 if gid >= self.lookbehindgroups:
108 raise source.error('cannot refer to group defined in the same '
109 'lookbehind subpattern')
110
111class SubPattern:
112 # a subpattern, in intermediate form

Callers 1

parseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…