def execute_use(self, exec_ctx): fn = exec_ctx.symbol_table.get("fn") if not isinstance(fn, String): return RTResult().failure( RTError(self.pos_start, self.pos_end, "Second argument must be string", exec_ctx)) fn = fn.value try: with open(fn, "r") as f: script = f.read() except Exception as e: return RTResult().failure( RTError(self.pos_start, self.pos_end, f"Failed to load script \"{fn}\"\n" + str(e), exec_ctx)) _, error = ds.run(fn, script) if error: return RTResult().failure( RTError( self.pos_start, self.pos_end, f"Failed to finish executing script \"{fn}\"\n" + error.as_string(), exec_ctx)) return RTResult().success(Number.null)
def eval_current(self, auto_indent=False): """Evaluate code""" index = self.index('input') lines = self.get('input', 'insert lineend').splitlines() # commands to execute self.mark_set('insert', 'insert lineend') if lines: # there is code to execute # remove prompts lines = [lines[0].rstrip()] + [line[len(self._prompt2):].rstrip() for line in lines[1:]] cmds = '\n'.join(lines) self.insert('insert', '\n') result, error = ds.run("<Dip's Development Environment>", cmds) if cmds == "copyright": self.insert('insert',"Copyright (c) Raghav Nautiyal. All Rights Reserved.\n") self.prompt() error = None if cmds == "help": self.insert('insert',"Visit https://dip.org/docs for help!\n") self.prompt() error = None if cmds == "credits": self.insert('insert',"Thanks to Reddit, Youtube and other online sources for supporting Dip's development. See www.dip.org for more information.\n") self.prompt() error = None if cmds == "about": self.insert('insert', """ Dip was created in 2020 by Raghav Nautiyal while he was a student in High School in India, as a language similar to Python but aimed at beginners. (Hence the recursive name - Dip Isn't Python). Raghav remains Dip's principal author, although it includes many contributions from others.\n""") self.prompt() error = None if cmds == "exit": self.insert('insert',"Use exit() or Ctrl-C to exit\n") self.prompt() error = None if cmds == "exit()": exit() if error: self.insert('insert', '\n') error_as_string = error.as_string() bear = """\n .------. ( ) .. `------' .' / O / ; o i OO C `-. | <-' ( ,--. V \_) \ : `._\. \n""" self.insert('insert', error_as_string) self.insert('insert', f'{bear}\n') self.insert('insert', '\n') self.prompt() result.elements += dt.toprint for i in dt.toprint: self.insert('insert', f'{i}\n') for i in result.elements: print(i) if i == "": continue elif type(i) == list: if "input" in i: answer = askinput(i[1]) self.insert('insert', f'{answer}\n') continue if "inputint" in i: answer = askinputint(i[1]) self.insert('insert', f'{answer}\n') continue if "say" in i: say(i[1]) continue if i in dt.toprint: continue self.insert('insert', f'{i}\n') self.prompt() dt.toprint = [] dt.veryimp = 0 #print(insert) #print(toinsert) #self.insert('insert', f"{result}\n") #self.prompt() #dt.toprint = [] #dt.veryimp = 0 else: self.insert('insert', '\n') self.prompt()