from .ConsoleApplication import ConsoleApplication class REPLApplication (ConsoleApplication): def split_with_quotes(self, value : str): escaping = False in_quote = 0 next = "" retval = [ ] quote_types = [ ] for i in range(0, len(value)): if value[i] == "\"" and not escaping: if in_quote == 0: in_quote = 1 continue elif in_quote == 1: in_quote = 0 quote_types.append(1) retval.append(next) next = "" continue elif value[i] == "'" and not escaping: if in_quote == 0: in_quote = 2 continue elif in_quote == 2: in_quote = 0 quote_types.append(2) retval.append(next) next = "" continue elif value[i] == "`" and not escaping: if in_quote == 0: in_quote = 3 continue elif in_quote == 3: in_quote = 0 quote_types.append(3) retval.append(next) next = "" continue elif value[i] == "\\" and not escaping: escaping = True continue elif value[i] == " " and in_quote == 0: if not next == "": quote_types.append(None) retval.append(next) next = "" escaping = False continue next += value[i] escaping = False if not next == "": quote_types.append(None) retval.append(next) next = "" return (retval, quote_types) def _start_internal(self): while (True): # print ("open instance attribute relationship close") input_str = input(self.get_prompt()) (inp, quotes) = self.split_with_quotes(input_str) if inp[0] == "clear": self.clear() continue elif inp[0] == "exit": break elif inp[0] == "help": continue self.process_input(inp, quotes) exit(0) def get_prompt(self): return "> " def process_input(self, value, quotes): pass