From ab149ce010eccf74c04111df556bccffb3b08349 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 3 Jan 2024 15:25:53 -0500 Subject: [PATCH] Fix CLI error and example --- examples/async.ds | 2 +- src/main.rs | 13 ++++++++++--- test.ds | 2 -- 3 files changed, 11 insertions(+), 6 deletions(-) delete mode 100644 test.ds diff --git a/examples/async.ds b/examples/async.ds index 18b9236..b4097fe 100644 --- a/examples/async.ds +++ b/examples/async.ds @@ -2,7 +2,7 @@ create_random_numbers = (count ) { numbers = [] while length(numbers) < count { - numbers += random_integer() + numbers += random:integer() } output("Made " + length(numbers) + " numbers.") diff --git a/src/main.rs b/src/main.rs index 9e56785..4146fd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use tree_sitter::Parser as TSParser; use std::{borrow::Cow, fs::read_to_string}; -use dust_lang::{interpret_with_context, language, Interpreter, Map, Value}; +use dust_lang::{language, Interpreter, Map, Value}; /// Command-line arguments to be parsed. #[derive(Parser, Debug)] @@ -169,7 +169,9 @@ impl Highlighter for DustReadline { fn run_cli_shell() { let context = Map::new(); + let mut interpreter = Interpreter::new(context); let mut rl: Editor = Editor::new().unwrap(); + let mut input = String::new(); rl.set_helper(Some(DustReadline::new())); @@ -183,13 +185,18 @@ fn run_cli_shell() { Ok(line) => { let line = line.as_str(); + input.push('\n'); + input.push_str(line); rl.add_history_entry(line).unwrap(); - let eval_result = interpret_with_context(line, context.clone()); + let eval_result = interpreter.run(&input); match eval_result { Ok(value) => println!("{value}"), - Err(error) => eprintln!("{error}"), + Err(error) => { + input = input.trim_end_matches(line).to_string(); + eprintln!("{error}") + } } } Err(ReadlineError::Interrupted) => break, diff --git a/test.ds b/test.ds deleted file mode 100644 index 0333dbc..0000000 --- a/test.ds +++ /dev/null @@ -1,2 +0,0 @@ -fn = (x ) {} -fn(1)