aboutsummaryrefslogtreecommitdiff
path: root/contrib/enumutils_describe.py
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-09-04 00:58:23 +0200
committerGitHub <noreply@github.com>2020-09-04 00:58:23 +0200
commit88d446dadf65bf47c72d3042834281233b1174ac (patch)
tree3e111e59e2241712bc82c627fdcb3e8ed9a9cf51 /contrib/enumutils_describe.py
parent35b3ba90b03143f2dc700cc4baeb88a58089c102 (diff)
Scripts/Commands: Convert argument parsing of .npc commands
(And I snuck some chat command cleanup in there, more de-cluttering!)
Diffstat (limited to 'contrib/enumutils_describe.py')
-rw-r--r--contrib/enumutils_describe.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/contrib/enumutils_describe.py b/contrib/enumutils_describe.py
index d6923b87dcc..70dca43238c 100644
--- a/contrib/enumutils_describe.py
+++ b/contrib/enumutils_describe.py
@@ -25,8 +25,8 @@ if not getcwd().endswith('src'):
print('(Invoke as \'python ../contrib/enumutils_describe.py\')')
exit(1)
-EnumPattern = compile(r'//\s*EnumUtils: DESCRIBE THIS\s+enum\s+([0-9A-Za-z]+)[^\n]*\s*{([^}]+)};')
-EnumValuesPattern = compile(r'\s+.+?(,|$)[^\n]*')
+EnumPattern = compile(r'//\s*EnumUtils: DESCRIBE THIS(?:\s*\(in ([^\)]+)\))?\s+enum\s+([0-9A-Za-z]+)[^\n]*\s*{([^}]+)};')
+EnumValuesPattern = compile(r'\s+\S.+?(,|$)[^\n]*')
EnumValueNamePattern = compile(r'^\s*([a-zA-Z0-9_]+)', flags=MULTILINE)
EnumValueSkipLinePattern = compile(r'^\s*//')
EnumValueCommentPattern = compile(r'//,?[ \t]*([^\n]+)$')
@@ -52,9 +52,10 @@ def processFile(path, filename):
enums = []
for enum in EnumPattern.finditer(file):
- name = enum.group(1)
+ prefix = enum.group(1) or ''
+ name = enum.group(2)
values = []
- for value in EnumValuesPattern.finditer(enum.group(2)):
+ for value in EnumValuesPattern.finditer(enum.group(3)):
valueData = value.group(0)
valueNameMatch = EnumValueNamePattern.search(valueData)
@@ -89,7 +90,7 @@ def processFile(path, filename):
values.append((valueName, valueTitle, valueDescription))
- enums.append((name, values))
+ enums.append((prefix + name, prefix, values))
print('%s.h: Enum %s parsed with %d values' % (filename, name, len(values)))
if not enums:
@@ -110,7 +111,7 @@ def processFile(path, filename):
output.write('\n')
output.write('namespace Trinity::Impl::EnumUtilsImpl\n')
output.write('{\n')
- for name, values in enums:
+ for name, prefix, values in enums:
tag = ('data for enum \'%s\' in \'%s.h\' auto-generated' % (name, filename))
output.write('\n')
output.write('/*' + ('*'*(len(tag)+2)) + '*\\\n')
@@ -122,7 +123,7 @@ def processFile(path, filename):
output.write(' switch (value)\n')
output.write(' {\n')
for label, title, description in values:
- output.write(' case %s: return { %s, %s, %s };\n' % (label, strescape(label), strescape(title), strescape(description)))
+ output.write(' case %s: return { %s, %s, %s };\n' % (prefix + label, strescape(label), strescape(title), strescape(description)))
output.write(' default: throw std::out_of_range("value");\n')
output.write(' }\n')
output.write('}\n')
@@ -135,8 +136,8 @@ def processFile(path, filename):
output.write('{\n')
output.write(' switch (index)\n')
output.write(' {\n')
- for i in range(len(values)):
- output.write(' case %d: return %s;\n' % (i, values[i][0]))
+ for (i, (label, title, description)) in enumerate(values):
+ output.write(' case %d: return %s;\n' % (i, prefix + label))
output.write(' default: throw std::out_of_range("index");\n')
output.write(' }\n')
output.write('}\n')
@@ -146,8 +147,8 @@ def processFile(path, filename):
output.write('{\n')
output.write(' switch (value)\n')
output.write(' {\n')
- for i in range(len(values)):
- output.write(' case %s: return %d;\n' % (values[i][0], i))
+ for (i, (label, title, description)) in enumerate(values):
+ output.write(' case %s: return %d;\n' % (prefix + label, i))
output.write(' default: throw std::out_of_range("value");\n')
output.write(' }\n')
output.write('}\n')