diff --git a/tagstudio/src/core/query_lang/ast.py b/tagstudio/src/core/query_lang/ast.py index 1eb9cdda..af828cd6 100644 --- a/tagstudio/src/core/query_lang/ast.py +++ b/tagstudio/src/core/query_lang/ast.py @@ -84,24 +84,24 @@ T = TypeVar("T") class BaseVisitor(ABC, Generic[T]): def visit(self, node: AST) -> T: return { - ANDList: self.visit_ANDList, - ORList: self.visit_ORList, - Constraint: self.visit_Constraint, - Property: self.visit_Property, + ANDList: self.visit_and_list, + ORList: self.visit_or_list, + Constraint: self.visit_constraint, + Property: self.visit_property, }[type(node)](node) @abstractmethod - def visit_ANDList(self, node: ANDList) -> T: # noqa: N802 + def visit_and_list(self, node: ANDList) -> T: raise NotImplementedError() @abstractmethod - def visit_ORList(self, node: ORList) -> T: # noqa: N802 + def visit_or_list(self, node: ORList) -> T: raise NotImplementedError() @abstractmethod - def visit_Constraint(self, node: Constraint) -> T: # noqa: N802 + def visit_constraint(self, node: Constraint) -> T: raise NotImplementedError() @abstractmethod - def visit_Property(self, node: Property) -> T: # noqa: N802 + def visit_property(self, node: Property) -> T: raise NotImplementedError() diff --git a/tagstudio/src/core/query_lang/parser.py b/tagstudio/src/core/query_lang/parser.py index 08533f47..5631da5b 100644 --- a/tagstudio/src/core/query_lang/parser.py +++ b/tagstudio/src/core/query_lang/parser.py @@ -18,6 +18,8 @@ class Parser: self.next_token = self.tokenizer.get_next_token() def parse(self) -> AST: + if self.next_token.type == TokenType.EOF: + return ORList([]) out = self.__or_list() if self.next_token.type != TokenType.EOF: raise ParsingError(self.next_token.start, self.next_token.end, "Syntax Error") diff --git a/tagstudio/src/core/query_lang/tokenizer.py b/tagstudio/src/core/query_lang/tokenizer.py index 16523d7b..242f362c 100644 --- a/tagstudio/src/core/query_lang/tokenizer.py +++ b/tagstudio/src/core/query_lang/tokenizer.py @@ -58,7 +58,7 @@ class Tokenizer: def __init__(self, text: str) -> None: self.text = text self.pos = 0 - self.current_char = self.text[self.pos] + self.current_char = self.text[self.pos] if len(text) > 0 else None def get_next_token(self) -> Token: self.__skip_whitespace() @@ -143,9 +143,7 @@ class Tokenizer: self.current_char = None def __skip_whitespace(self) -> None: - if self.current_char is None: - return - while self.current_char.isspace(): + while self.current_char is not None and self.current_char.isspace(): self.__advance()