neutralts/bif/
parse_bif_exit.rs1#![doc = include_str!("../../doc/bif-exit.md")]
2
3use crate::{bif::constants::*, bif::Bif, bif::BifError, constants::*};
4
5impl<'a> Bif<'a> {
6 pub(crate) fn parse_bif_exit(&mut self) -> Result<(), BifError> {
13 if self.mod_filter || self.mod_scope {
14 return Err(self.bif_error(BIF_ERROR_MODIFIER_NOT_ALLOWED));
15 }
16
17 if self.inherit.in_cache {
18 self.out = format!("{}{}{}", "{:!cache;", self.raw.to_string(), ":}");
19 } else {
20 self.out = EMPTY_STRING;
21 }
22
23 let has_status_params = self.extract_params_code(true);
24
25 if !self.flags.is_empty() {
26 return Err(self.bif_error(BIF_ERROR_FLAGS_NOT_ALLOWED));
27 }
28
29 if self.code.contains(BIF_OPEN) {
30 self.code = new_child_parse!(self, &self.code, false);
31 }
32
33 let mut status_code = "200";
34 let mut status_param = "";
35
36 if has_status_params {
37 if !self.params.is_empty() {
38 status_code = self.params.as_str();
39 }
40 status_param = &self.code;
41 } else if !self.code.is_empty() {
42 status_code = self.code.as_str();
43 }
44
45 self.shared.status_code = status_code.to_string();
46 self.shared.status_param = status_param.to_string();
47
48 if let Some(text) = STATUS_CODES.get(status_code) {
49 self.shared.status_text = text.to_string();
50 } else {
51 self.shared.status_text = EMPTY_STRING;
52 }
53
54 self.shared.exit = true ^ self.mod_negate;
55
56 Ok(())
57 }
58}
59
60#[cfg(test)]
61#[path = "parse_bif_exit_tests.rs"]
62mod tests;