Skip to content

Commit

Permalink
Remove intra-workspace dependencies on kernel for console/web/telne…
Browse files Browse the repository at this point in the history
…t hosts.

They didn't need this dependency and it was bloating compile times.
  • Loading branch information
rdaum committed Jan 7, 2024
1 parent 85d3a47 commit 7de9a9b
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 60 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/console-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repository.workspace = true
license.workspace = true

[dependencies]
moor-kernel = { path = "../kernel" }
moor-values = { path = "../values" }
rpc-common = { path = "../rpc-common" }

Expand Down
2 changes: 1 addition & 1 deletion crates/daemon/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 4 additions & 49 deletions crates/kernel/src/tasks/command_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -103,53 +104,6 @@ fn match_preposition(prep: &str) -> Option<Prep> {
.cloned()
}

pub fn parse_into_words(input: &str) -> Vec<String> {
// 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<String>, 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<Option<Objid>, WorldStateError>;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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};

Expand Down
5 changes: 2 additions & 3 deletions crates/kernel/src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ 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};
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};
Expand Down
1 change: 0 additions & 1 deletion crates/telnet-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repository.workspace = true
license.workspace = true

[dependencies]
moor-kernel = { path = "../kernel" }
moor-values = { path = "../values" }
rpc-common = { path = "../rpc-common" }

Expand Down
2 changes: 1 addition & 1 deletion crates/telnet-host/src/telnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions crates/values/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,53 @@ pub fn quote_str(s: &str) -> String {
output
}

pub fn parse_into_words(input: &str) -> Vec<String> {
// 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<String>, 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};
Expand Down
1 change: 0 additions & 1 deletion crates/web-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repository.workspace = true
license.workspace = true

[dependencies]
moor-kernel = { path = "../kernel" }
moor-values = { path = "../values" }
rpc-common = { path = "../rpc-common" }

Expand Down

0 comments on commit 7de9a9b

Please sign in to comment.