diff --git a/dissect/cstruct/expression.py b/dissect/cstruct/expression.py index 53e1cf2..4727f26 100644 --- a/dissect/cstruct/expression.py +++ b/dissect/cstruct/expression.py @@ -1,7 +1,7 @@ from __future__ import annotations import string -from typing import TYPE_CHECKING, Callable, Optional, Union +from typing import TYPE_CHECKING, Callable, Optional from dissect.cstruct.exceptions import ExpressionParserError, ExpressionTokenizerError @@ -18,7 +18,7 @@ def __init__(self, expression: str): self.pos = 0 self.tokens = [] - def equal(self, token: str, expected: Union[str, str[str]]) -> bool: + def equal(self, token: str, expected: str | set[str]) -> bool: if isinstance(expected, set): return token in expected else: @@ -42,7 +42,7 @@ def operator(self, token: str) -> bool: def match( self, func: Optional[Callable[[str], bool]] = None, - expected: Optional[str] = None, + expected: Optional[str | set[str]] = None, consume: bool = True, append: bool = True, ) -> bool: @@ -142,7 +142,7 @@ def tokenize(self) -> list[str]: self.tokens.append(">>") elif self.match(expected="<", append=False) and self.match(expected="<", append=False): self.tokens.append("<<") - elif self.match(expected=" ", append=False): + elif self.match(expected={" ", "\t"}, append=False): continue else: raise ExpressionTokenizerError( diff --git a/tests/test_expression.py b/tests/test_expression.py index c1d0fc0..1495ecf 100644 --- a/tests/test_expression.py +++ b/tests/test_expression.py @@ -11,6 +11,7 @@ ("7*8", 56), ("7 *8", 56), (" 7 * 8 ", 56), + ("\t7\t*\t8\t", 56), ("0 / 1", 0), ("1 / 1", 1), ("2 / 2", 1),