diff --git a/Cargo.lock b/Cargo.lock index 8d1ca58a..e82e7fcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1855,7 +1855,6 @@ dependencies = [ "futures", "futures-util", "itertools 0.12.0", - "moor-kernel", "moor-values", "rpc-common", "rustyline", @@ -1998,7 +1997,6 @@ dependencies = [ "metrics-exporter-prometheus", "metrics-macros", "metrics-util", - "moor-kernel", "moor-values", "rpc-common", "strum", @@ -2050,7 +2048,6 @@ dependencies = [ "metrics-exporter-prometheus", "metrics-macros", "metrics-util", - "moor-kernel", "moor-values", "rpc-common", "serde", diff --git a/crates/console-host/Cargo.toml b/crates/console-host/Cargo.toml index 00e05c26..f48a039e 100644 --- a/crates/console-host/Cargo.toml +++ b/crates/console-host/Cargo.toml @@ -6,7 +6,6 @@ repository.workspace = true license.workspace = true [dependencies] -moor-kernel = { path = "../kernel" } moor-values = { path = "../values" } rpc-common = { path = "../rpc-common" } diff --git a/crates/daemon/src/rpc_server.rs b/crates/daemon/src/rpc_server.rs index cc98eac8..c34bc760 100644 --- a/crates/daemon/src/rpc_server.rs +++ b/crates/daemon/src/rpc_server.rs @@ -31,13 +31,13 @@ use tokio::sync::Mutex; use tracing::{debug, error, info, trace, warn}; use uuid::Uuid; -use moor_kernel::tasks::command_parse::parse_into_words; use moor_kernel::tasks::scheduler::{Scheduler, SchedulerError, TaskWaiterResult}; use moor_kernel::tasks::sessions::SessionError::DeliveryError; use moor_kernel::tasks::sessions::{Session, SessionError}; use moor_kernel::tasks::TaskId; use moor_values::model::world_state::WorldStateSource; use moor_values::model::NarrativeEvent; +use moor_values::util::parse_into_words; use moor_values::var::objid::Objid; use moor_values::var::variant::Variant; use moor_values::var::Var; diff --git a/crates/kernel/src/tasks/command_parse.rs b/crates/kernel/src/tasks/command_parse.rs index e22cd27e..a4a03902 100644 --- a/crates/kernel/src/tasks/command_parse.rs +++ b/crates/kernel/src/tasks/command_parse.rs @@ -20,6 +20,7 @@ use lazy_static::lazy_static; use moor_values::model::r#match::{PrepSpec, Preposition, PREP_LIST}; use moor_values::model::WorldStateError; +use moor_values::util; use moor_values::var::objid::Objid; use moor_values::var::{v_str, Var}; @@ -103,53 +104,6 @@ fn match_preposition(prep: &str) -> Option { .cloned() } -pub fn parse_into_words(input: &str) -> Vec { - // Initialize state variables. - let mut in_quotes = false; - let mut previous_char_was_backslash = false; - - // Define the fold function's logic as a closure. - let accumulate_words = |mut acc: Vec, c| { - if previous_char_was_backslash { - // Handle escaped characters. - if let Some(last_word) = acc.last_mut() { - last_word.push(c); - } else { - acc.push(c.to_string()); - } - previous_char_was_backslash = false; - } else if c == '\\' { - // Mark the next character as escaped. - previous_char_was_backslash = true; - } else if c == '"' { - // Toggle whether we're inside quotes. - in_quotes = !in_quotes; - } else if c.is_whitespace() && !in_quotes { - // Add a new empty string to the accumulator if we've reached a whitespace boundary. - if let Some(last_word) = acc.last() { - if !last_word.is_empty() { - acc.push(String::new()); - } - } - } else { - // Append the current character to the last word in the accumulator, - // or create a new word if there isn't one yet. - if let Some(last_word) = acc.last_mut() { - last_word.push(c); - } else { - acc.push(c.to_string()); - } - } - acc - }; - - // Use the fold function to accumulate the words in the input string. - let words = input.chars().fold(vec![], accumulate_words); - - // Filter out empty strings and return the result. - words.into_iter().filter(|w| !w.is_empty()).collect() -} - #[async_trait] pub trait ParseMatcher { async fn match_object(&mut self, name: &str) -> Result, WorldStateError>; @@ -186,7 +140,7 @@ where }; // Get word list - let words = parse_into_words(&command); + let words = util::parse_into_words(&command); if words.is_empty() { return Err(ParseCommandError::EmptyCommand); } @@ -218,7 +172,7 @@ where let verb = parts.next().unwrap_or_default().to_string(); let argstr = parts.next().unwrap_or_default().to_string(); - let words = parse_into_words(&argstr); + let words = util::parse_into_words(&argstr); // Normal MOO command // Find preposition, if any @@ -279,6 +233,7 @@ where #[cfg(test)] mod tests { use moor_values::model::r#match::Preposition; + use moor_values::util::parse_into_words; use moor_values::var::v_str; use moor_values::{FAILED_MATCH, NOTHING}; diff --git a/crates/kernel/src/tasks/task.rs b/crates/kernel/src/tasks/task.rs index 31a5a755..3655daf1 100644 --- a/crates/kernel/src/tasks/task.rs +++ b/crates/kernel/src/tasks/task.rs @@ -25,6 +25,7 @@ use moor_values::model::verb_info::VerbInfo; use moor_values::model::world_state::{WorldState, WorldStateSource}; use moor_values::model::CommandError::PermissionDenied; use moor_values::model::{CommandError, CommitResult, WorldStateError}; +use moor_values::util::parse_into_words; use moor_values::var::objid::Objid; use moor_values::var::variant::Variant; use moor_values::var::{v_int, v_string}; @@ -32,9 +33,7 @@ use moor_values::NOTHING; use crate::matching::match_env::MatchEnvironmentParseMatcher; use crate::matching::ws_match_env::WsMatchEnv; -use crate::tasks::command_parse::{ - parse_command, parse_into_words, ParseCommandError, ParsedCommand, -}; +use crate::tasks::command_parse::{parse_command, ParseCommandError, ParsedCommand}; use crate::tasks::scheduler::AbortLimitReason; use crate::tasks::sessions::Session; use crate::tasks::task_messages::{SchedulerControlMsg, TaskControlMsg, TaskStart}; diff --git a/crates/telnet-host/Cargo.toml b/crates/telnet-host/Cargo.toml index c6869a5e..15904480 100644 --- a/crates/telnet-host/Cargo.toml +++ b/crates/telnet-host/Cargo.toml @@ -6,7 +6,6 @@ repository.workspace = true license.workspace = true [dependencies] -moor-kernel = { path = "../kernel" } moor-values = { path = "../values" } rpc-common = { path = "../rpc-common" } diff --git a/crates/telnet-host/src/telnet.rs b/crates/telnet-host/src/telnet.rs index 997dd143..65bca4e4 100644 --- a/crates/telnet-host/src/telnet.rs +++ b/crates/telnet-host/src/telnet.rs @@ -28,8 +28,8 @@ use tokio_util::codec::{Framed, LinesCodec}; use tracing::{debug, error, info, trace}; use uuid::Uuid; -use moor_kernel::tasks::command_parse::parse_into_words; use moor_values::model::CommandError; +use moor_values::util::parse_into_words; use moor_values::var::objid::Objid; use rpc_common::pubsub_client::{broadcast_recv, narrative_recv}; use rpc_common::rpc_client::RpcSendClient; diff --git a/crates/values/src/util/mod.rs b/crates/values/src/util/mod.rs index 0b288c60..d0d9bbc9 100644 --- a/crates/values/src/util/mod.rs +++ b/crates/values/src/util/mod.rs @@ -70,6 +70,53 @@ pub fn quote_str(s: &str) -> String { output } +pub fn parse_into_words(input: &str) -> Vec { + // Initialize state variables. + let mut in_quotes = false; + let mut previous_char_was_backslash = false; + + // Define the fold function's logic as a closure. + let accumulate_words = |mut acc: Vec, c| { + if previous_char_was_backslash { + // Handle escaped characters. + if let Some(last_word) = acc.last_mut() { + last_word.push(c); + } else { + acc.push(c.to_string()); + } + previous_char_was_backslash = false; + } else if c == '\\' { + // Mark the next character as escaped. + previous_char_was_backslash = true; + } else if c == '"' { + // Toggle whether we're inside quotes. + in_quotes = !in_quotes; + } else if c.is_whitespace() && !in_quotes { + // Add a new empty string to the accumulator if we've reached a whitespace boundary. + if let Some(last_word) = acc.last() { + if !last_word.is_empty() { + acc.push(String::new()); + } + } + } else { + // Append the current character to the last word in the accumulator, + // or create a new word if there isn't one yet. + if let Some(last_word) = acc.last_mut() { + last_word.push(c); + } else { + acc.push(c.to_string()); + } + } + acc + }; + + // Use the fold function to accumulate the words in the input string. + let words = input.chars().fold(vec![], accumulate_words); + + // Filter out empty strings and return the result. + words.into_iter().filter(|w| !w.is_empty()).collect() +} + #[cfg(test)] mod tests { use crate::util::{quote_str, verbname_cmp}; diff --git a/crates/web-host/Cargo.toml b/crates/web-host/Cargo.toml index fb51e686..4d5eb28f 100644 --- a/crates/web-host/Cargo.toml +++ b/crates/web-host/Cargo.toml @@ -6,7 +6,6 @@ repository.workspace = true license.workspace = true [dependencies] -moor-kernel = { path = "../kernel" } moor-values = { path = "../values" } rpc-common = { path = "../rpc-common" }