You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: input.rs
    path of file: ./repos/rusti/src/rusti
    
    the code of the file until where you have to start completion: // Copyright 2014-2016 Rusti Project
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Parsing REPL input statements, including Rust code and `rusti` commands.

use std::borrow::Cow;
use std::borrow::Cow::*;
use std::fs::File;
use std::io::{self, stdin, BufRead, BufReader};
use std::mem::swap;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::sync::mpsc::channel;
use std::thread::Builder;

use syntax::ast::{ItemKind, MacStmtStyle, StmtKind};
use syntax::codemap::{BytePos, CodeMap};
use syntax::errors::{ColorConfig, DiagnosticBuilder, Handler};
use syntax::errors::emitter::{Emitter, Emitt
    
pub fn parse_program(code: &str, filter: bool, filename: Option<&str>) -> InputResult {
    let err = Arc::new(Mutex::new(ErrorState::Success));
    let (tx, rx) = channel();

    let task = Builder::new().name("parse_program".to_owned());

    // Items are not returned in data structures; nor are they converted back
    // into strings. Instead, to preserve user input formatting, we use
    // byte offsets to return the input as it was received.
    fn slice(s: &str, lo: BytePos, hi: BytePos) -> String {
        s[lo.0 as usize .. hi.0 as usize].to_owned()
    }

    let code = code.to_owned();
    let filename = filename.unwrap_or("<input>").to_owned();
    let em_err = err.clone();

    let handle = task.spawn(move || {
        if !log_enabled!(::log::LogLevel::Debug) {
            io::set_panic(Box::new(io::sink()));
        }
        let mut input = Input::new();
        let cm = Rc::new(CodeMap::new());
        let handler = Handler::with_emitter(false, false,
            Box::new(ErrorEmitter::new(cm.clone(), em_err.clone(), filter)));
        let sess = ParseSess::with_span_handler(handler, cm);

        let mut p = filemap_to_parser(&sess,
            sess.codemap().new_filemap(filename, None, code.clone()),
            Vec::new());

        // Whether the last statement is an expression without a semicolon
        let mut last_expr = false;

        while p.token != token::Eof {
            if let token::DocComment(_) = p.token {
                p.bump();
                continue;
            }

            let lo = p.span.lo;

            if p.token == token::Pound {
                if p.look_ahead(1, |t| *t == token::Not) {
                    try_parse!(p.parse_attribute(true));
                    input.attributes.push(slice(&code, lo, p.last_span.hi));
                    continue;
                }
            }

            let stmt = match try_parse!(p.parse_stmt()) {
                None => break,
                Some(stmt) => stmt,
            };

            {
                let lock = em_err.lock().unwrap();

                if *lock != ErrorState::Success {
                    return;
                }
            }

            let mut hi = None;

            last_expr = match stmt.node {
                StmtKind::Expr(ref e) => {
                    if classify::expr_requires_semi_to_be_stmt(&**e) {
                        try_parse!(p.expect_one_of(&[], &[token::Semi, token::Eof]));
                    }
                    !p.eat(&token::Semi)
                }
                StmtKind::Mac(ref mac) if mac.1 == MacStmtStyle::NoBraces => {
                    try_parse!(p.expect_one_of(&[], &[token::Semi, token::Eof]));
                    !p.eat(&token::Semi)
                }
                StmtKind::Mac(_) => false,
                StmtKind::Local(_) => {
                    try_parse!(p.expect(&token::Semi));
                    false
                }
                StmtKind::Item(_) => {
                    // Consume the semicolon if there is one,
                    // but don't add it to the item
                    hi = Some(p.last_span.hi);
                    p.eat(&token::Semi);
                    false
                }
                _ => false
            };

            let dest = match stmt.node {
                StmtKind::Local(..) => &mut input.statements,
                StmtKind::Item(ref item) => {
                    match item.node {
                        ItemKind::ExternCrate(..) | ItemKind::Use(..) =>
                            &mut input.view_items,
                        _ => &mut input.items,
                    }
                },
                StmtKind::Mac(ref mac) if mac.1 == MacStmtStyle::Braces =>
                    &mut input.items,
                _ => &mut input.statements,
            };

            dest.push(slice(&code, lo, hi.unwrap_or(p.last_span.hi)));
        }

        input.last_expr = last_expr;

        tx.send(input).unwrap();
    }).unwrap();

    let _ = handle.join();

    let lock = err.lock().unwrap();

    match *lock {
        ErrorState::Success => Program(rx.recv().unwrap()),
        ErrorState::Fatal => InputError(None),
        ErrorState::NonFatal => More
    }
}