def _parse_plot(self, lineno, linesplit_space): """ @plot expr {mpl_prop} """ cmd = linesplit_space[0] if len(linesplit_space) == 1: # @plot raise ParseException(lineno, f"Invalid {cmd} command.") expr0, mpl_prop = ParseUtil.get_ending_dict(linesplit_space[1]) if mpl_prop is None: mpl_prop = dict() expr = expr0 all_stimulus_elements = self.parameters.get(kw.STIMULUS_ELEMENTS) all_behaviors = self.parameters.get(kw.BEHAVIORS) err = None if cmd == kw.VPLOT: expr, err = ParseUtil.parse_element_behavior( expr0, all_stimulus_elements, all_behaviors) elif cmd == kw.VSSPLOT: expr, err = ParseUtil.parse_element_element( expr0, all_stimulus_elements) elif cmd == kw.PPLOT: stimulus, behavior, err = ParseUtil.parse_stimulus_behavior( expr0, all_stimulus_elements, all_behaviors, self.variables) expr = (stimulus, behavior) elif cmd == kw.NPLOT: expr, err = ParseUtil.parse_chain(expr0, all_stimulus_elements, all_behaviors) if err: raise ParseException(lineno, err) return expr, mpl_prop, expr0
def _parse_export(self, lineno, linesplit_space): """ @export expr @export expr filename @hexport @hexport filename """ cmd = linesplit_space[0] filename_param = self.parameters.get(kw.FILENAME) if cmd == kw.HEXPORT: if len(linesplit_space) == 1: # @hexport if len(filename_param) == 0: raise ParseException(lineno, f"Invalid {cmd} command.") else: filename = filename_param else: # @hexport filename filename = linesplit_space[1] return None, filename, None if len(linesplit_space) == 1: # @export raise ParseException(lineno, f"Invalid {cmd} command.") args = linesplit_space[1] expr0, filename = ParseUtil.split1_strip(args) expr = expr0 if filename is None: if len(filename_param) == 0: raise ParseException(lineno, f"No filename given to {cmd}.") else: filename = filename_param all_stimulus_elements = self.parameters.get(kw.STIMULUS_ELEMENTS) all_behaviors = self.parameters.get(kw.BEHAVIORS) err = None if cmd == kw.VEXPORT: expr, err = ParseUtil.parse_element_behavior( expr0, all_stimulus_elements, all_behaviors) elif cmd == kw.VSSEXPORT: expr, err = ParseUtil.parse_element_element( expr0, all_stimulus_elements) elif cmd == kw.PEXPORT: stimulus, behavior, err = ParseUtil.parse_stimulus_behavior( expr0, all_stimulus_elements, all_behaviors, self.variables) expr = (stimulus, behavior) elif cmd == kw.NEXPORT: expr, err = ParseUtil.parse_chain(expr0, all_stimulus_elements, all_behaviors) if err: raise ParseException(lineno, err) return expr, filename, expr0
def _parse_xscale(self, xscale, phases): if not self.val[kw.STIMULUS_ELEMENTS]: return f"The parameter 'stimulus_elements' must be assigned before the parameter '{kw.XSCALE}'." if not self.val[kw.BEHAVIORS] and self.val[kw.MECHANISM_NAME] != mn.RW: return f"The parameter 'behaviors' must be assigned before the parameter '{kw.XSCALE}'." if phases.is_phase_label(xscale): pass elif xscale == 'all': pass else: xscale, err = ParseUtil.parse_chain(xscale, self.val[kw.STIMULUS_ELEMENTS], self.val[kw.BEHAVIORS]) if err: return err self.val[kw.XSCALE] = xscale return None