neutralts/bif/
parse_bif_param.rs

1#![doc = include_str!("../../doc/bif-param.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*, json, utils::*};
4
5impl<'a> Bif<'a> {
6    /*
7        Play param: {:param; param-name :}
8        Set param:  {:param; param-name >> content to set :}
9    */
10    pub(crate) fn parse_bif_param(&mut self) -> Result<(), BifError> {
11        if self.mod_filter || self.mod_negate || self.mod_scope {
12            return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
13        }
14
15        let is_set = self.extract_params_code(true);
16
17        if !self.flags.is_empty() {
18            return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
19        }
20
21        if is_set {
22            if self.inherit.alias == "code" {
23                if self.code.contains(BIF_OPEN) {
24                    self.code = new_child_parse!(self, &self.code, self.mod_scope);
25                }
26
27                self.inherit.create_block_schema(self.shared);
28                self.shared.schema["__indir"][&self.inherit.indir]["params"][&self.params] =
29                    json!(&self.code);
30                self.out = EMPTY_STRING;
31
32                Ok(())
33            } else {
34                Err(self.bif_error(BIF_ERROR_PARAM_SET_HERE))
35            }
36        } else {
37            if self.code.contains(BIF_OPEN) {
38                self.code = new_child_parse!(self, &self.code, self.mod_scope);
39            }
40
41            self.code = get_from_key(
42                &self.shared.schema["__indir"][&self.inherit.indir]["params"],
43                &self.code,
44            );
45            self.out = self.code.to_string();
46
47            Ok(())
48        }
49    }
50}
51
52#[cfg(test)]
53#[path = "parse_bif_param_tests.rs"]
54mod tests;