neutralts/bif/
parse_bif_moveto.rs1#![doc = include_str!("../../doc/bif-moveto.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*, json};
4use md5::{Digest, Md5};
5
6impl<'a> Bif<'a> {
7 pub(crate) fn parse_bif_moveto(&mut self) -> Result<(), BifError> {
12 if self.mod_filter || self.mod_negate || self.mod_scope {
13 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
14 }
15
16 if self.inherit.in_cache {
17 self.out = format!("{}{}{}", "{:!cache;", self.raw.to_string(), ":}");
18 } else {
19 self.out = EMPTY_STRING;
20 }
21
22 self.extract_params_code(true);
23
24 if !self.flags.is_empty() {
25 return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
26 }
27
28 if self.code.contains(BIF_OPEN) {
29 self.code = new_child_parse!(self, &self.code, self.mod_scope);
30 }
31
32 self.moveto(&self.params.clone(), &self.code.clone());
33
34 Ok(())
35 }
36
37 pub(crate) fn moveto(&mut self, to: &str, code: &str) {
38 let mut moveto = json!({});
39 let mut hasher = Md5::new();
40
41 hasher.update(code.replace("\n", "").replace(" ", ""));
43 let code_hash = hasher.finalize();
44 let code_hash = format!("{:x}", code_hash);
45
46 moveto[to] = json!(code);
47 self.shared.schema["__moveto"][&code_hash] = moveto;
48 }
49}
50
51#[cfg(test)]
52#[path = "parse_bif_moveto_tests.rs"]
53mod tests;