pijul nest
guest [sign in]

Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

main.rs
use nom::{
    character::complete::{digit1, one_of},
    IResult,
};
use rustyline::{
    error::ReadlineError::{Eof, Interrupted},
    Editor,
};

fn number(input: &str) -> IResult<&str, &str> {
    digit1(input)
}

fn operator(input: &str) -> IResult<&str, char> {
    one_of("+-*/")(input)
}

fn main() -> std::io::Result<()> {
    let mut rl = Editor::<()>::new();
    if let Err(_) = rl.load_history("history.txt") {
        println!("Previous history was not loaded.");
    }
    Ok(loop {
        let readline = rl.readline("Ferencz> ");
        match readline {
            Ok(line) => {
                rl.add_history_entry(&line);
                println!("Line: {}", line);
            }
            Err(Interrupted) => {
                println!("CTRL-C");
                break;
            }
            Err(Eof) => {
                println!("CTRL-D");
                break;
            }
            Err(err) => {
                println!("Error: {:}", err);
                break;
            }
        }
    })
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test() {
        assert_eq!(number("23"), Ok(("", "23")));
    }
}