summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 12:49:50 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 13:18:32 +0200
commitf9005692a1e2dba89274f39df762fdcfa59b739b (patch)
tree4e3c8e8b4e5fd9565dfd348f0199cec2bfb7649b /crates
parent6d09f6c30d05a8da65fdfc7be8ccb11ee069eb2b (diff)
downloadrebel-f9005692a1e2dba89274f39df762fdcfa59b739b.tar
rebel-f9005692a1e2dba89274f39df762fdcfa59b739b.zip
rebel-lang: repl: switch from rustyline to reedline
reedline has a nicer API than rustyline.
Diffstat (limited to 'crates')
-rw-r--r--crates/rebel-lang/Cargo.toml2
-rw-r--r--crates/rebel-lang/examples/repl.rs43
2 files changed, 17 insertions, 28 deletions
diff --git a/crates/rebel-lang/Cargo.toml b/crates/rebel-lang/Cargo.toml
index 957d31d..6601c8e 100644
--- a/crates/rebel-lang/Cargo.toml
+++ b/crates/rebel-lang/Cargo.toml
@@ -15,4 +15,4 @@ enum-kinds = "0.5.1"
[dev-dependencies]
clap = { version = "4.0.0", features = ["derive"] }
-rustyline = { version = "14.0.0", features = ["derive"] }
+reedline = "0.31.0"
diff --git a/crates/rebel-lang/examples/repl.rs b/crates/rebel-lang/examples/repl.rs
index 185155b..4a7b755 100644
--- a/crates/rebel-lang/examples/repl.rs
+++ b/crates/rebel-lang/examples/repl.rs
@@ -5,7 +5,7 @@ use rebel_lang::{
value::{EvalError, Result, Value},
};
use rebel_parse::{recipe, tokenize};
-use rustyline::{error::ReadlineError, validate::ValidationResult};
+use reedline::{DefaultPrompt, DefaultPromptSegment, Reedline, Signal, ValidationResult};
fn intrinsic_array_len(params: &[Value]) -> Result<Value> {
assert!(params.len() == 1);
@@ -24,25 +24,19 @@ fn intrinsic_string_len(params: &[Value]) -> Result<Value> {
))
}
-#[derive(rustyline::Completer, rustyline::Hinter, rustyline::Highlighter, rustyline::Helper)]
-struct Helper;
+struct Validator;
-impl rustyline::validate::Validator for Helper {
- fn validate(
- &self,
- ctx: &mut rustyline::validate::ValidationContext,
- ) -> rustyline::Result<rustyline::validate::ValidationResult> {
- let input = ctx.input();
- let result = match tokenize::token_stream(input) {
- Ok(_) => ValidationResult::Valid(None),
- Err(_) => ValidationResult::Incomplete,
- };
-
- Ok(result)
+impl reedline::Validator for Validator {
+ fn validate(&self, line: &str) -> ValidationResult {
+ if tokenize::token_stream(line).is_ok() {
+ ValidationResult::Complete
+ } else {
+ ValidationResult::Incomplete
+ }
}
}
-fn main() -> rustyline::Result<()> {
+fn main() {
let mut ctx = Context::default();
ctx.methods.entry(TypeFamily::Array).or_default().insert(
@@ -66,18 +60,15 @@ fn main() -> rustyline::Result<()> {
},
);
- let mut rl = rustyline::Editor::<Helper, rustyline::history::DefaultHistory>::new()?;
- rl.set_helper(Some(Helper));
+ let mut rl = Reedline::create().with_validator(Box::new(Validator));
+ let prompt = DefaultPrompt::new(DefaultPromptSegment::Empty, DefaultPromptSegment::Empty);
loop {
- let input = match rl.readline("> ") {
- Ok(input) => input,
- Err(ReadlineError::Interrupted) => continue,
- Err(ReadlineError::WindowResized) => continue,
- Err(ReadlineError::Eof) => break,
- Err(err) => panic!("{err}"),
+ let input = match rl.read_line(&prompt).unwrap() {
+ Signal::Success(input) => input,
+ Signal::CtrlC => continue,
+ Signal::CtrlD => break,
};
- rl.add_history_entry(input.as_str())?;
let tokens = match tokenize::token_stream(&input) {
Ok(value) => value,
@@ -146,6 +137,4 @@ fn main() -> rustyline::Result<()> {
};
println!("{value}: {typ}");
}
-
- Ok(())
}