Skip to content

Splat arbitrary number of strings into Vec<String> #6

@femtomc

Description

@femtomc

Hi @jedrzejboczar! I'm using easy-repl as a front end to a REPL for a language, but I'm having difficulties passing the full string to my parser/interpreter.

I tried the following:

fn main() {
    let mut repl = Repl::builder().add(":e", command! {
        "Evaluate an expression using the interpreter.",
        (raw: Vec<String>) => |raw: Vec<String>| {
            let expr = raw.join(" ");
            match libstachio::run_program(expr.as_str()) {
                Ok(v) => println!("{}", libstachio::unspan(v)),
                Err(reports) => libstachio::print_reports(expr.as_str(), reports),
            };
            Ok(CommandStatus::Done)
        }
    }).build().expect("Failed to create REPL.");
    repl.run().expect("Critical REPL error.");
}

But this doesn't work -- is there an idiom that will allow me to get the entire input after the command :e as a String or a Vec<String> all together?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions