MCPcopy Create free account
hub / github.com/PRQL/prql / post_process

Function post_process

prqlc/prqlc/src/cli/jinja.rs:121–145  ·  view source on GitHub ↗

Replace anchors with their values.

(source: &str, context: JinjaContext)

Source from the content-addressed store, hash-verified

119
120/// Replace anchors with their values.
121pub fn post_process(source: &str, context: JinjaContext) -> String {
122 let mut res = String::new();
123
124 for stmt in context.header {
125 res += stmt;
126 res += "\n";
127 }
128
129 let re = Regex::new(&format!(r"{ANCHOR_PREFIX}\d+")).unwrap();
130
131 let mut last_index = 0;
132 for cap in re.captures_iter(source) {
133 let cap = cap.get(0).unwrap();
134 let index = cap.start();
135 let anchor_id = cap.as_str();
136
137 res += &source[last_index..index];
138 res += context.anchor_map.get(anchor_id).unwrap_or(&anchor_id);
139
140 last_index = index + anchor_id.len();
141 }
142 res += &source[last_index..];
143
144 res
145}
146
147#[cfg(test)]
148mod test {

Callers 3

test_post_processFunction · 0.85
compile_pathFunction · 0.85

Calls 4

startMethod · 0.80
as_strMethod · 0.80
lenMethod · 0.80
getMethod · 0.45

Tested by 2

test_post_processFunction · 0.68