compiled, needs further progress
This commit is contained in:
@@ -1 +1,4 @@
|
||||
// src/steel/handlers.rs
|
||||
pub mod execution;
|
||||
|
||||
pub use execution::*;
|
||||
|
||||
66
server/src/steel/handlers/execution.rs
Normal file
66
server/src/steel/handlers/execution.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
// src/steel/execution.rs
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ScriptOperation {
|
||||
SetToColumn { source: String },
|
||||
// Future operations can be added here
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ScriptExecutionError {
|
||||
ParseError(String),
|
||||
MissingSourceColumn(String),
|
||||
Mismatch { expected: String, actual: String },
|
||||
}
|
||||
|
||||
impl fmt::Display for ScriptExecutionError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::ParseError(msg) => write!(f, "Parse error: {}", msg),
|
||||
Self::MissingSourceColumn(col) => write!(f, "Missing source column: {}", col),
|
||||
Self::Mismatch { expected, actual } => write!(
|
||||
f,
|
||||
"Value does not match script expectation. Expected: {}, Actual: {}",
|
||||
expected, actual
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_script(script: &str, expected_target: &str) -> Result<ScriptOperation, ScriptExecutionError> {
|
||||
let script = script.trim();
|
||||
|
||||
if !script.starts_with("(set! ") || !script.ends_with(')') {
|
||||
return Err(ScriptExecutionError::ParseError(
|
||||
"Script must be in the form (set! target source)".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let content = &script[6..script.len() - 1].trim();
|
||||
let mut parts = content.split_whitespace();
|
||||
|
||||
let target = parts.next().ok_or_else(|| {
|
||||
ScriptExecutionError::ParseError("Missing target in set! expression".to_string())
|
||||
})?;
|
||||
let source = parts.next().ok_or_else(|| {
|
||||
ScriptExecutionError::ParseError("Missing source in set! expression".to_string())
|
||||
})?;
|
||||
|
||||
if parts.next().is_some() {
|
||||
return Err(ScriptExecutionError::ParseError(
|
||||
"Too many arguments in set! expression".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if target != expected_target {
|
||||
return Err(ScriptExecutionError::ParseError(format!(
|
||||
"Script target '{}' does not match expected '{}'",
|
||||
target, expected_target
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(ScriptOperation::SetToColumn {
|
||||
source: source.to_string(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user