def compile_coffee(code): try: interim = eval_coffee_footprint(code) if interim != None: interim = inter.cleanup_js(interim) interim = inter.add_names(interim) return (None, None, interim) else: return ('internal error', 'internal error', None) except JSError as ex: s = str(ex) s = s.replace('JSError: Error: ', '') return ('coffee error:\n' + s, s, None) except (ReferenceError, IndexError, AttributeError, SyntaxError, TypeError, NotImplementedError) as ex: print traceback.format_exc() return ('coffee error:\n' + str(ex), str(ex), None) except RuntimeError as ex: if str(ex) == 'maximum recursion depth exceeded while calling a Python object': msg = 'Error: please make sure your coffeescript does not contain self-referencing recursive elements because those can\'t be compiled into a result at the moment' else: tb = traceback.format_exc() msg = str(ex) + "\n"+tb return (msg, "", None) except Exception as ex: tb = traceback.format_exc() return ('other error:\n' + str(ex) + "\n"+tb, str(ex), None)
def compile(self): code = self.te1.toPlainText() compilation_failed_last_time = self.executed_footprint == [] self.executed_footprint = [] try: interim = pycoffee.eval_coffee_footprint(code) if interim != None: interim = inter.cleanup_js(interim) interim = inter.add_names(interim) self.executed_footprint = interim self.te2.setPlainText(str(interim)) if self.auto_zoom.isChecked(): (dx, dy, x1, y1, x2, y2) = inter.size(interim) self.update_zoom(dx, dy, x1, y1, x2, y2) filter_out = [] if not self.display_docu: filter_out.append('docu') if not self.display_restrict: filter_out.append('restrict') self.glw.set_shapes(inter.prepare_for_display(interim, filter_out)) if not self.is_fresh_from_file: with open(self.active_footprint_file(), "w+") as f: f.write(code) if compilation_failed_last_time: self.status("Compilation successful.") [s1, s2] = self.lsplitter.sizes() self.lsplitter.setSizes([s1+s2, 0]) # TODO: get rid of exception handling code duplication except pycoffee.JSError as ex: self.executed_footprint = [] s = str(ex) s = s.replace('JSError: Error: ', '') self.te2.setPlainText('coffee error:\n' + s) self.status(s) [s1, s2] = self.lsplitter.sizes() self.lsplitter.setSizes([s1+s2-150, 150]) except (ReferenceError, IndexError, AttributeError, SyntaxError, TypeError, NotImplementedError) as ex: self.executed_footprint = [] self.te2.setPlainText('coffee error:\n' + str(ex)) print traceback.format_exc() self.status(str(ex)) [s1, s2] = self.lsplitter.sizes() self.lsplitter.setSizes([s1+s2-150, 150]) except RuntimeError as ex: if str(ex) == 'maximum recursion depth exceeded while calling a Python object': msg = 'Error: please make sure your coffeescript does not contain self-referencing recursive elements because those can\'t be compiled into a result at the moment' else: tb = traceback.format_exc() msg = str(ex) + "\n"+tb self.executed_footprint = [] self.te2.setPlainText(msg) [s1, s2] = self.lsplitter.sizes() self.lsplitter.setSizes([s1+s2-150, 150]) except Exception as ex: self.executed_footprint = [] tb = traceback.format_exc() self.te2.setPlainText('other error:\n' + str(ex) + "\n"+tb) self.status(str(ex)) [s1, s2] = self.lsplitter.sizes() self.lsplitter.setSizes([s1+s2-150, 150])
def compile_coffee(code): try: preprocessed = preprocess_coffee(code) interim = eval_coffee_footprint(preprocessed) if interim != None: interim = inter.cleanup_js(interim) interim = inter.add_names(interim) return (None, None, interim) else: return ('internal error', 'internal error', None) except JsEngineException as ex: s = ex.getMessage() return ('coffee error:\n' + s, s, None) except Exception as ex: tb = traceback.format_exc() return ('other error:\n' + str(ex) + "\n"+tb, str(ex), None)