Skip to content
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
7 changes: 3 additions & 4 deletions src/tagstudio/core/query_lang/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class Parser:
tokenizer: Tokenizer
next_token: Token

last_constraint_type: ConstraintType = ConstraintType.Tag

def __init__(self, text: str) -> None:
self.text = text
self.tokenizer = Tokenizer(self.text)
Expand Down Expand Up @@ -92,11 +90,12 @@ def __is_next_not(self) -> bool:
return self.next_token.type == TokenType.ULITERAL and self.next_token.value.upper() == "NOT" # pyright: ignore

def __constraint(self) -> Constraint:
constraint_type = ConstraintType.Tag
if self.next_token.type == TokenType.CONSTRAINTTYPE:
constraint = self.__eat(TokenType.CONSTRAINTTYPE).value
if not isinstance(constraint, ConstraintType):
raise self.__syntax_error()
self.last_constraint_type = constraint
constraint_type = constraint

value = self.__literal()

Expand All @@ -111,7 +110,7 @@ def __constraint(self) -> Constraint:

self.__eat(TokenType.SBRACKETC)

return Constraint(self.last_constraint_type, value, properties)
return Constraint(constraint_type, value, properties)

def __property(self) -> Property:
key = self.__eat(TokenType.ULITERAL).value
Expand Down
1 change: 1 addition & 0 deletions tests/core/library/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_single_constraint(search_library: Library, query: str, count: int):
("square and filetype:jpg", 2),
("orange filetype:png", 5),
("green path:*inherit*", 4),
("filetype:png orange", 5),
],
)
def test_and(search_library: Library, query: str, count: int):
Expand Down
Loading