<commit_before>extern mod rusp;
extern mod extra;

// for a nicer prompt, with history etc.
use extra::rl;

fn main() {
    unsafe { do rl::complete |_line, _suggest| {} }

    let mut prompt = "> ";
    let mut stored = ~"";
    println("Rusp Repl");
    let env = rusp::Rusp::new();

    loop {
        let line = match unsafe { rl::read(prompt) } {
            Some(line) => line,
            None => break
        };

        if !stored.is_empty() { stored.push_char('\n'); }
        stored.push_str(line);
        unsafe { rl::add_history(line); }

        let continue_line = match rusp::parse(stored) {
            Ok(ex) => {
                // print the AST, since that's useful for debugging
                println(fmt!("AST: %?" ex));
                // separate, since this can make the REPL crash
                println(match env.eval(&ex) {
                    Ok(evaled) => evaled.to_str(),
                    Err(e) => {
                        fmt!("Error: %s", e)
                    }
                });
                false
            }
            Err(ref er) if er.description == ~"Unexpected EOF" => {
                // it's not invalid yet, just haven't got enough
                // input, so wait for more
                true
            }
            Err(ref er) => {
                // give a little caret pointing at the serror
                println(fmt!("%s^\nParse Error: %s",
                             str::repeat(" ", er.position.col - 1 + prompt.len()),
                             er.description));
                false
            }
        };

        prompt = if continue_line {
            "+ "
        } else {<commit_msg>Usability improvements to the repl, don't print () or the AST.<commit_after>extern mod rusp;
extern mod extra;

// for a nicer prompt, with history etc.
use extra::rl;

fn main() {
    unsafe { do rl::complete |_line, _suggest| {} }

    let mut prompt = "> ";
    let mut stored = ~"";
    println("Rusp Repl");
    let env = rusp::Rusp::new();

    loop {
        let line = match unsafe { rl::read(prompt) } {
            Some(line) => line,
            None => break
        };

        if !stored.is_empty() { stored.push_char('\n'); }
        else if line.is_empty() {
            // no input and no history
            loop;
        }
        stored.push_str(line);

        if !line.is_empty() {
            unsafe { rl::add_history(line); }
        }

        let continue_line = match rusp::parse(stored) {
            Ok(ex) => {
                let to_print = match env.eval(&ex) {
                    Ok(evaled) => evaled.to_str(),
                    Err(e) => {
                        fmt!("Error: %s", e)
                    }
                };

                if to_print != ~"()" {
                    println(to_print);
                }
                false
            }
            Err(ref er) if er.description == ~"Unexpected EOF" => {
                // it's not invalid yet, just haven't got enough
                // input, so wait for more
                true
            }
            Err(ref er) => {
                // give a little caret pointing at the serror
                println(fmt!("%s^\nParse Error: %s",
                             str::repeat(" ", er.position.col - 1 + prompt.len()),
                             er.description));
                false
            }
        };

        prompt = if continue_line {
            "+ "
        } else {
{'fraction_non_alphanumeric': 0.12834532374100718, 'fraction_numerical': 0.0005755395683453237, 'mean_word_length': 1.1930599369085173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6750900', 'n_tokens_mistral': 1008, 'n_tokens_neox': 933, 'n_words': 255}