/
githubmirror
/
cpython
Обзор
Документация
Войти
/
githubmirror
/
cpython
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
3.9
Parser/pgen/token.py
38 строк
907 B
Pablo Galindo
Refactor Parser/pgen and add documentation and explanations (GH-15373)
22 авг 2019, 04:38
Не верифицирован
22 авг 2019, 04:38
71876fa
Код
Авторство
О чём код?
import itertools def generate_tokens(tokens): numbers = itertools.count(0) for line in tokens: line = line.strip() if not line or line.startswith("#"): continue name = line.split()[0] yield (name, next(numbers)) yield ("N_TOKENS", next(numbers)) yield ("NT_OFFSET", 256) def generate_opmap(tokens): for line in tokens: line = line.strip() if not line or line.startswith("#"): continue pieces = line.split() if len(pieces) != 2: continue name, op = pieces yield (op.strip("'"), name) # Yield independently <>. This is needed so it does not collide # with the token generation in "generate_tokens" because if this # symbol is included in Grammar/Tokens, it will collide with != # as it has the same name (NOTEQUAL). yield ("<>", "NOTEQUAL")