aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/positioned.rs
blob: d2793fad743a44866a16508efc0bd9c89bde761f (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2019 Fredrik Portström <https://portstrom.com>
// This is free software distributed under the terms specified in
// the file LICENSE at the top-level directory of this distribution.

macro_rules! impl_positioned {
    ($type:tt) => {
        impl<'a> crate::Positioned for crate::$type<'a> {
            fn end(&self) -> usize {
                self.end
            }

            fn start(&self) -> usize {
                self.start
            }
        }
    };
}

impl_positioned!(DefinitionListItem);
impl_positioned!(ListItem);
impl_positioned!(Parameter);
impl_positioned!(TableCaption);
impl_positioned!(TableCell);
impl_positioned!(TableRow);

impl<'a> crate::Positioned for crate::Node<'a> {
    fn end(&self) -> usize {
        match *self {
            crate::Node::Bold { end, .. } => end,
            crate::Node::BoldItalic { end, .. } => end,
            crate::Node::Category { end, .. } => end,
            crate::Node::CharacterEntity { end, .. } => end,
            crate::Node::Comment { end, .. } => end,
            crate::Node::DefinitionList { end, .. } => end,
            crate::Node::EndTag { end, .. } => end,
            crate::Node::ExternalLink { end, .. } => end,
            crate::Node::Heading { end, .. } => end,
            crate::Node::HorizontalDivider { end, .. } => end,
            crate::Node::Image { end, .. } => end,
            crate::Node::Italic { end, .. } => end,
            crate::Node::Link { end, .. } => end,
            crate::Node::MagicWord { end, .. } => end,
            crate::Node::OrderedList { end, .. } => end,
            crate::Node::ParagraphBreak { end, .. } => end,
            crate::Node::Parameter { end, .. } => end,
            crate::Node::Preformatted { end, .. } => end,
            crate::Node::Redirect { end, .. } => end,
            crate::Node::StartTag { end, .. } => end,
            crate::Node::Table { end, .. } => end,
            crate::Node::Tag { end, .. } => end,
            crate::Node::Template { end, .. } => end,
            crate::Node::Text { end, .. } => end,
            crate::Node::UnorderedList { end, .. } => end,
        }
    }

    fn start(&self) -> usize {
        match *self {
            crate::Node::Bold { start, .. } => start,
            crate::Node::BoldItalic { start, .. } => start,
            crate::Node::Category { start, .. } => start,
            crate::Node::CharacterEntity { start, .. } => start,
            crate::Node::Comment { start, .. } => start,
            crate::Node::DefinitionList { start, .. } => start,
            crate::Node::EndTag { start, .. } => start,
            crate::Node::ExternalLink { start, .. } => start,
            crate::Node::Heading { start, .. } => start,
            crate::Node::HorizontalDivider { start, .. } => start,
            crate::Node::Image { start, .. } => start,
            crate::Node::Italic { start, .. } => start,
            crate::Node::Link { start, .. } => start,
            crate::Node::MagicWord { start, .. } => start,
            crate::Node::OrderedList { start, .. } => start,
            crate::Node::ParagraphBreak { start, .. } => start,
            crate::Node::Parameter { start, .. } => start,
            crate::Node::Preformatted { start, .. } => start,
            crate::Node::Redirect { start, .. } => start,
            crate::Node::StartTag { start, .. } => start,
            crate::Node::Table { start, .. } => start,
            crate::Node::Tag { start, .. } => start,
            crate::Node::Template { start, .. } => start,
            crate::Node::Text { start, .. } => start,
            crate::Node::UnorderedList { start, .. } => start,
        }
    }
}