compiled, needs further progress

This commit is contained in:
filipriec
2025-03-08 12:49:54 +01:00
parent 9a87940311
commit 6281702575
4 changed files with 133 additions and 0 deletions

View File

@@ -1 +1,4 @@
// src/steel/handlers.rs
pub mod execution;
pub use execution::*;

View 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(),
})
}