parser improvements
This commit is contained in:
@@ -3,7 +3,7 @@ use regex::Regex;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub struct SyntaxParser {
|
||||
same_table_column_re: Regex,
|
||||
current_table_column_re: Regex,
|
||||
different_table_column_re: Regex,
|
||||
one_to_many_indexed_re: Regex,
|
||||
sql_integration_re: Regex,
|
||||
@@ -12,7 +12,7 @@ pub struct SyntaxParser {
|
||||
impl SyntaxParser {
|
||||
pub fn new() -> Self {
|
||||
SyntaxParser {
|
||||
same_table_column_re: Regex::new(r"@(\w+)").unwrap(),
|
||||
current_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(),
|
||||
@@ -24,18 +24,18 @@ impl SyntaxParser {
|
||||
|
||||
// Process indexed access first to avoid overlap with relationship matches
|
||||
transformed = self.one_to_many_indexed_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(get_related_index \"{}\" {} \"{}\")",
|
||||
format!("(steel_get_column_with_index \"{}\" {} \"{}\")",
|
||||
&caps[1], &caps[2], &caps[3])
|
||||
}).to_string();
|
||||
|
||||
// Process relationships
|
||||
transformed = self.different_table_column_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(get_related_value \"{}\" \"{}\")", &caps[1], &caps[2])
|
||||
format!("(steel_get_column \"{}\" \"{}\")", &caps[1], &caps[2])
|
||||
}).to_string();
|
||||
|
||||
// Process basic column access
|
||||
transformed = self.same_table_column_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(steel_get_column \"{}\")", &caps[1])
|
||||
transformed = self.current_table_column_re.replace_all(&transformed, |caps: ®ex::Captures| {
|
||||
format!("(steel_get_column \"{}\" \"{}\")", current_table, &caps[1])
|
||||
}).to_string();
|
||||
|
||||
// Process SQL integration
|
||||
@@ -46,14 +46,15 @@ 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.current_table_column_re.captures_iter(script) {
|
||||
tables.insert(current_table.to_string());
|
||||
columns.insert(cap[1].to_string());
|
||||
}
|
||||
|
||||
for cap in self.different_table_column_re.captures_iter(script) {
|
||||
tables.insert(cap[1].to_string());
|
||||
columns.insert(cap[2].to_string());
|
||||
|
||||
Reference in New Issue
Block a user