Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore tabs in expression #88

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dissect/cstruct/expression.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading