From d0e30f1ab57fc6a6a107c13a745ccc0747ee4c88 Mon Sep 17 00:00:00 2001 From: Admiral-Fish Date: Sun, 9 Jul 2023 15:11:04 -0700 Subject: [PATCH] Fully compute test enum mappings --- Source/Test/enum_map.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Source/Test/enum_map.py b/Source/Test/enum_map.py index fb0f7808..ae48fd2a 100644 --- a/Source/Test/enum_map.py +++ b/Source/Test/enum_map.py @@ -5,24 +5,32 @@ def enum_map(parent, files): - re1 = re.compile(r"enum class (\w+) .+ {(.+)};") - re2 = re.compile(r"([a-zA-Z]\w+)(?:,| =)") + re1 = re.compile(r"enum class (\w+) : u\d+") + re2 = re.compile(r"(\w+)(?:,| =|$)") strings = [] for file in files: with open(f"{parent}/{file}.hpp", "r") as f: - data = f.read().replace("\n", " ") + data = [x for x in f.read().split("\n") if x != ""] - enum_data = re1.search(data) + for start, string in enumerate(data): + if string.startswith("enum class"): + enum_name = re1.search(string).group(1) + start += 2 + break - enum_name = enum_data.group(1) - enum_class = enum_data.group(2) - enum_values = list(set(re2.findall(enum_class))) + for end in range(start + 1, len(data), 1): + if data[end] == "};": + break + + data = data[start:end] string = f"NLOHMANN_JSON_SERIALIZE_ENUM( {enum_name}, {{\n" - for i, enum_value in enumerate(enum_values): + for i, line in enumerate(data): + enum_value = re2.search(line).group(1) + string += f"\t{{ {enum_name}::{enum_value}, \"{enum_value}\" }}" - if i != len(enum_values) - 1: + if i != len(data) - 1: string += "," string += "\n" string += "})"