coordle/backend/coordle_backend.py
def assert_query(self, querytokens: deque, errmsgs: list) -> bool:
        '''
        Check if query is properly formatted. Returns True if everything is ok,
        else False. 
        '''
        q = querytokens.copy()
        p_list = []
        p_counter = 0 
        flag = True
        curr = q.popleft()
        
        ##### Initialize by checking the first token #####
        
        # Stray closing parenthesis
        if curr == ')':
            p_counter -= 1
            p_list.append(p_counter)
            flag = False
        
        if curr == '(':
            p_counter += 1
            p_list.append(p_counter)
        
        # If query is starting with an operator
        if curr in self.operators:
            errmsgs.append(f'SyntaxError: First token "{curr}" is an operator')
            flag = False
        
        # If querytokens consisted of only a single token
        if len(q) == 0:
            if p_counter != 0:
                errmsgs.append(f'SyntaxError: Stray parenthesis')
                flag = False
            return flag
        ##################################################
        
        prev = curr
        # Runs if more than one token left
        while len(q) > 0:
            curr: str = q.popleft()
            
            if curr == '(':
                p_counter += 1
                p_list.append(p_counter)
            
            if curr == ')':
                p_counter -= 1
                p_list.append(p_counter)
            
            # If curr is operator
            if curr in self.operators:
                # Two succeeding operators
                if prev in self.operators:
                    errmsgs.append(f'SyntaxError: Two succeeding operators "{prev} {curr}"')
                    flag = False
                    
            prev = curr
        
        # Should only be one token left when interpreter is here
        
        # If ending with an operator
        if prev in self.operators:
            errmsgs.append(f'SyntaxError: Last token "{prev}" is an operator')
            flag = False
        
        ###### Check paranthesis' #####
        
        # If unbalanced number of parenthesis'
        if p_counter > 0:
            errmsgs.append(f'SyntaxError: Found stray opening parenthesis')
            flag = False
            
        # Check if any negative values in p_list, implies stray closing 
        # parenthesis
        if any((x < 0 for x in p_list)): 
            errmsgs.append(f'SyntaxError: Found stray closing parenthesis')
            flag = False
        ###############################
        return flag

        Check if query is properly formatted. Returns True if everything is ok,
        else False. 
        
Check if query is properly formatted. Returns True if everything is ok,
else False.
Check if query is properly formatted . Returns True if everything is ok else False .
def assert_query(self, querytokens: deque, errmsgs: list) -> bool:
        q = querytokens.copy()
        p_list = []
        p_counter = 0 
        flag = True
        curr = q.popleft()
        if curr == ')':
            p_counter -= 1
            p_list.append(p_counter)
            flag = False
        if curr == '(':
            p_counter += 1
            p_list.append(p_counter)
        if curr in self.operators:
            errmsgs.append(f'SyntaxError: First token "{curr}" is an operator')
            flag = False
        if len(q) == 0:
            if p_counter != 0:
                errmsgs.append(f'SyntaxError: Stray parenthesis')
                flag = False
            return flag
        prev = curr
        while len(q) > 0:
            curr: str = q.popleft()
            if curr == '(':
                p_counter += 1
                p_list.append(p_counter)
            if curr == ')':
                p_counter -= 1
                p_list.append(p_counter)
            if curr in self.operators:
                if prev in self.operators:
                    errmsgs.append(f'SyntaxError: Two succeeding operators "{prev} {curr}"')
                    flag = False
            prev = curr
        if prev in self.operators:
            errmsgs.append(f'SyntaxError: Last token "{prev}" is an operator')
            flag = False
        if p_counter > 0:
            errmsgs.append(f'SyntaxError: Found stray opening parenthesis')
            flag = False
        if any((x < 0 for x in p_list)): 
            errmsgs.append(f'SyntaxError: Found stray closing parenthesis')
            flag = False
        return flag
def assert_query ( self , querytokens : deque , errmsgs : list ) -> bool : q = querytokens . copy ( ) p_list = [ ] p_counter = 0 flag = True curr = q . popleft ( ) if curr == ')' : p_counter -= 1 p_list . append ( p_counter ) flag = False if curr == '(' : p_counter += 1 p_list . append ( p_counter ) if curr in self . operators : errmsgs . append ( f'SyntaxError: First token "{curr}" is an operator' ) flag = False if len ( q ) == 0 : if p_counter != 0 : errmsgs . append ( f'SyntaxError: Stray parenthesis' ) flag = False return flag prev = curr while len ( q ) > 0 : curr : str = q . popleft ( ) if curr == '(' : p_counter += 1 p_list . append ( p_counter ) if curr == ')' : p_counter -= 1 p_list . append ( p_counter ) if curr in self . operators : if prev in self . operators : errmsgs . append ( f'SyntaxError: Two succeeding operators "{prev} {curr}"' ) flag = False prev = curr if prev in self . operators : errmsgs . append ( f'SyntaxError: Last token "{prev}" is an operator' ) flag = False if p_counter > 0 : errmsgs . append ( f'SyntaxError: Found stray opening parenthesis' ) flag = False if any ( ( x < 0 for x in p_list ) ) : errmsgs . append ( f'SyntaxError: Found stray closing parenthesis' ) flag = False return flag
Check if query is properly formatted.
Check if query is properly formatted .
'''
        Check if query is properly formatted. Returns True if everything is ok,
        else False. 
        ''' ##### Initialize by checking the first token ##### # Stray closing parenthesis # If query is starting with an operator # If querytokens consisted of only a single token ################################################## # Runs if more than one token left # If curr is operator # Two succeeding operators # Should only be one token left when interpreter is here # If ending with an operator ###### Check paranthesis' ##### # If unbalanced number of parenthesis' # Check if any negative values in p_list, implies stray closing  # parenthesis ###############################
self
querytokens
deque
errmsgs
list