コード例 #1
0
ファイル: test_lib.py プロジェクト: shamrin/oil
def InitWordEvaluator():
    arena = MakeArena('<InitWordEvaluator>')
    mem = state.Mem('', [], arena, [])
    state.InitMem(mem, {})

    opt_array = [False] * option_i.ARRAY_SIZE
    errexit = state._ErrExit()
    parse_opts = optview.Parse(opt_array)
    exec_opts = optview.Exec(opt_array, errexit)
    mem.exec_opts = exec_opts  # circular dep

    exec_deps = cmd_exec.Deps()
    exec_deps.trap_nodes = []

    splitter = split.SplitContext(mem)
    errfmt = ui.ErrorFormatter(arena)

    ev = word_eval.CompletionWordEvaluator(mem, exec_opts, splitter, errfmt)
    return ev
コード例 #2
0
ファイル: process_test.py プロジェクト: grahamc/oil

def Banner(msg):
  print('-' * 60)
  print(msg)


# TODO: Put these all in a function.
_ARENA = test_lib.MakeArena('process_test.py')

_MEM = state.Mem('', [], _ARENA, [])
state.InitMem(_MEM, {}, '0.1')

_OPT_ARRAY = [False] * option_i.ARRAY_SIZE
_PARSE_OPTS = optview.Parse(_OPT_ARRAY)
_ERREXIT = state._ErrExit()
_EXEC_OPTS = state.MutableOpts(_MEM, _OPT_ARRAY, _ERREXIT, None)
_JOB_STATE = process.JobState()
_WAITER = process.Waiter(_JOB_STATE, _EXEC_OPTS)
_ERRFMT = ui.ErrorFormatter(_ARENA)
_FD_STATE = process.FdState(_ERRFMT, _JOB_STATE)
_EXT_PROG = process.ExternalProgram('', _FD_STATE, _ERRFMT,
                                    util.NullDebugFile())


def _CommandNode(code_str, arena):
  c_parser = test_lib.InitCommandParser(code_str, arena=arena)
  return c_parser.ParseLogicalLine()


def _ExtProc(argv):
コード例 #3
0
ファイル: test_lib.py プロジェクト: shamrin/oil
def InitExecutor(parse_ctx=None,
                 comp_lookup=None,
                 arena=None,
                 mem=None,
                 aliases=None,
                 ext_prog=None):
    opt_array = [False] * option_i.ARRAY_SIZE
    if parse_ctx:
        arena = parse_ctx.arena
        parse_opts = parse_ctx.parse_opts
    else:
        parse_ctx = InitParseContext()

    mem = mem or state.Mem('', [], arena, [])
    state.InitMem(mem, {})
    errexit = state._ErrExit()
    exec_opts = optview.Exec(opt_array, errexit)
    mutable_opts = state.MutableOpts(mem, opt_array, errexit, None)
    # No 'readline' in the tests.

    errfmt = ui.ErrorFormatter(arena)
    job_state = process.JobState()
    fd_state = process.FdState(errfmt, job_state)
    funcs = {}
    aliases = {} if aliases is None else aliases

    compopt_state = completion.OptionState()
    comp_lookup = comp_lookup or completion.Lookup()

    readline = None  # simulate not having it
    new_var = builtin_assign.NewVar(mem, funcs, errfmt)
    builtins = {  # Lookup
        builtin_i.echo: builtin_pure.Echo(exec_opts),
        builtin_i.shift: builtin_assign.Shift(mem),

        builtin_i.history: builtin_misc.History(readline),

        builtin_i.compopt: builtin_comp.CompOpt(compopt_state, errfmt),
        builtin_i.compadjust: builtin_comp.CompAdjust(mem),

        builtin_i.alias: builtin_pure.Alias(aliases, errfmt),
        builtin_i.unalias: builtin_pure.UnAlias(aliases, errfmt),

        builtin_i.declare: new_var,
        builtin_i.typeset: new_var,
        builtin_i.local: new_var,

        builtin_i.export_: builtin_assign.Export(mem, errfmt),
        builtin_i.readonly: builtin_assign.Readonly(mem, errfmt),
    }

    debug_f = util.DebugFile(sys.stderr)
    exec_deps = cmd_exec.Deps()
    exec_deps.mutable_opts = state.MutableOpts(mem, opt_array, errexit, None)
    exec_deps.search_path = state.SearchPath(mem)
    exec_deps.errfmt = errfmt
    exec_deps.trap_nodes = []
    exec_deps.job_state = job_state
    exec_deps.waiter = process.Waiter(exec_deps.job_state, exec_opts)

    exec_deps.ext_prog = \
        ext_prog or process.ExternalProgram('', fd_state,
                                            exec_deps.search_path, errfmt,
                                            debug_f)

    exec_deps.dumper = dev.CrashDumper('')
    exec_deps.debug_f = debug_f
    exec_deps.trace_f = debug_f

    splitter = split.SplitContext(mem)

    procs = {}

    arith_ev = sh_expr_eval.ArithEvaluator(mem, exec_opts, errfmt)
    bool_ev = sh_expr_eval.BoolEvaluator(mem, exec_opts, errfmt)
    expr_ev = expr_eval.OilEvaluator(mem, procs, errfmt)
    word_ev = word_eval.NormalWordEvaluator(mem, exec_opts, splitter, errfmt)
    ex = cmd_exec.Executor(mem, fd_state, funcs, builtins, exec_opts,
                           parse_ctx, exec_deps)
    assert ex.mutable_opts is not None, ex
    prompt_ev = prompt.Evaluator('osh', parse_ctx, mem)
    tracer = dev.Tracer(parse_ctx, exec_opts, mutable_opts, mem, word_ev,
                        debug_f)

    vm.InitCircularDeps(arith_ev, bool_ev, expr_ev, word_ev, ex, prompt_ev,
                        tracer)

    spec_builder = builtin_comp.SpecBuilder(ex, parse_ctx, word_ev, splitter,
                                            comp_lookup)
    # Add some builtins that depend on the executor!
    complete_builtin = builtin_comp.Complete(spec_builder, comp_lookup)
    builtins[builtin_i.complete] = complete_builtin
    builtins[builtin_i.compgen] = builtin_comp.CompGen(spec_builder)

    return ex