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

Class Tokenizer

Lib/re/_parser.py:230–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228 return self.width
229
230class Tokenizer:
231 def __init__(self, string):
232 self.istext = isinstance(string, str)
233 self.string = string
234 if not self.istext:
235 string = str(string, 'latin1')
236 self.decoded_string = string
237 self.index = 0
238 self.next = None
239 self.__next()
240 def __next(self):
241 index = self.index
242 try:
243 char = self.decoded_string[index]
244 except IndexError:
245 self.next = None
246 return
247 if char == "\\":
248 index += 1
249 try:
250 char += self.decoded_string[index]
251 except IndexError:
252 raise error("bad escape (end of pattern)",
253 self.string, len(self.string) - 1) from None
254 self.index = index + 1
255 self.next = char
256 def match(self, char):
257 if char == self.next:
258 self.__next()
259 return True
260 return False
261 def get(self):
262 this = self.next
263 self.__next()
264 return this
265 def getwhile(self, n, charset):
266 result = ''
267 for _ in range(n):
268 c = self.next
269 if c not in charset:
270 break
271 result += c
272 self.__next()
273 return result
274 def getuntil(self, terminator, name):
275 result = ''
276 while True:
277 c = self.next
278 self.__next()
279 if c is None:
280 if not result:
281 raise self.error("missing " + name)
282 raise self.error("missing %s, unterminated name" % terminator,
283 len(result))
284 if c == terminator:
285 if not result:
286 raise self.error("missing " + name, 1)
287 break

Callers 2

parseFunction · 0.70
parse_templateFunction · 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…