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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#[cfg(not(target_arch = "wasm32"))]
mod native {
    use std::convert::TryFrom;

    #[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
    pub struct Point {
        pub(crate) inner: tree_sitter::Point,
    }

    impl Point {
        #[inline]
        pub fn new(row: u32, column: u32) -> Self {
            let row = row as usize;
            let column = column as usize;
            tree_sitter::Point { row, column }.into()
        }

        #[inline]
        pub fn column(&self) -> u32 {
            u32::try_from(self.inner.column).unwrap()
        }

        #[inline]
        pub fn row(&self) -> u32 {
            u32::try_from(self.inner.row).unwrap()
        }
    }

    impl std::fmt::Debug for Point {
        fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
            std::fmt::Debug::fmt(&self.inner, fmt)
        }
    }

    impl std::fmt::Display for Point {
        fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
            std::fmt::Display::fmt(&self.inner, fmt)
        }
    }

    impl Default for Point {
        fn default() -> Self {
            let row = Default::default();
            let column = Default::default();
            Self::new(row, column)
        }
    }

    impl From<tree_sitter::Point> for Point {
        #[inline]
        fn from(inner: tree_sitter::Point) -> Self {
            Self { inner }
        }
    }

    impl std::panic::RefUnwindSafe for Point {
    }

    unsafe impl Send for Point {
    }

    unsafe impl Sync for Point {
    }

    impl Unpin for Point {
    }

    impl std::panic::UnwindSafe for Point {
    }
}

#[cfg(not(target_arch = "wasm32"))]
pub use native::*;

#[cfg(target_arch = "wasm32")]
mod wasm {
    #[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
    pub struct Point {
        pub(crate) inner: web_tree_sitter::Point,
    }

    impl Point {
        #[inline]
        pub fn new(row: u32, column: u32) -> Self {
            web_tree_sitter::Point::new(row, column).into()
        }

        #[inline]
        pub fn column(&self) -> u32 {
            self.inner.column()
        }

        #[inline]
        pub fn row(&self) -> u32 {
            self.inner.row()
        }
    }

    impl std::fmt::Debug for Point {
        fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
            std::fmt::Debug::fmt(&self.inner, fmt)
        }
    }

    impl std::fmt::Display for Point {
        fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(fmt, "({}, {})", self.row(), self.column())
        }
    }

    impl Default for Point {
        fn default() -> Self {
            let row = Default::default();
            let column = Default::default();
            Self::new(row, column)
        }
    }

    impl From<web_tree_sitter::Point> for Point {
        #[inline]
        fn from(inner: web_tree_sitter::Point) -> Self {
            Self { inner }
        }
    }

    impl std::panic::RefUnwindSafe for Point {
    }

    unsafe impl Send for Point {
    }

    unsafe impl Sync for Point {
    }

    impl Unpin for Point {
    }

    impl std::panic::UnwindSafe for Point {
    }
}

#[cfg(target_arch = "wasm32")]
pub use wasm::*;