(
infile="Lib/re/_constants.py",
outfile_constants="crates/sre_engine/src/constants.rs",
)
| 84 | |
| 85 | |
| 86 | def main( |
| 87 | infile="Lib/re/_constants.py", |
| 88 | outfile_constants="crates/sre_engine/src/constants.rs", |
| 89 | ): |
| 90 | ns = {} |
| 91 | with open(infile) as fp: |
| 92 | code = fp.read() |
| 93 | exec(code, ns) |
| 94 | |
| 95 | content = [sre_constants_header] |
| 96 | content.append("use bitflags::bitflags;\n\n") |
| 97 | content.append(f"pub const SRE_MAGIC: usize = {ns['MAGIC']};\n") |
| 98 | content.extend( |
| 99 | dump_enum( |
| 100 | ns["OPCODES"], |
| 101 | "SreOpcode", |
| 102 | "#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]", |
| 103 | ) |
| 104 | ) |
| 105 | content.extend( |
| 106 | dump_enum( |
| 107 | ns["ATCODES"], |
| 108 | "SreAtCode", |
| 109 | "#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]", |
| 110 | "AT_", |
| 111 | ) |
| 112 | ) |
| 113 | content.extend( |
| 114 | dump_enum( |
| 115 | ns["CHCODES"], |
| 116 | "SreCatCode", |
| 117 | "#[derive(num_enum::TryFromPrimitive, Debug)]", |
| 118 | "CATEGORY_", |
| 119 | ) |
| 120 | ) |
| 121 | |
| 122 | content.extend( |
| 123 | dump_bitflags( |
| 124 | ns, |
| 125 | "SRE_FLAG_", |
| 126 | "#[derive(Debug, PartialEq, Eq, Clone, Copy)]", |
| 127 | "SreFlag", |
| 128 | "u16", |
| 129 | ) |
| 130 | ) |
| 131 | content.extend(dump_bitflags(ns, "SRE_INFO_", "", "SreInfo", "u32")) |
| 132 | |
| 133 | update_file(outfile_constants, "".join(content)) |
| 134 | |
| 135 | |
| 136 | if __name__ == "__main__": |
no test coverage detected