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

Function tokenize_asdl

Parser/asdl.py:245–265  ·  view source on GitHub ↗

Tokenize the given buffer. Yield Token objects.

(buf)

Source from the content-addressed store, hash-verified

243 return 'Syntax error on line {0.lineno}: {0.msg}'.format(self)
244
245def tokenize_asdl(buf):
246 """Tokenize the given buffer. Yield Token objects."""
247 for lineno, line in enumerate(buf.splitlines(), 1):
248 for m in re.finditer(r'\s*(\w+|--.*|.)', line.strip()):
249 c = m.group(1)
250 if c[0].isalpha():
251 # Some kind of identifier
252 if c[0].isupper():
253 yield Token(TokenKind.ConstructorId, c, lineno)
254 else:
255 yield Token(TokenKind.TypeId, c, lineno)
256 elif c[:2] == '--':
257 # Comment
258 break
259 else:
260 # Operators
261 try:
262 op_kind = TokenKind.operator_table[c]
263 except KeyError:
264 raise ASDLSyntaxError('Invalid operator %s' % c, lineno)
265 yield Token(op_kind, c, lineno)
266
267class ASDLParser:
268 """Parser for ASDL files.

Callers 1

parseMethod · 0.85

Calls 8

enumerateFunction · 0.85
ASDLSyntaxErrorClass · 0.85
isalphaMethod · 0.80
isupperMethod · 0.80
TokenClass · 0.50
splitlinesMethod · 0.45
stripMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…