ratex_parser/functions/
pmb.rs1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8 define_function_full(
9 map,
10 &["\\pmb"],
11 "pmb",
12 1,
13 0,
14 None,
15 false,
16 true,
17 true,
18 false,
19 false,
20 handle_pmb,
21 );
22}
23
24fn binrel_class(arg: &ParseNode) -> String {
25 let atom = if let ParseNode::OrdGroup { body, .. } = arg {
26 if !body.is_empty() {
27 &body[0]
28 } else {
29 arg
30 }
31 } else {
32 arg
33 };
34 if let ParseNode::Atom { family, .. } = atom {
35 match family {
36 crate::parse_node::AtomFamily::Bin => return "mbin".to_string(),
37 crate::parse_node::AtomFamily::Rel => return "mrel".to_string(),
38 _ => {}
39 }
40 }
41 "mord".to_string()
42}
43
44fn handle_pmb(
45 ctx: &mut FunctionContext,
46 args: Vec<ParseNode>,
47 _opt_args: Vec<Option<ParseNode>>,
48) -> ParseResult<ParseNode> {
49 let body = args.into_iter().next().unwrap();
50
51 Ok(ParseNode::Pmb {
52 mode: ctx.parser.mode,
53 mclass: binrel_class(&body),
54 body: ParseNode::ord_argument(body),
55 loc: None,
56 })
57}