def candidates(self, line, text): candidates = None debug(f'complete: line={line}, text=<{text}>') if len(line.strip()) == 0: candidates = TabCompleter.OPS else: # Parse the text so far, to get information needed for tab completion. It is expected that # the text will end early, since we are doing tab completion here. This results in a PrematureEndError # which can be ignored. The important point is that the parse will set Parser.op. parser = marcel.parser.Parser(line, self.main) try: parser.parse() debug( f'parse succeeded, context: {parser.tab_completion_context}' ) except Exception as e: debug(f'caught {type(e)}: {e}') # Don't do tab completion candidates = None return except marcel.exception.KillCommandException as e: # Parse may have failed because of an unrecognized op, for example. Normal continuation should # do the right thing. debug(f'Caught KillCommandException: {e}') except BaseException as e: debug(f'Something went really wrong: {e}') marcel.util.print_stack() context = parser.tab_completion_context if context.is_complete_op(): op = context.op() if op is None: # Could be a partial op name, an executable name (or partial), or just gibberish candidates = self.complete_op(text) elif op.op_name() == 'help': candidates = self.complete_help(text) else: # Could be a partial op name, an executable name (or partial), or just gibberish candidates = self.complete_op(text) elif context.is_complete_arg(): if len(text) == 0: candidates = self.complete_filename(text) elif text[-1].isspace(): text = '' candidates = self.complete_filename(text) elif text.startswith('-'): candidates = self.complete_flag(text, context.flags()) else: candidates = self.complete_filename(text) return candidates
def candidates(self, line, text): debug(f'complete: line={line}, text={text}') if len(line.strip()) == 0: candidates = TabCompleter.OPS else: # Parse the text so far, to get information needed for tab completion. It is expected that # the text will end early, since we are doing tab completion here. This results in a PrematureEndError # which can be ignored. The important point is that the parse will set Parser.op. parser = marcel.parser.Parser(line, self.main) try: parser.parse() debug('parse succeeded') except Exception as e: debug(f'caught ({type(e)}) {e}') # Don't do tab completion return None except marcel.exception.KillCommandException as e: # Parse may have failed because of an unrecognized op, for example. Normal continuation should # do the right thing. pass except BaseException as e: debug(f'Something went really wrong: {e}') marcel.util.print_stack() current_op = parser.current_op assert current_op is not None debug(f'current_op: {current_op}') if not current_op.processing_args: op = current_op.op if op is None: # Could be a partial op name, an executable name (or partial), or just gibberish candidates = self.complete_op(text) elif op.op_name() == 'help': candidates = self.complete_help(text) else: assert op.op_name() == text, text # Op is complete candidates = [text + ' '] elif text.startswith('-'): candidates = self.complete_flag(text, parser.current_op.flags) else: candidates = self.complete_filename(text) return candidates
def run_command(self, line): if line: try: parser = marcel.parser.Parser(line, self) pipeline = parser.parse() pipeline.set_error_handler(Main.default_error_handler) # Append an out op at the end of pipeline, if there is no output op there already. if not pipeline.is_terminal_op('out'): pipeline.append(marcel.opmodule.create_op(self.env, 'out')) command = marcel.core.Command(line, pipeline) if self.run_immediate(pipeline): command.execute() else: self.job_control.create_job(command) except marcel.parser.EmptyCommand: pass except marcel.exception.KillCommandException as e: marcel.util.print_to_stderr(e, self.env) except marcel.exception.KillAndResumeException as e: # Error handler printed the error pass
def run_command(self, line): if line: try: parser = marcel.parser.Parser(line, self) pipeline = parser.parse() pipeline.set_error_handler(Main.default_error_handler) # self.run_immediate(pipeline) depends on whether the pipeline has a single op. # So check this before tacking on the out op. run_immediate = self.run_immediate(pipeline) # Append an out op at the end of pipeline, if there is no output op there already. if not pipeline.last_op().op_name() == 'out': pipeline.append(marcel.opmodule.create_op(self.env, 'out')) command = marcel.core.Command(self.env, line, pipeline) if run_immediate: command.execute() else: self.job_control.create_job(command) except marcel.parser.EmptyCommand: pass except marcel.exception.KillCommandException as e: marcel.util.print_to_stderr(e, self.env) except marcel.exception.KillAndResumeException: # Error handler printed the error pass
def test(text): parser = marcel.parser.Parser(text, MAIN.op_modules) pipeline = parser.parse() print(f'{text} ->\n{pipeline}')