Skip to content

Commit

Permalink
Fix parse_query function in common/tools.py
Browse files Browse the repository at this point in the history
Fixed a bug in the `parse_query` function in common/tools.py where it parsed
characters after a terminating delimiter seperately from the previous token
without requiring a whitespace in between them as a separator. Also adjusted
the comments in correspondance with the changes made in the algorithm.
  • Loading branch information
rahul4732saini committed Jul 5, 2024
1 parent ee57d3a commit e0d42d1
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions fise/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def parse_query(query: str) -> list[str]:
# Temporarily stores the current token.
token = ""

# Stores an array of current starting delimiters which have
# not yet terminated during iteration in the specified query.
# Stores an array of current starting delimiters in the specified
# query which are not yet terminated during iteration.
cur: list = []

# Adds a whitespace at the end of the query to avoid
Expand All @@ -50,20 +50,14 @@ def parse_query(query: str) -> list[str]:
cur.append(char)
token += char

# Adds the token to list if the current character is
# not nested inside and is a terminating delimiter.
# Adds the current character to the list if it is a terminating delimiter
# and also pops up its corresponding starting delimiter in the `cur` list.
elif cur and char == delimiters.get(cur[-1]):
cur.pop()

if not cur:
tokens.append(token + char)
token = ""
continue

token += char

# Adds to list if the character is a top-level whitespace
# and `token` is not an empty or enclosed string.
# and `token` is not an nested or empty string.
elif not cur and char.isspace():
if token:
tokens.append(token)
Expand Down

0 comments on commit e0d42d1

Please sign in to comment.