aboutsummaryrefslogtreecommitdiff
path: root/src/smp
diff options
context:
space:
mode:
Diffstat (limited to 'src/smp')
-rw-r--r--src/smp/macro_processor.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/smp/macro_processor.py b/src/smp/macro_processor.py
index 19e692e..2519255 100644
--- a/src/smp/macro_processor.py
+++ b/src/smp/macro_processor.py
@@ -278,7 +278,8 @@ class MacroProcessor:
self.file = file
if (file is None) and (self.file is not None):
file = self.file
- output = ""
+ output: list[str] = []
+
state = ParserState.NORMAL
state_start = 0
macro_name = ""
@@ -358,7 +359,7 @@ class MacroProcessor:
args = [
x.strip()
for x in input[nspace:nline].split(" ")
- if x is not ""
+ if x != ""
]
sname = input[i + 1 : end_special]
@@ -366,8 +367,10 @@ class MacroProcessor:
hi_range(end=end_special)
args.append(input[nline + 1 :])
# @TODO: Make try/catch wrapper here as well
- output += self._expand_callable_macro(
- self.special_macros[sname][0], args
+ output.extend(
+ self._expand_callable_macro(
+ self.special_macros[sname][0], args
+ )
)
i = len(input) - 1
continue
@@ -382,23 +385,23 @@ class MacroProcessor:
state_start = i
macro_name += c
else:
- output += c
+ output.append(c)
elif state == ParserState.IN_QUOTES:
if c == "%" and peek == '"':
quote_level += 1
i += 1
- output += '%"'
+ output.extend(["%", '"'])
elif c == '"' and peek == "%":
quote_level -= 1
if quote_level == 0:
state = ParserState.NORMAL
state_start = i
else:
- output += '"%'
+ output.extend(['"', "%"])
i += 1
else:
- output += c
+ output.append(c)
elif state == ParserState.IN_MACRO:
if c.isalnum() or c == "_":
@@ -429,8 +432,8 @@ class MacroProcessor:
continue
else:
expanded = self.expand_macro(macro_name)
- output += expanded
- output += c
+ output.extend(expanded)
+ output.append(c)
macro_name = ""
self._pop_frame()
@@ -463,7 +466,7 @@ class MacroProcessor:
macro_args.append(argument.strip())
self._enter_frame(macro_name, file, linenr, input)
expanded = self.expand_macro(macro_name, macro_args)
- output += expanded
+ output.extend(expanded)
state = ParserState.NORMAL
state_start = i
macro_name = ""
@@ -490,7 +493,7 @@ class MacroProcessor:
exec(py_expr, self.py_global_env, self.py_local_env_current)
s = f.getvalue()
if s != "":
- output += s
+ output.extend(s)
except Exception:
traceback.print_exc()
finally:
@@ -510,8 +513,9 @@ class MacroProcessor:
output = output[:-1]
macro_name = macro_name_clean(macro_name)
hi_range()
- output += self.expand_macro(macro_name)
- return output
+ output.extend(self.expand_macro(macro_name))
+
+ return "".join(output)
def store(self, **xargs):
requested_keys = self._get_metadata("keep_states", [])