renamed parser

This commit is contained in:
filipriec
2025-03-15 20:48:02 +01:00
parent d87cc3b5b9
commit d8a52b9d73

View File

@@ -3,18 +3,18 @@ use regex::Regex;
use std::collections::HashSet; use std::collections::HashSet;
pub struct SyntaxParser { pub struct SyntaxParser {
column_access_re: Regex, same_table_column_re: Regex,
relationship_re: Regex, different_table_column_re: Regex,
indexed_access_re: Regex, one_to_many_indexed_re: Regex,
sql_integration_re: Regex, sql_integration_re: Regex,
} }
impl SyntaxParser { impl SyntaxParser {
pub fn new() -> Self { pub fn new() -> Self {
SyntaxParser { SyntaxParser {
column_access_re: Regex::new(r"@(\w+)").unwrap(), same_table_column_re: Regex::new(r"@(\w+)").unwrap(),
relationship_re: Regex::new(r"@(\w+)\.(\w+)").unwrap(), different_table_column_re: Regex::new(r"@(\w+)\.(\w+)").unwrap(),
indexed_access_re: Regex::new(r"@(\w+)\[(\d+)\]\.(\w+)").unwrap(), one_to_many_indexed_re: Regex::new(r"@(\w+)\[(\d+)\]\.(\w+)").unwrap(),
sql_integration_re: Regex::new(r#"@sql\((['"])(.*?)['"]\)"#).unwrap(), sql_integration_re: Regex::new(r#"@sql\((['"])(.*?)['"]\)"#).unwrap(),
} }
} }
@@ -23,18 +23,18 @@ impl SyntaxParser {
let mut transformed = script.to_string(); let mut transformed = script.to_string();
// Process indexed access first to avoid overlap with relationship matches // Process indexed access first to avoid overlap with relationship matches
transformed = self.indexed_access_re.replace_all(&transformed, |caps: &regex::Captures| { transformed = self.one_to_many_indexed_re.replace_all(&transformed, |caps: &regex::Captures| {
format!("(get_related_index \"{}\" {} \"{}\")", format!("(get_related_index \"{}\" {} \"{}\")",
&caps[1], &caps[2], &caps[3]) &caps[1], &caps[2], &caps[3])
}).to_string(); }).to_string();
// Process relationships // Process relationships
transformed = self.relationship_re.replace_all(&transformed, |caps: &regex::Captures| { transformed = self.different_table_column_re.replace_all(&transformed, |caps: &regex::Captures| {
format!("(get_related_value \"{}\" \"{}\")", &caps[1], &caps[2]) format!("(get_related_value \"{}\" \"{}\")", &caps[1], &caps[2])
}).to_string(); }).to_string();
// Process basic column access // Process basic column access
transformed = self.column_access_re.replace_all(&transformed, |caps: &regex::Captures| { transformed = self.same_table_column_re.replace_all(&transformed, |caps: &regex::Captures| {
format!("(steel_get_column \"{}\")", &caps[1]) format!("(steel_get_column \"{}\")", &caps[1])
}).to_string(); }).to_string();
@@ -46,16 +46,20 @@ impl SyntaxParser {
transformed transformed
} }
pub fn extract_current_table(&self, script: &str) -> (HashSet<String>, HashSet<String>) {
}
pub fn extract_dependencies(&self, script: &str) -> (HashSet<String>, HashSet<String>) { pub fn extract_dependencies(&self, script: &str) -> (HashSet<String>, HashSet<String>) {
let mut tables = HashSet::new(); let mut tables = HashSet::new();
let mut columns = HashSet::new(); let mut columns = HashSet::new();
for cap in self.relationship_re.captures_iter(script) { for cap in self.different_table_column_re.captures_iter(script) {
tables.insert(cap[1].to_string()); tables.insert(cap[1].to_string());
columns.insert(cap[2].to_string()); columns.insert(cap[2].to_string());
} }
for cap in self.indexed_access_re.captures_iter(script) { for cap in self.one_to_many_indexed_re.captures_iter(script) {
tables.insert(cap[1].to_string()); tables.insert(cap[1].to_string());
columns.insert(cap[3].to_string()); columns.insert(cap[3].to_string());
} }