diff options
Diffstat (limited to 'src/smp')
-rw-r--r-- | src/smp/builtins.py | 2 | ||||
-rw-r--r-- | src/smp/macro_processor.py | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/smp/builtins.py b/src/smp/builtins.py index c1d67ce..3ff15c6 100644 --- a/src/smp/builtins.py +++ b/src/smp/builtins.py @@ -20,7 +20,7 @@ def smp_builtin_define(macro_processor, macro_name, macro_value=None): def smp_builtin_undefine(macro_processor, macro_name): if macro_name in macro_processor.macros: - del macro_processor[macro_name] + del macro_processor.macros[macro_name] return "" diff --git a/src/smp/macro_processor.py b/src/smp/macro_processor.py index bda6c6f..68fd726 100644 --- a/src/smp/macro_processor.py +++ b/src/smp/macro_processor.py @@ -31,6 +31,30 @@ def macro_name_clean(macro_name: str) -> str: return macro_name +def seek(input: str, start: int, target: str) -> int | None: + """Seek for a value in a string, consider using startswith instead""" + from warnings import warn + + warn( + "seek should be considered replaced with str.startswith", + DeprecationWarning, + stacklevel=2, + ) + input_end = len(input) + target_end = len(target) + + if input_end < start + target_end: + return None + + i = 0 + while i < len(target): + if input[start + i] != target[i]: + return None + i += 1 + + return start + target_end + + class MacroProcessor: """All currently defined macros in this MacroProcessor""" @@ -46,6 +70,9 @@ class MacroProcessor: special_macros: dict[str, tuple[Any, Any]] + start_quote: str = '%"' + end_quote: str = '"%' + def __init__(self, prefix=""): self.macros = dict() self.macro_invocations = list() |