Skip to content

Commit

Permalink
cli: Improve REPL UX.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wafelack committed Sep 25, 2021
1 parent 5f4ca39 commit 25a7ea1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ impl Lexer {
builtins: vec![],
}
}
pub fn line(self, line: usize) -> Self {
Self {
input: self.input,
output: self.output,
current: self.current,
line,
start: self.start,
file: self.file,
builtins: self.builtins,
}
}
fn is_at_end(&self) -> bool {
self.current >= self.input.chars().count()
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ fn repl(no_prelude: bool, debug: bool, quiet: bool) -> Result<()> {
// let mut interpreter = Interpreter::new(vec![], no_prelude, quiet)?;

let mut rl = Editor::<()>::new();
let mut i = 0;

loop {
i += 1;
let line = rl.readline("orion> ");

match line {
Expand All @@ -105,7 +107,7 @@ fn repl(no_prelude: bool, debug: bool, quiet: bool) -> Result<()> {
return Ok(());
}

let tokens = match Lexer::new(line.trim(), "REPL").proc_tokens() {
let tokens = match Lexer::new(line.trim(), "REPL").line(i).proc_tokens() {
Ok(t) => t,
Err(e) => {
print_err(e);
Expand Down

0 comments on commit 25a7ea1

Please sign in to comment.