mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Show line numbers for ucg statements in the repl.
This commit is contained in:
parent
f81eb95e9a
commit
fc9595ab38
@ -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
|
||||||
|
@ -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()))?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user