swc_html_parser/parser/
macros.rs

1macro_rules! span {
2    ($parser:expr, $start:expr) => {{
3        let last_pos = $parser.input.last_pos()?;
4        swc_common::Span::new($start, last_pos)
5    }};
6}
7
8macro_rules! bump {
9    ($parser:expr) => {
10        $parser.input.bump()?.unwrap().token
11    };
12}
13
14macro_rules! get_tag_name {
15    ($node:expr) => {{
16        match &$node.data {
17            crate::parser::Data::Element { tag_name, .. } => &**tag_name,
18            _ => {
19                unreachable!();
20            }
21        }
22    }};
23}
24
25macro_rules! get_namespace {
26    ($node:expr) => {{
27        match $node.data {
28            crate::parser::Data::Element { namespace, .. } => namespace,
29            _ => {
30                unreachable!();
31            }
32        }
33    }};
34}
35
36macro_rules! get_document_mode {
37    ($node:expr) => {{
38        match &$node.data {
39            crate::parser::Data::Document { mode, .. } => *mode.borrow(),
40            _ => {
41                unreachable!();
42            }
43        }
44    }};
45}
46
47macro_rules! is_html_element {
48    ($node:expr, $tag_names:pat) => {{
49        get_namespace!($node) == Namespace::HTML && matches!(get_tag_name!($node), $tag_names)
50    }};
51}
52
53macro_rules! is_mathml_element {
54    ($node:expr, $tag_names:pat) => {{
55        get_namespace!($node) == Namespace::MATHML && matches!(get_tag_name!($node), $tag_names)
56    }};
57}
58
59macro_rules! is_svg_element {
60    ($node:expr, $tag_names:pat) => {{
61        get_namespace!($node) == Namespace::SVG && matches!(get_tag_name!($node), $tag_names)
62    }};
63}
64
65macro_rules! is_html_element_with_tag_name {
66    ($node:expr, $tag_name:expr) => {{
67        get_namespace!($node) == Namespace::HTML && get_tag_name!($node) == $tag_name
68    }};
69}