Parse a proccode (part of a mutation) into argument types and strings
(_proc_code: str)
| 122 | |
| 123 | |
| 124 | def parse_proc_code(_proc_code: str) -> Optional[list[str | ArgumentType]]: |
| 125 | """ |
| 126 | Parse a proccode (part of a mutation) into argument types and strings |
| 127 | """ |
| 128 | |
| 129 | if _proc_code is None: |
| 130 | return None |
| 131 | token = "" |
| 132 | tokens = [] |
| 133 | |
| 134 | last_char = "" |
| 135 | for char in _proc_code: |
| 136 | if last_char == "%": |
| 137 | if char in "sb": |
| 138 | # If we've hit an %s or %b |
| 139 | token = token[:-1] |
| 140 | # Clip the % sign off the token |
| 141 | |
| 142 | if token.endswith(" "): |
| 143 | # A space is required before params, but this should not be part of the parsed output |
| 144 | token = token[:-1] |
| 145 | |
| 146 | if token != "": |
| 147 | # Make sure not to append an empty token |
| 148 | tokens.append(token) |
| 149 | |
| 150 | # Add the parameter token |
| 151 | token = f"%{char}" |
| 152 | if token == "%b": |
| 153 | tokens.append(ArgTypes.BOOLEAN.value.dcopy()) |
| 154 | elif token == "%s": |
| 155 | tokens.append(ArgTypes.NUMBER_OR_TEXT.value.dcopy()) |
| 156 | |
| 157 | token = "" |
| 158 | continue |
| 159 | |
| 160 | token += char |
| 161 | last_char = char |
| 162 | |
| 163 | if token != "": |
| 164 | tokens.append(token) |
| 165 | |
| 166 | return tokens |
| 167 | |
| 168 | |
| 169 | def construct_proccode(*components: ArgumentType | ArgTypes | Argument | str) -> str: |
no test coverage detected