Skip to main content

ratex_parser/functions/
arrow.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        &[
11            "\\xleftarrow", "\\xrightarrow", "\\xLeftarrow", "\\xRightarrow",
12            "\\xleftrightarrow", "\\xLeftrightarrow", "\\xhookleftarrow",
13            "\\xhookrightarrow", "\\xmapsto", "\\xrightharpoondown",
14            "\\xrightharpoonup", "\\xleftharpoondown", "\\xleftharpoonup",
15            "\\xrightleftharpoons", "\\xleftrightharpoons", "\\xlongequal",
16            "\\xtwoheadrightarrow", "\\xtwoheadleftarrow", "\\xtofrom",
17            "\\xrightleftarrows", "\\xrightequilibrium", "\\xleftequilibrium",
18        ],
19        "xArrow",
20        1, 1, None,
21        false, false, true, false, false,
22        handle_arrow,
23    );
24}
25
26fn handle_arrow(
27    ctx: &mut FunctionContext,
28    args: Vec<ParseNode>,
29    opt_args: Vec<Option<ParseNode>>,
30) -> ParseResult<ParseNode> {
31    let body = args.into_iter().next().unwrap();
32    let below = opt_args.into_iter().next().flatten();
33
34    Ok(ParseNode::XArrow {
35        mode: ctx.parser.mode,
36        label: ctx.func_name.clone(),
37        body: Box::new(body),
38        below: below.map(Box::new),
39        loc: None,
40    })
41}