Skip to main content

ratex_parser/functions/
overline.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        &["\\overline"],
11        "overline",
12        1,
13        0,
14        None,
15        false,
16        false,
17        true,
18        false,
19        false,
20        handle_overline,
21    );
22
23    define_function_full(
24        map,
25        &["\\underline"],
26        "underline",
27        1,
28        0,
29        None,
30        false,
31        true, // allowed_in_text
32        true,
33        false,
34        false,
35        handle_underline,
36    );
37}
38
39fn handle_overline(
40    ctx: &mut FunctionContext,
41    args: Vec<ParseNode>,
42    _opt_args: Vec<Option<ParseNode>>,
43) -> ParseResult<ParseNode> {
44    Ok(ParseNode::Overline {
45        mode: ctx.parser.mode,
46        body: Box::new(args.into_iter().next().unwrap()),
47        loc: None,
48    })
49}
50
51fn handle_underline(
52    ctx: &mut FunctionContext,
53    args: Vec<ParseNode>,
54    _opt_args: Vec<Option<ParseNode>>,
55) -> ParseResult<ParseNode> {
56    Ok(ParseNode::Underline {
57        mode: ctx.parser.mode,
58        body: Box::new(args.into_iter().next().unwrap()),
59        loc: None,
60    })
61}