FEATURE: Show line numbers for ucg statements in the repl.

This commit is contained in:
Jeremy Wall 2019-05-28 18:06:23 -05:00
parent f81eb95e9a
commit fc9595ab38
2 changed files with 8 additions and 2 deletions

View File

@ -24,6 +24,10 @@ impl StatementAccumulator {
Self { acc: Vec::new() } Self { acc: Vec::new() }
} }
pub fn next_line(&self) -> usize {
self.acc.len() + 1
}
/// Tells you if the latest line ends in the statement terminator. /// Tells you if the latest line ends in the statement terminator.
/// ///
/// Returns None if it wasn't a terminated statement and leaves the /// Returns None if it wasn't a terminated statement and leaves the

View File

@ -551,9 +551,11 @@ fn do_repl(
let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, cache); let mut builder = build::FileBuilder::new(std::env::current_dir()?, import_paths, cache);
// loop // loop
let mut lines = ucglib::io::StatementAccumulator::new(); let mut lines = ucglib::io::StatementAccumulator::new();
println!("Welcome to the UCG repl. Ctrl-D to exit");
println!("");
loop { loop {
// print prompt // print prompt
lines.push(editor.readline("ucg> ")?); lines.push(editor.readline(&format!("{}> ", lines.next_line()))?);
// check to see if that line is a statement // check to see if that line is a statement
loop { loop {
// read a statement // read a statement
@ -573,7 +575,7 @@ fn do_repl(
break; break;
} }
// if not then keep accumulating lines without a prompt // if not then keep accumulating lines without a prompt
lines.push(editor.readline(">> ")?); lines.push(editor.readline(&format!("{}> ", lines.next_line()))?);
} }
} }
} }