Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0b9c9c7
bpo-30455: Generate tokens related C code and docs from token.py.
serhiy-storchaka May 30, 2017
de94fde
Merge branch 'master' into regen-token
serhiy-storchaka Jun 1, 2017
3f78955
Generate regexpes from EXACT_TOKEN_TYPES.
serhiy-storchaka Jun 1, 2017
7a0a67a
Merge branch 'master' into regen-token
serhiy-storchaka Jul 3, 2017
3c10bf6
Fix generating the documentation.
serhiy-storchaka Jul 3, 2017
f116722
Add shebangs and executable bits.
serhiy-storchaka Jul 3, 2017
812fc1f
Add generated file Parser/token_names.h.
serhiy-storchaka Jul 3, 2017
8258f49
Misc other fixes and enhancements.
serhiy-storchaka Jul 3, 2017
b44aa6f
Merge branch 'master' into regen-token
serhiy-storchaka Apr 14, 2018
e26b9c8
Move symbol.py generating code into a separate file.
serhiy-storchaka Apr 14, 2018
33e3724
Fix dependencies for pgen.
serhiy-storchaka Apr 14, 2018
c9966b2
Add a hack for '<>'.
serhiy-storchaka Apr 14, 2018
72bd747
Make _PyParser_TokenNames a const array.
serhiy-storchaka Apr 14, 2018
85f37db
Fix tests.
serhiy-storchaka Apr 14, 2018
27ae82c
Merge branch 'master' into regen-token
serhiy-storchaka Oct 7, 2018
7a38bf0
Remove ASYNC and AWAIT.
serhiy-storchaka Oct 7, 2018
c917a42
Merge branch 'master' into regen-token
serhiy-storchaka Nov 6, 2018
bf167aa
Merge branch 'master' into regen-token
serhiy-storchaka Nov 18, 2018
d5f6f0b
Use a single generating script.
serhiy-storchaka Nov 18, 2018
5b71cf4
Generate descriptions for punctuation and operators.
serhiy-storchaka Nov 18, 2018
7746abe
Add generated files to .gitattributes.
serhiy-storchaka Nov 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ Include/opcode.h linguist-generated=true
Python/opcode_targets.h linguist-generated=true
Objects/typeslots.inc linguist-generated=true
Modules/unicodedata_db.h linguist-generated=true
Doc/library/token-list.inc linguist-generated=true
Include/token.h linguist-generated=true
Parser/token.c linguist-generated=true
206 changes: 206 additions & 0 deletions Doc/library/token-list.inc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 1 addition & 58 deletions Doc/library/token.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,64 +44,7 @@ functions. The functions mirror definitions in the Python C header files.

The token constants are:

.. data:: ENDMARKER
NAME
NUMBER
STRING
NEWLINE
INDENT
DEDENT
LPAR
RPAR
LSQB
RSQB
COLON
COMMA
SEMI
PLUS
MINUS
STAR
SLASH
VBAR
AMPER
LESS
GREATER
EQUAL
DOT
PERCENT
LBRACE
RBRACE
EQEQUAL
NOTEQUAL
LESSEQUAL
GREATEREQUAL
TILDE
CIRCUMFLEX
LEFTSHIFT
RIGHTSHIFT
DOUBLESTAR
PLUSEQUAL
MINEQUAL
STAREQUAL
SLASHEQUAL
PERCENTEQUAL
AMPEREQUAL
VBAREQUAL
CIRCUMFLEXEQUAL
LEFTSHIFTEQUAL
RIGHTSHIFTEQUAL
DOUBLESTAREQUAL
DOUBLESLASH
DOUBLESLASHEQUAL
AT
ATEQUAL
RARROW
ELLIPSIS
OP
ERRORTOKEN
N_TOKENS
NT_OFFSET

.. include:: token-list.inc

The following token type values aren't used by the C tokenizer but are needed for
the :mod:`tokenize` module.
Expand Down
11 changes: 3 additions & 8 deletions Include/token.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions Lib/symbol.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#! /usr/bin/env python3

"""Non-terminal symbols of Python grammar (from "graminit.h")."""

# This file is automatically generated; please don't muck it up!
#
# To update the symbols in this file, 'cd' to the top directory of
# the python source tree after building the interpreter and run:
#
# ./python Lib/symbol.py

#--start constants--
single_input = 256
Expand Down Expand Up @@ -103,14 +96,4 @@
for _name, _value in list(globals().items()):
if type(_value) is type(0):
sym_name[_value] = _name


def _main():
import sys
import token
if len(sys.argv) == 1:
sys.argv = sys.argv + ["Include/graminit.h", "Lib/symbol.py"]
token._main()

if __name__ == "__main__":
_main()
del _name, _value
5 changes: 4 additions & 1 deletion Lib/test/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@


SYMBOL_FILE = support.findfile('symbol.py')
GEN_SYMBOL_FILE = os.path.join(os.path.dirname(__file__),
'..', '..', 'Tools', 'scripts',
'generate_symbol_py.py')
GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
'..', '..', 'Include', 'graminit.h')
TEST_PY_FILE = 'symbol_test.py'
Expand All @@ -22,7 +25,7 @@ def _copy_file_without_generated_symbols(self, source_file, dest_file):

def _generate_symbols(self, grammar_file, target_symbol_py_file):
proc = subprocess.Popen([sys.executable,
SYMBOL_FILE,
GEN_SYMBOL_FILE,
grammar_file,
target_symbol_py_file], stderr=subprocess.PIPE)
stderr = proc.communicate()[1]
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,8 @@ def test_random_files(self):
testfiles = random.sample(testfiles, 10)

for testfile in testfiles:
if support.verbose >= 2:
print('tokenize', testfile)
with open(testfile, 'rb') as f:
with self.subTest(file=testfile):
self.check_roundtrip(f)
Expand Down
Loading