summaryrefslogtreecommitdiffstats
path: root/Lib/re
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-12 15:34:06 (GMT)
committerGitHub <noreply@github.com>2022-04-12 15:34:06 (GMT)
commit474fdbe9e4a2ff90ef39e8748da644c86a200981 (patch)
treed15c64e70f6038121cf698b8b80b4436a0964e6d /Lib/re
parent943ca5e1d6b72830c530a72426cff094f155d010 (diff)
downloadcpython-474fdbe9e4a2ff90ef39e8748da644c86a200981.zip
cpython-474fdbe9e4a2ff90ef39e8748da644c86a200981.tar.gz
cpython-474fdbe9e4a2ff90ef39e8748da644c86a200981.tar.bz2
bpo-47152: Automatically regenerate sre_constants.h (GH-91439)
* Move the code for generating Modules/_sre/sre_constants.h from Lib/re/_constants.py into a separate script Tools/scripts/generate_sre_constants.py. * Add target `regen-sre` in the makefile. * Make target `regen-all` depending on `regen-sre`.
Diffstat (limited to 'Lib/re')
-rw-r--r--Lib/re/_constants.py43
1 files changed, 0 insertions, 43 deletions
diff --git a/Lib/re/_constants.py b/Lib/re/_constants.py
index 4c7e93e..5e999de 100644
--- a/Lib/re/_constants.py
+++ b/Lib/re/_constants.py
@@ -215,46 +215,3 @@ SRE_FLAG_ASCII = 256 # use ascii "locale"
SRE_INFO_PREFIX = 1 # has prefix
SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix)
SRE_INFO_CHARSET = 4 # pattern starts with character from given set
-
-if __name__ == "__main__":
- def dump(f, d, prefix):
- items = sorted(d)
- for item in items:
- f.write("#define %s_%s %d\n" % (prefix, item, item))
- with open("sre_constants.h", "w") as f:
- f.write("""\
-/*
- * Secret Labs' Regular Expression Engine
- *
- * regular expression matching engine
- *
- * NOTE: This file is generated by Lib/re/_constants.py. If you need
- * to change anything in here, edit Lib/re/_constants.py and run it.
- *
- * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
- *
- * See the sre.c file for information on usage and redistribution.
- */
-
-""")
-
- f.write("#define SRE_MAGIC %d\n" % MAGIC)
-
- dump(f, OPCODES, "SRE_OP")
- dump(f, ATCODES, "SRE")
- dump(f, CHCODES, "SRE")
-
- f.write("#define SRE_FLAG_IGNORECASE %d\n" % SRE_FLAG_IGNORECASE)
- f.write("#define SRE_FLAG_LOCALE %d\n" % SRE_FLAG_LOCALE)
- f.write("#define SRE_FLAG_MULTILINE %d\n" % SRE_FLAG_MULTILINE)
- f.write("#define SRE_FLAG_DOTALL %d\n" % SRE_FLAG_DOTALL)
- f.write("#define SRE_FLAG_UNICODE %d\n" % SRE_FLAG_UNICODE)
- f.write("#define SRE_FLAG_VERBOSE %d\n" % SRE_FLAG_VERBOSE)
- f.write("#define SRE_FLAG_DEBUG %d\n" % SRE_FLAG_DEBUG)
- f.write("#define SRE_FLAG_ASCII %d\n" % SRE_FLAG_ASCII)
-
- f.write("#define SRE_INFO_PREFIX %d\n" % SRE_INFO_PREFIX)
- f.write("#define SRE_INFO_LITERAL %d\n" % SRE_INFO_LITERAL)
- f.write("#define SRE_INFO_CHARSET %d\n" % SRE_INFO_CHARSET)
-
- print("done")