From e0d42d1413ab30de7e35e2e9e42ef4ad233b61f6 Mon Sep 17 00:00:00 2001 From: rahul4732saini Date: Fri, 5 Jul 2024 21:29:17 +0530 Subject: [PATCH] Fix `parse_query` function in common/tools.py 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. --- fise/common/tools.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fise/common/tools.py b/fise/common/tools.py index 9ef7b49..b6e4e3a 100644 --- a/fise/common/tools.py +++ b/fise/common/tools.py @@ -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 @@ -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)