pub fn run(color: ColorChoice, opts: &Opts) -> Result<(), Error> {
    let interface = Interface::new("repl")?;
    let mut codemap = CodeMap::new();
    let writer = StandardStream::stderr(color);
    let mut context = Context::default();
    let mut desugar_env = DesugarEnv::new(context.mappings());

    interface.set_prompt(&opts.prompt)?;
    interface.set_report_signal(Signal::Interrupt, true);
    interface.set_report_signal(Signal::Quit, true);

    if !opts.no_history && interface.load_history(&opts.history_file).is_err() {
        // No previous REPL history!
    }

    if !opts.no_banner {
        print_welcome_banner();
    }

    // TODO: Load files

    loop {
        match interface.read_line()? {
            ReadResult::Input(line) => {
                if !opts.no_history && !line.trim().is_empty() {
                    interface.add_history_unique(line.clone());
                }

                let filename = FileName::virtual_("repl");
                match eval_print(
                    &mut desugar_env,
                    &mut context,
                    &codemap.add_filemap(filename, line),
                ) {
                    Ok(ControlFlow::Continue) => {},
                    Ok(ControlFlow::Break) => break,
                    Err(EvalPrintError::Parse(errs)) => {
                        for err in errs {
                            let diagnostic = err.to_diagnostic();
                            codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                        }
                    },
                    Err(EvalPrintError::Desugar(err)) => {
                        let diagnostic = err.to_diagnostic();
                        codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                    },
                    Err(EvalPrintError::Type(err)) => {
                        let diagnostic = err.to_diagnostic();
                        codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                    },
                }
            },
            ReadResult::Signal(Signal::Quit) | ReadResult::Eof => break,
            ReadResult::Signal(Signal::Interrupt) => println!("Interrupt"),
            ReadResult::Signal(_) => {},
        }
    }

    if !opts.no_history {
        interface.save_history(&opts.history_file)?;
    }

    println!("Bye bye");

    Ok(())
}
/// Run the `repl` subcommand with the given options
Run the `repl` subcommand with the given options
Run the ` repl ` subcommand with the given options
pub fn run(color: ColorChoice, opts: &Opts) -> Result<(), Error> {
    let interface = Interface::new("repl")?;
    let mut codemap = CodeMap::new();
    let writer = StandardStream::stderr(color);
    let mut context = Context::default();
    let mut desugar_env = DesugarEnv::new(context.mappings());
    interface.set_prompt(&opts.prompt)?;
    interface.set_report_signal(Signal::Interrupt, true);
    interface.set_report_signal(Signal::Quit, true);
    if !opts.no_history && interface.load_history(&opts.history_file).is_err() {
        // No previous REPL history!
    }
    if !opts.no_banner {
        print_welcome_banner();
    }
    // TODO: Load files
    loop {
        match interface.read_line()? {
            ReadResult::Input(line) => {
                if !opts.no_history && !line.trim().is_empty() {
                    interface.add_history_unique(line.clone());
                }
                let filename = FileName::virtual_("repl");
                match eval_print(
                    &mut desugar_env,
                    &mut context,
                    &codemap.add_filemap(filename, line),
                ) {
                    Ok(ControlFlow::Continue) => {},
                    Ok(ControlFlow::Break) => break,
                    Err(EvalPrintError::Parse(errs)) => {
                        for err in errs {
                            let diagnostic = err.to_diagnostic();
                            codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                        }
                    },
                    Err(EvalPrintError::Desugar(err)) => {
                        let diagnostic = err.to_diagnostic();
                        codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                    },
                    Err(EvalPrintError::Type(err)) => {
                        let diagnostic = err.to_diagnostic();
                        codespan_reporting::emit(&mut writer.lock(), &codemap, &diagnostic)?;
                    },
                }
            },
            ReadResult::Signal(Signal::Quit) | ReadResult::Eof => break,
            ReadResult::Signal(Signal::Interrupt) => println!("Interrupt"),
            ReadResult::Signal(_) => {},
        }
    }
    if !opts.no_history {
        interface.save_history(&opts.history_file)?;
    }
    println!("Bye bye");
    Ok(())
}
pub fn run ( color : ColorChoice , opts : & Opts ) -> Result < ( ) , Error > { let interface = Interface :: new ( " " ) ? ; let mut codemap = CodeMap :: new ( ) ; let writer = StandardStream :: stderr ( color ) ; let mut context = Context :: default ( ) ; let mut desugar_env = DesugarEnv :: new ( context . mappings ( ) ) ; interface . set_prompt ( & opts . prompt ) ? ; interface . set_report_signal ( Signal :: Interrupt , true ) ; interface . set_report_signal ( Signal :: Quit , true ) ; if ! opts . no_history && interface . load_history ( & opts . history_file ) . is_err ( ) { // No previous REPL history! } if ! opts . no_banner { print_welcome_banner ( ) ; } // TODO: Load files loop { match interface . read_line ( ) ? { ReadResult :: Input ( line ) => { if ! opts . no_history && ! line . trim ( ) . is_empty ( ) { interface . add_history_unique ( line . clone ( ) ) ; } let filename = FileName :: virtual_ ( " " ) ; match eval_print ( & mut desugar_env , & mut context , & codemap . add_filemap ( filename , line ) , ) { Ok ( ControlFlow :: Continue ) => { } , Ok ( ControlFlow :: Break ) => break , Err ( EvalPrintError :: Parse ( errs ) ) => { for err in errs { let diagnostic = err . to_diagnostic ( ) ; codespan_reporting :: emit ( & mut writer . lock ( ) , & codemap , & diagnostic ) ? ; } } , Err ( EvalPrintError :: Desugar ( err ) ) => { let diagnostic = err . to_diagnostic ( ) ; codespan_reporting :: emit ( & mut writer . lock ( ) , & codemap , & diagnostic ) ? ; } , Err ( EvalPrintError :: Type ( err ) ) => { let diagnostic = err . to_diagnostic ( ) ; codespan_reporting :: emit ( & mut writer . lock ( ) , & codemap , & diagnostic ) ? ; } , } } , ReadResult :: Signal ( Signal :: Quit ) | ReadResult :: Eof => break , ReadResult :: Signal ( Signal :: Interrupt ) => println ! ( " " ) , ReadResult :: Signal ( _ ) => { } , } } if ! opts . no_history { interface . save_history ( & opts . history_file ) ? ; } println ! ( " " ) ; Ok ( ( ) ) }
Run the `repl` subcommand with the given options
Run the ` repl ` subcommand with the given options
color
ColorChoice
opts
&Opts
color
ColorChoice
opts
&Opts