def create_variable(self, words): snippets = [""] index_type = helper.find_next_index({'array', 'dictionary', 'set', 'call', 'integer', 'string', 'equals'}, words) if index_type > 0: if words[index_type] == 'array': snippets[0] = format_variable(words[0:index_type]) + ' = []' elif words[index_type] == 'dictionary' or words[index_type] == 'set': snippets[0] = format_variable(words[0:index_type]) + ' = {}' elif words[index_type] == 'call': snippets[0] = format_variable(words[0:index_type]) + ' = ' + self.create_call(words[index_type+1:])[0] elif words[index_type] == 'integer': snippets[0] = format_variable(words[0:index_type]) + ' = ' + helper.verify_number(words[index_type+1]) elif words[index_type] == 'string': snippets[0] = format_variable(words[0:index_type]) + ' = ' snippets.append('quote') snippets.append(helper.convert_to_string(words[index_type+1:])) snippets.append('quote') elif words[index_type] == 'equals': snippets[0] = format_variable(words[0:index_type]) + ' = ' + self.process_conditional_math(helper.convert_to_string(words[index_type+1:])) else: snippets[0] = format_variable(words[0:index_type]) + ' = ' else: snippets[0] = format_variable(words) + ' = ' return snippets
def create_return(self, words): snippets = [""] if words[0] == 'variable': snippets[0] = format_variable(words[1:]) else: snippets[0] = helper.convert_to_string(words) return snippets
def create_while(self, words): snippets = [""] if words[0] == 'call': snippets[0] = 'while'+ self.create_call(words[1:])[0] + ':' elif words[0] == 'variable': snippets[0] = 'while ' + format_variable(words) + ':' else: # used process later snippets[0] = 'while ' + self.process_conditional_math(helper.convert_to_string(words)) + ':' return snippets
def create_print(self, words): snippets = [""] length = len(words) print(str(words)) if words[0] == 'variable' and length > 1: snippets[0] = 'print(str(' + format_variable(words[1:]) + '))' else: pass snippets[0] = 'print(' snippets.append('quote') snippets.append(format(helper.convert_to_string(words))) snippets.append('quote') snippets.append(')') return snippets
def create_elif(self, words): snippets = ["elif "] processed = self.process_conditional_math(helper.convert_to_string(words)) snippets[0] += processed + ':' return snippets