Merge aeda93ff372d17796434153f5262f3ae783aa429 into 520d8ee39037c9c94aa6e708a4fd6c0fa313ae80

This commit is contained in:
Eisuke Kawashima 2025-06-07 03:59:14 +09:00 committed by GitHub
commit ef7bd4d6c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 58 additions and 61 deletions

View File

@ -24,7 +24,7 @@ constants of full-`constexpr` enums. To extend:
replacement macros for `enum.h` to use. Pick a name for this file and a replacement macros for `enum.h` to use. Pick a name for this file and a
location somewhere in your include path. I will assume that this file is location somewhere in your include path. I will assume that this file is
`common/enum_macros.h` in your project. `common/enum_macros.h` in your project.
4. Run `python make_macros.py 512 64 > common/enum_macros.h`. 4. Run `python3 make_macros.py 512 64 > common/enum_macros.h`.
5. Define `BETTER_ENUMS_MACRO_FILE <common/enum_macros.h>` before including 5. Define `BETTER_ENUMS_MACRO_FILE <common/enum_macros.h>` before including
`enum.h`. This is typically done by supplying extra flags to the compiler `enum.h`. This is typically done by supplying extra flags to the compiler
on the command line: on the command line:

View File

@ -5,7 +5,7 @@ SOURCE_CXX := $(foreach md,$(SOURCE_MARKDOWN),$(call toexample,$(md)))
.PHONY : html .PHONY : html
html : html :
python docs.py python3 docs.py
@echo "See html/index.html" @echo "See html/index.html"
.PHONY : publish .PHONY : publish
@ -19,14 +19,14 @@ prepare : examples web
.PHONY : web .PHONY : web
web : examples web : examples
python docs.py --web python3 docs.py --web
.PHONY : examples .PHONY : examples
examples : $(SOURCE_CXX) examples : $(SOURCE_CXX)
define EXAMPLE define EXAMPLE
$(1) : $(2) $(1) : $(2)
python transform.py --o-cxx $(1) $(2) python3 transform.py --o-cxx $(1) $(2)
endef endef
$(foreach md,$(SOURCE_MARKDOWN), \ $(foreach md,$(SOURCE_MARKDOWN), \

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python #!/usr/bin/env python3
import glob import glob
import re import re
@ -8,7 +8,7 @@ import transform
import os import os
import os.path import os.path
import sys import sys
import urllib import urllib.parse
TEMPLATE_DIRECTORY = "template" TEMPLATE_DIRECTORY = "template"
OUTPUT_DIRECTORY = "html" OUTPUT_DIRECTORY = "html"
@ -85,8 +85,8 @@ def compose_page(relative_path, definitions):
definitions["canonical"] = canonical definitions["canonical"] = canonical
definitions["prefix"] = prefix definitions["prefix"] = prefix
definitions["quoted_url"] = urllib.quote(definitions["canonical"], "") definitions["quoted_url"] = urllib.parse.quote(definitions["canonical"], "")
definitions["quoted_title"] = urllib.quote(definitions["title"], "") definitions["quoted_title"] = urllib.parse.quote(definitions["title"], "")
if "class" not in definitions: if "class" not in definitions:
definitions["class"] = "" definitions["class"] = ""
@ -140,9 +140,7 @@ def compose_general_page(relative_path):
write_page(relative_path, text) write_page(relative_path, text)
def list_general_pages(): def list_general_pages():
return filter( return [s for s in glob.glob("*.md") if not os.path.splitext(os.path.basename(s))[0].isupper()]
lambda s: not os.path.splitext(os.path.basename(s))[0].isupper(),
glob.glob("*.md"))
def process_threaded(directory): def process_threaded(directory):
sources = glob.glob(os.path.join(directory, "*.md")) sources = glob.glob(os.path.join(directory, "*.md"))

View File

@ -944,7 +944,7 @@ class Markdown(object):
if not self.footnotes: if not self.footnotes:
return out return out
footnotes = filter(lambda o: keys.get(o['key']), self.footnotes) footnotes = [o for o in self.footnotes if keys.get(o['key'])]
self.footnotes = sorted( self.footnotes = sorted(
footnotes, key=lambda o: keys.get(o['key']), reverse=True footnotes, key=lambda o: keys.get(o['key']), reverse=True
) )

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python #!/usr/bin/env python3
# Reads mixed source/text markdown files and outputs HTML and/or C++ source. # Reads mixed source/text markdown files and outputs HTML and/or C++ source.
# Usage: # Usage:
@ -48,9 +48,9 @@ def pretty_print(text, prefix, start_with_prefix = True):
def camel_case(text): def camel_case(text):
components = re.split("[ -]+", text) components = re.split("[ -]+", text)
components = map(lambda s: s.capitalize(), components) components = [s.capitalize() for s in components]
result = "".join(components) result = "".join(components)
result = filter(lambda c: c not in ",!:-$()?", result) result = "".join([c for c in result if c not in ",!:-$()?"])
return result return result
class HtmlRenderer(mistune.Renderer): class HtmlRenderer(mistune.Renderer):

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python #!/usr/bin/env python3
# This file is part of Better Enums, released under the BSD 2-clause license. # This file is part of Better Enums, released under the BSD 2-clause license.
# See LICENSE for details, or visit http://github.com/aantron/better-enums. # See LICENSE for details, or visit http://github.com/aantron/better-enums.
@ -25,7 +25,7 @@
# #
# 0. MACRO_FILE is the name of the external macro file. Make sure you put it # 0. MACRO_FILE is the name of the external macro file. Make sure you put it
# somewhere in your include path. # somewhere in your include path.
# 1. Run python make_macros.py 512 128 > MACRO_FILE # 1. Run python3 make_macros.py 512 128 > MACRO_FILE
# 2. Build your code with an additional compiler flag: # 2. Build your code with an additional compiler flag:
# - for gcc and clang, -DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>' # - for gcc and clang, -DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
# - for VC++, /DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>' # - for VC++, /DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
@ -53,7 +53,7 @@ class MultiLine(object):
break_line = True break_line = True
if break_line: if break_line:
print >> self._stream, ' ' * (self._columns_left - 1) + '\\' print(' ' * (self._columns_left - 1) + '\\', file=self._stream)
self._stream.write(' ' * self._indent) self._stream.write(' ' * self._indent)
self._columns_left = self._columns - self._indent self._columns_left = self._columns - self._indent
token = token.lstrip() token = token.lstrip()
@ -62,42 +62,42 @@ class MultiLine(object):
self._columns_left -= len(token) self._columns_left -= len(token)
def generate(stream, constants, length, script): def generate(stream, constants, length, script):
print >> stream, '// This file was automatically generated by ' + script print('// This file was automatically generated by ' + script, file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#pragma once' print('#pragma once', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#ifndef BETTER_ENUMS_MACRO_FILE_H' print('#ifndef BETTER_ENUMS_MACRO_FILE_H', file=stream)
print >> stream, '#define BETTER_ENUMS_MACRO_FILE_H' print('#define BETTER_ENUMS_MACRO_FILE_H', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\' print('#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\', file=stream)
print >> stream, ' BETTER_ENUMS_ID( \\' print(' BETTER_ENUMS_ID( \\', file=stream)
print >> stream, ' BETTER_ENUMS_APPLY( \\' print(' BETTER_ENUMS_APPLY( \\', file=stream)
print >> stream, ' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\' print(' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\', file=stream)
print >> stream, ' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\' print(' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\', file=stream)
print >> stream, ' (macro, data, __VA_ARGS__))' print(' (macro, data, __VA_ARGS__))', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' + \ print('#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' +
'BETTER_ENUMS_M ## count' 'BETTER_ENUMS_M ## count', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_APPLY(macro, ...) ' + \ print('#define BETTER_ENUMS_APPLY(macro, ...) ' +
'BETTER_ENUMS_ID(macro(__VA_ARGS__))' 'BETTER_ENUMS_ID(macro(__VA_ARGS__))', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_ID(x) x' print('#define BETTER_ENUMS_ID(x) x', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)' print('#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)', file=stream)
for index in range(2, constants + 1): for index in range(2, constants + 1):
print >> stream, '#define BETTER_ENUMS_M' + str(index) + \ print('#define BETTER_ENUMS_M' + str(index) +
'(m,d,x,...) m(d,' + str(index - 1) + ',x) \\' '(m,d,x,...) m(d,' + str(index - 1) + ',x) \\', file=stream)
print >> stream, ' BETTER_ENUMS_ID(BETTER_ENUMS_M' + \ print(' BETTER_ENUMS_ID(BETTER_ENUMS_M' +
str(index - 1) + '(m,d,__VA_ARGS__))' str(index - 1) + '(m,d,__VA_ARGS__))', file=stream)
print >> stream, '' print('', file=stream)
pp_count_impl_prefix = '#define BETTER_ENUMS_PP_COUNT_IMPL(_1,' pp_count_impl_prefix = '#define BETTER_ENUMS_PP_COUNT_IMPL(_1,'
stream.write(pp_count_impl_prefix) stream.write(pp_count_impl_prefix)
pp_count_impl = MultiLine(stream = stream, indent = 4, pp_count_impl = MultiLine(stream = stream, indent = 4,
@ -107,10 +107,10 @@ def generate(stream, constants, length, script):
pp_count_impl.write(' count,') pp_count_impl.write(' count,')
pp_count_impl.write(' ...)') pp_count_impl.write(' ...)')
pp_count_impl.write(' count', last = True) pp_count_impl.write(' count', last = True)
print >> stream, '' print('', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#define BETTER_ENUMS_PP_COUNT(...) \\' print('#define BETTER_ENUMS_PP_COUNT(...) \\', file=stream)
pp_count_prefix = \ pp_count_prefix = \
' BETTER_ENUMS_ID(BETTER_ENUMS_PP_COUNT_IMPL(__VA_ARGS__,' ' BETTER_ENUMS_ID(BETTER_ENUMS_PP_COUNT_IMPL(__VA_ARGS__,'
stream.write(pp_count_prefix) stream.write(pp_count_prefix)
@ -119,28 +119,27 @@ def generate(stream, constants, length, script):
for index in range(0, constants - 1): for index in range(0, constants - 1):
pp_count.write(' ' + str(constants - index) + ',') pp_count.write(' ' + str(constants - index) + ',')
pp_count.write(' 1))', last = True) pp_count.write(' 1))', last = True)
print >> stream, '' print('', file=stream)
print >> stream, '' print('', file=stream)
iterate_prefix = '#define BETTER_ENUMS_ITERATE(X, f, l)' iterate_prefix = '#define BETTER_ENUMS_ITERATE(X, f, l)'
stream.write(iterate_prefix) stream.write(iterate_prefix)
iterate = MultiLine(stream = stream, indent = 4, iterate = MultiLine(stream = stream, indent = 4,
initial_column = len(iterate_prefix)) initial_column = len(iterate_prefix))
for index in range(0, length): for index in range(0, length):
iterate.write(' X(f, l, %i)' % index) iterate.write(' X(f, l, %i)' % index)
print >> stream, '' print('', file=stream)
print >> stream, '' print('', file=stream)
print >> stream, '#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H' print('#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H', file=stream)
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 3: if len(sys.argv) != 3:
print >> sys.stderr, \ print('Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE', file=sys.stderr)
'Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE' print('', file=sys.stderr)
print >> sys.stderr, '' print('Prints map macro definition to FILE.', file=sys.stderr)
print >> sys.stderr, 'Prints map macro definition to FILE.' print('CONSTANTS is the number of constants to support.', file=sys.stderr)
print >> sys.stderr, 'CONSTANTS is the number of constants to support.' print('LENGTH is the maximum length of a constant name.', file=sys.stderr)
print >> sys.stderr, 'LENGTH is the maximum length of a constant name.'
sys.exit(1) sys.exit(1)
generate(sys.stdout, int(sys.argv[1]), int(sys.argv[2]), generate(sys.stdout, int(sys.argv[1]), int(sys.argv[2]),

View File

@ -36,7 +36,7 @@ define PATH_FIX
sed 's!include "/!include "C:/cygwin/!g' $1 > $$$$ && mv $$$$ $1 sed 's!include "/!include "C:/cygwin/!g' $1 > $$$$ && mv $$$$ $1
endef endef
SUFFIX := .exe SUFFIX := .exe
CXXTESTGEN := python `which cxxtestgen | sed -E 's!(/cygdrive)?/c/!c:/!'` CXXTESTGEN := python3 `which cxxtestgen | sed -E 's!(/cygdrive)?/c/!c:/!'`
endif endif