neutralts/macros.rs
1
2// Inherit, macro: new_child_parse
3// -------------------------------
4// Inheritance is implemented with this macro. It is also used for the inheritance
5// of the application itself.
6//
7//
8// Block level scope example:
9// {:code; <--------------------------.
10// {:* block *:} |<---- Block
11// {:param; name >> value :} <----|----- Set "name" for this block and its children
12// {:param; name :} <-------------|----- "name" has the value "value".
13// {:code; |
14// {:* child block *:} |
15// {:param; name :} <---------|----- "name" has the value "value".
16// :} |
17// :} <-------------------------------ยท
18// {:param; name :} <----------------------- outside block, no value or a previous value if any.
19//
20//
21// "include" has a block scope, then:
22// {:code;
23// {:* include for set "snippet-name" *:}
24// {:include; snippet.ntpl :}
25// {:snippet; snippet-name :} {:* Ok, "snippet-name" is set *:}
26// :}
27// {:snippet; snippet-name :} {:* Ko, "snippet-name" is not set *:}
28//
29// The modifier scope (+) adds the scope to the current level to make it possible to do this:
30// {:+bool; something >>
31// {:include; snippet.ntpl :}
32// :}
33// {:snippet; snippet-name :} {:* Ok, "snippet-name" is set *:}
34//
35#[macro_use]
36mod macros {
37 macro_rules! new_child_parse {
38 ($self:expr, $source:expr, $scope:expr) => {{
39 let mut child_inherit = $self.inherit.clone();
40 let shared = &mut $self.shared;
41
42 // "bif.alias" is used and not "bif.name" because in "var" or "unprintable"
43 // its name is an empty string and could have more meanings.
44 child_inherit.alias = $self.alias.clone();
45
46 if !$self.file_path.is_empty() {
47 child_inherit.current_file = $self.file_path.clone();
48 }
49
50 if !$self.dir.is_empty() {
51 child_inherit.current_dir = $self.dir.clone();
52 }
53
54 // Create a new version of the schema if mod_scope
55 // This is necessary because indirections are used,
56 // and create_block_schema takes care of that.
57 if $scope {
58 $self.inherit.create_block_schema(shared);
59 }
60
61 let mut block = $crate::block_parser::BlockParser::new(shared, &child_inherit);
62 let code = block.parse($source, $self.only);
63
64 // Update this block with the data generated in the child
65 if $scope {
66 block.update_indir(&$self.inherit.indir);
67 }
68
69 code
70 }};
71 }
72}