swc_html_parser/parser/
macros.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
macro_rules! span {
    ($parser:expr, $start:expr) => {{
        let last_pos = $parser.input.last_pos()?;
        swc_common::Span::new($start, last_pos)
    }};
}

macro_rules! bump {
    ($parser:expr) => {
        $parser.input.bump()?.unwrap().token
    };
}

macro_rules! get_tag_name {
    ($node:expr) => {{
        match &$node.data {
            crate::parser::Data::Element { tag_name, .. } => &**tag_name,
            _ => {
                unreachable!();
            }
        }
    }};
}

macro_rules! get_namespace {
    ($node:expr) => {{
        match $node.data {
            crate::parser::Data::Element { namespace, .. } => namespace,
            _ => {
                unreachable!();
            }
        }
    }};
}

macro_rules! get_document_mode {
    ($node:expr) => {{
        match &$node.data {
            crate::parser::Data::Document { mode, .. } => *mode.borrow(),
            _ => {
                unreachable!();
            }
        }
    }};
}

macro_rules! is_html_element {
    ($node:expr, $tag_names:pat) => {{
        get_namespace!($node) == Namespace::HTML && matches!(get_tag_name!($node), $tag_names)
    }};
}

macro_rules! is_mathml_element {
    ($node:expr, $tag_names:pat) => {{
        get_namespace!($node) == Namespace::MATHML && matches!(get_tag_name!($node), $tag_names)
    }};
}

macro_rules! is_svg_element {
    ($node:expr, $tag_names:pat) => {{
        get_namespace!($node) == Namespace::SVG && matches!(get_tag_name!($node), $tag_names)
    }};
}

macro_rules! is_html_element_with_tag_name {
    ($node:expr, $tag_name:expr) => {{
        get_namespace!($node) == Namespace::HTML && get_tag_name!($node) == $tag_name
    }};
}