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
use crate::{
node::{Node, Tokens},
private::Sealed,
tokenizer::{Position, TokenReference},
};
use std::borrow::Cow;
use full_moon_derive::{Owned, Visit};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Owned, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct ContainedSpan<'a> {
#[cfg_attr(feature = "serde", serde(borrow))]
pub(crate) tokens: (Cow<'a, TokenReference<'a>>, Cow<'a, TokenReference<'a>>),
}
impl<'a> ContainedSpan<'a> {
pub fn new(start: Cow<'a, TokenReference<'a>>, end: Cow<'a, TokenReference<'a>>) -> Self {
Self {
tokens: (start, end),
}
}
pub fn tokens(&self) -> (&TokenReference<'a>, &TokenReference<'a>) {
(&self.tokens.0, &self.tokens.1)
}
}
impl<'a> Node<'a> for ContainedSpan<'a> {
fn start_position(&self) -> Option<Position> {
self.tokens.0.start_position()
}
fn end_position(&self) -> Option<Position> {
self.tokens.1.end_position()
}
fn similar(&self, other: &Self) -> bool {
self.tokens.0.similar(&other.tokens.0) && self.tokens.1.similar(&other.tokens.1)
}
fn tokens<'b>(&'b self) -> Tokens<'a, 'b> {
self.tokens.tokens()
}
}
impl<'a> Sealed for ContainedSpan<'a> {}