ratex_parser/functions/
enclose.rs1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, ArgType, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8 define_function_full(
9 map,
10 &["\\fbox"],
11 "enclose",
12 1, 0,
13 Some(vec![ArgType::HBox]),
14 false,
15 true, true,
16 false, false,
17 handle_fbox,
18 );
19
20 define_function_full(
21 map,
22 &["\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\phase"],
23 "enclose",
24 1, 0, None,
25 false, false, true, false, false,
26 handle_cancel,
27 );
28
29 define_function_full(
30 map,
31 &["\\angl"],
32 "enclose",
33 1, 0,
34 Some(vec![ArgType::HBox]),
35 false,
36 false, true,
37 false, false,
38 handle_angl,
39 );
40}
41
42fn handle_fbox(
43 ctx: &mut FunctionContext,
44 args: Vec<ParseNode>,
45 _opt_args: Vec<Option<ParseNode>>,
46) -> ParseResult<ParseNode> {
47 Ok(ParseNode::Enclose {
48 mode: ctx.parser.mode,
49 label: "\\fbox".to_string(),
50 background_color: None,
51 border_color: None,
52 body: Box::new(args.into_iter().next().unwrap()),
53 loc: None,
54 })
55}
56
57fn handle_cancel(
58 ctx: &mut FunctionContext,
59 args: Vec<ParseNode>,
60 _opt_args: Vec<Option<ParseNode>>,
61) -> ParseResult<ParseNode> {
62 Ok(ParseNode::Enclose {
63 mode: ctx.parser.mode,
64 label: ctx.func_name.clone(),
65 background_color: None,
66 border_color: None,
67 body: Box::new(args.into_iter().next().unwrap()),
68 loc: None,
69 })
70}
71
72fn handle_angl(
73 ctx: &mut FunctionContext,
74 args: Vec<ParseNode>,
75 _opt_args: Vec<Option<ParseNode>>,
76) -> ParseResult<ParseNode> {
77 Ok(ParseNode::Enclose {
78 mode: ctx.parser.mode,
79 label: "\\angl".to_string(),
80 background_color: None,
81 border_color: None,
82 body: Box::new(args.into_iter().next().unwrap()),
83 loc: None,
84 })
85}