mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 23:59:10 +00:00
refactoring and fixes
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user