Ejemplo n.º 1
0
 def __prepare_wrapped_invocation(invocation: dict) -> dict:
     new_invoke = invocation.copy()
     if Tokens.is_spacing_token(new_invoke['arguments'][0]):
         new_invoke['arguments'] = new_invoke['arguments'][1:]
     if Tokens.is_spacing_token(new_invoke['arguments'][-1]):
         new_invoke['arguments'] = new_invoke['arguments'][:-1]
     return new_invoke
Ejemplo n.º 2
0
 def wrap(self, invocation: dict) -> dict:
     wrapped_invoke = self.__prepare_wrapped_invocation(invocation)
     wrapped_invoke['arguments'] = [
         e if not Tokens.is_spacing_token(e) else ' '
         for e in wrapped_invoke['arguments']
     ]
     return wrapped_invoke
Ejemplo n.º 3
0
 def __merge_line_comments_with_whitespaces_before(args: List[str]) -> list:
     merged = []
     for i in range(len(args) - 1):
         if Tokens.is_spacing_token(args[i]) and Tokens.is_line_comment(
                 args[i + 1]):
             args[i + 1] = args[i] + args[i + 1]
         else:
             merged.append(args[i])
     return merged + [args[-1]] if args else []
Ejemplo n.º 4
0
 def __realign_commands(self, args: List[str]) -> list:
     diff = 0 if self.__settings.get('keyword_and_single_value_in_one_line') else CommandRealignModifier.__DIFF_BETWEEN_KEYWORD_AND_VALUE
     for i in range(len(args)):
         if KeywordVerifier.is_command_keyword(args[i]):
             for j in range(i + diff, len(args) - 1):
                 if self.__verifier.is_keyword(args[j + 1]):
                     break
                 if Tokens.is_spacing_token(args[j]):
                     args[j] = ' '
     return args
Ejemplo n.º 5
0
 def test_matching_spacing_tokens(self):
     self.assertFalse(Tokens.is_line_comment(''))
     self.assertTrue(Tokens.is_spacing_token(' '))
     self.assertTrue(Tokens.is_spacing_token('\t '))
     self.assertTrue(Tokens.is_spacing_token('\t \n'))
     self.assertTrue(Tokens.is_spacing_token(f'\t {Tokens.remove_spaces()}\n'))
     self.assertFalse(Tokens.is_spacing_token('\t d'))
     self.assertFalse(Tokens.is_spacing_token(f'\t {Tokens.reindent(1)}'))
Ejemplo n.º 6
0
 def __is_argument(data: str) -> bool:
     return not (Tokens.is_line_comment(data) or Tokens.is_spacing_token(data))
Ejemplo n.º 7
0
 def __should_realign_value_after_keyword(self, args: List[str], current_index: int) -> bool:
     return self.__verifier.is_keyword_or_property(args[current_index]) and \
            Tokens.is_spacing_token(args[current_index + 1]) and \
            not self.__verifier.is_keyword_or_property(args[current_index + 2]) and \
            self.__is_single_value(args, current_index)
Ejemplo n.º 8
0
 def __is_last_element_newline(invocation: dict) -> bool:
     return Tokens.is_spacing_token(invocation['arguments'][-1]) or \
            Tokens.is_line_comment(invocation['arguments'][-1])
Ejemplo n.º 9
0
 def __is_spacing_token(args: List[str], index: int) -> bool:
     try:
         return Tokens.is_spacing_token(args[index])
     except IndexError:
         return False