Skip to main content

ratex_parser/functions/
pmb.rs

1use 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, 0, None,
13        false,
14        true, true,
15        false, false,
16        handle_pmb,
17    );
18}
19
20fn binrel_class(arg: &ParseNode) -> String {
21    let atom = if let ParseNode::OrdGroup { body, .. } = arg {
22        if !body.is_empty() { &body[0] } else { arg }
23    } else {
24        arg
25    };
26    if let ParseNode::Atom { family, .. } = atom {
27        match family {
28            crate::parse_node::AtomFamily::Bin => return "mbin".to_string(),
29            crate::parse_node::AtomFamily::Rel => return "mrel".to_string(),
30            _ => {}
31        }
32    }
33    "mord".to_string()
34}
35
36fn handle_pmb(
37    ctx: &mut FunctionContext,
38    args: Vec<ParseNode>,
39    _opt_args: Vec<Option<ParseNode>>,
40) -> ParseResult<ParseNode> {
41    let body = args.into_iter().next().unwrap();
42
43    Ok(ParseNode::Pmb {
44        mode: ctx.parser.mode,
45        mclass: binrel_class(&body),
46        body: ParseNode::ord_argument(body),
47        loc: None,
48    })
49}