removal of @ syntax as reference from the backend

This commit is contained in:
filipriec
2025-07-25 12:13:51 +02:00
parent 9eb46cb5d3
commit 7437908baf
2 changed files with 9 additions and 33 deletions

View File

@@ -82,13 +82,12 @@ pub async fn execute_script(
// Register decimal math operations // Register decimal math operations
register_decimal_math_functions(&mut vm); register_decimal_math_functions(&mut vm);
// Register row data as variables in the Steel VM // Register row data as variables in the Steel VM for get-var access
// Both bare names and @-prefixed names are supported for flexibility
let mut define_script = String::new(); let mut define_script = String::new();
for (key, value) in &context.row_data { for (key, value) in &context.row_data {
// Register both @ prefixed and bare variable names // Register only bare variable names for get-var access
define_script.push_str(&format!("(define @{} \"{}\")\n", key, value)); define_script.push_str(&format!("(define {} \"{}\")\n", key, value));
} }
// Execute variable definitions if any exist // Execute variable definitions if any exist
@@ -169,7 +168,7 @@ fn register_decimal_math_functions(vm: &mut Engine) {
/// Processes Steel script results into string format for consistent output. /// Processes Steel script results into string format for consistent output.
fn process_string_results(results: Vec<SteelVal>) -> Result<Value, ExecutionError> { fn process_string_results(results: Vec<SteelVal>) -> Result<Value, ExecutionError> {
let mut strings = Vec::new(); let mut strings = Vec::new();
for result in results { for result in results {
let result_str = match result { let result_str = match result {
SteelVal::StringV(s) => s.to_string(), SteelVal::StringV(s) => s.to_string(),

View File

@@ -103,7 +103,7 @@ impl From<DependencyError> for Status {
} }
/// Analyzes Steel scripts to extract table dependencies and validate referential integrity. /// Analyzes Steel scripts to extract table dependencies and validate referential integrity.
/// ///
/// This analyzer identifies how tables reference each other through Steel function calls /// This analyzer identifies how tables reference each other through Steel function calls
/// and ensures that dependency graphs remain acyclic while respecting table link constraints. /// and ensures that dependency graphs remain acyclic while respecting table link constraints.
pub struct DependencyAnalyzer { pub struct DependencyAnalyzer {
@@ -117,12 +117,11 @@ impl DependencyAnalyzer {
} }
/// Analyzes a Steel script to extract all table dependencies. /// Analyzes a Steel script to extract all table dependencies.
/// ///
/// Uses regex patterns to identify function calls that create dependencies: /// Uses regex patterns to identify function calls that create dependencies:
/// - `steel_get_column` calls for direct column access /// - `steel_get_column` calls for direct column access
/// - `steel_get_column_with_index` calls for indexed access /// - `steel_get_column_with_index` calls for indexed access
/// - `steel_query_sql` calls for raw SQL access /// - `steel_query_sql` calls for raw SQL access
/// - Variable references like `@column_name`
/// - `get-var` calls in transformed scripts /// - `get-var` calls in transformed scripts
/// ///
/// # Arguments /// # Arguments
@@ -139,7 +138,6 @@ impl DependencyAnalyzer {
dependencies.extend(self.extract_function_calls(script)?); dependencies.extend(self.extract_function_calls(script)?);
dependencies.extend(self.extract_sql_dependencies(script)?); dependencies.extend(self.extract_sql_dependencies(script)?);
dependencies.extend(self.extract_get_var_calls(script, current_table_name)?); dependencies.extend(self.extract_get_var_calls(script, current_table_name)?);
dependencies.extend(self.extract_variable_references(script, current_table_name)?);
Ok(dependencies) Ok(dependencies)
} }
@@ -202,27 +200,6 @@ impl DependencyAnalyzer {
Ok(dependencies) Ok(dependencies)
} }
/// Extracts direct variable references like @price, @quantity.
/// These represent self-references to the current table.
fn extract_variable_references(&self, script: &str, current_table_name: &str) -> Result<Vec<Dependency>, DependencyError> {
let mut dependencies = Vec::new();
// Pattern: @variable_name
let variable_pattern = regex::Regex::new(r#"@([a-zA-Z_][a-zA-Z0-9_]*)"#)
.map_err(|e: regex::Error| DependencyError::ScriptParseError { error: e.to_string() })?;
for caps in variable_pattern.captures_iter(script) {
let variable_name = caps[1].to_string();
dependencies.push(Dependency {
target_table: current_table_name.to_string(),
dependency_type: DependencyType::ColumnAccess { column: variable_name },
context: None,
});
}
Ok(dependencies)
}
/// Extracts table references from SQL queries in steel_query_sql calls. /// Extracts table references from SQL queries in steel_query_sql calls.
fn extract_sql_dependencies(&self, script: &str) -> Result<Vec<Dependency>, DependencyError> { fn extract_sql_dependencies(&self, script: &str) -> Result<Vec<Dependency>, DependencyError> {
let mut dependencies = Vec::new(); let mut dependencies = Vec::new();
@@ -272,7 +249,7 @@ impl DependencyAnalyzer {
} }
/// Checks for circular dependencies in the dependency graph. /// Checks for circular dependencies in the dependency graph.
/// ///
/// This function validates that adding new dependencies won't create cycles /// This function validates that adding new dependencies won't create cycles
/// that could lead to infinite loops during script execution. Self-references /// that could lead to infinite loops during script execution. Self-references
/// are explicitly allowed and filtered out from cycle detection. /// are explicitly allowed and filtered out from cycle detection.
@@ -421,7 +398,7 @@ impl DependencyAnalyzer {
} }
/// Validates that structured table access respects table link constraints. /// Validates that structured table access respects table link constraints.
/// ///
/// # Access Rules /// # Access Rules
/// - Self-references are always allowed (table can access its own columns) /// - Self-references are always allowed (table can access its own columns)
/// - Structured access (steel_get_column functions) requires explicit table links /// - Structured access (steel_get_column functions) requires explicit table links
@@ -532,7 +509,7 @@ impl DependencyAnalyzer {
} }
/// Saves dependencies to the database within an existing transaction. /// Saves dependencies to the database within an existing transaction.
/// ///
/// This function replaces all existing dependencies for a script with the new set, /// This function replaces all existing dependencies for a script with the new set,
/// ensuring the database reflects the current script analysis results. /// ensuring the database reflects the current script analysis results.
/// ///