You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
885 B

  1. mod execute;
  2. mod parse;
  3. mod prompt;
  4. use execute::interpret;
  5. use rustyline::error::ReadlineError;
  6. use rustyline::{Editor, Result};
  7. use crate::prompt::Prompt;
  8. fn main() -> Result<()> {
  9. let mut rl = Editor::<()>::new()?;
  10. let mut prompt = Prompt::new();
  11. loop {
  12. let readline = rl.readline(&prompt.get_prompt());
  13. match readline {
  14. Ok(line) => {
  15. if let Err(err) = interpret(&line) {
  16. println!("{}", err);
  17. }
  18. }
  19. Err(ReadlineError::Interrupted) => {
  20. println!("CTRL-C");
  21. break;
  22. }
  23. Err(ReadlineError::Eof) => {
  24. println!("CTRL-D");
  25. break;
  26. }
  27. Err(err) => {
  28. println!("Error: {:?}", err);
  29. break;
  30. }
  31. }
  32. }
  33. Ok(())
  34. }