MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / parse_proc_code

Function parse_proc_code

scratchattach/editor/mutation.py:124–166  ·  view source on GitHub ↗

Parse a proccode (part of a mutation) into argument types and strings

(_proc_code: str)

Source from the content-addressed store, hash-verified

122
123
124def 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
169def construct_proccode(*components: ArgumentType | ArgTypes | Argument | str) -> str:

Callers 2

typeMethod · 0.85
parsed_proc_codeMethod · 0.85

Calls 1

dcopyMethod · 0.80

Tested by

no test coverage detected