renamed parser
This commit is contained in:
@@ -3,18 +3,18 @@ use regex::Regex;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct SyntaxParser {
|
||||
column_access_re: Regex,
|
||||
relationship_re: Regex,
|
||||
indexed_access_re: Regex,
|
||||
same_table_column_re: Regex,
|
||||
different_table_column_re: Regex,
|
||||
one_to_many_indexed_re: Regex,
|
||||
sql_integration_re: Regex,
|
||||
}
|
||||
|
||||
impl SyntaxParser {
|
||||
pub fn new() -> Self {
|
||||
SyntaxParser {
|
||||
column_access_re: Regex::new(r"@(\w+)").unwrap(),
|
||||
relationship_re: Regex::new(r"@(\w+)\.(\w+)").unwrap(),
|
||||
indexed_access_re: Regex::new(r"@(\w+)\[(\d+)\]\.(\w+)").unwrap(),
|
||||
same_table_column_re: Regex::new(r"@(\w+)").unwrap(),
|
||||
different_table_column_re: Regex::new(r"@(\w+)\.(\w+)").unwrap(),
|
||||
one_to_many_indexed_re: Regex::new(r"@(\w+)\[(\d+)\]\.(\w+)").unwrap(),
|
||||
sql_integration_re: Regex::new(r#"@sql\((['"])(.*?)['"]\)"#).unwrap(),
|
||||
}
|
||||
}
|
||||
@@ -23,18 +23,18 @@ impl SyntaxParser {
|
||||
let mut transformed = script.to_string();
|
||||
|
||||
// Process indexed access first to avoid overlap with relationship matches
|
||||
transformed = self.indexed_access_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
transformed = self.one_to_many_indexed_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(get_related_index \"{}\" {} \"{}\")",
|
||||
&caps[1], &caps[2], &caps[3])
|
||||
}).to_string();
|
||||
|
||||
// Process relationships
|
||||
transformed = self.relationship_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
transformed = self.different_table_column_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(get_related_value \"{}\" \"{}\")", &caps[1], &caps[2])
|
||||
}).to_string();
|
||||
|
||||
// Process basic column access
|
||||
transformed = self.column_access_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
transformed = self.same_table_column_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(steel_get_column \"{}\")", &caps[1])
|
||||
}).to_string();
|
||||
|
||||
@@ -46,16 +46,20 @@ impl SyntaxParser {
|
||||
transformed
|
||||
}
|
||||
|
||||
pub fn extract_current_table(&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 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());
|
||||
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());
|
||||
columns.insert(cap[3].to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user