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
use crate::tokenizer::TokenReference;
use derive_more::Display;
use full_moon_derive::{Node, Owned, Visit};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Display, PartialEq, Owned, Node, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[display(fmt = "{}{}", "goto_token", "label_name")]
pub struct Goto<'a> {
#[cfg_attr(feature = "serde", serde(borrow))]
pub(crate) goto_token: TokenReference<'a>,
pub(crate) label_name: TokenReference<'a>,
}
impl<'a> Goto<'a> {
pub fn new(label_name: TokenReference<'a>) -> Self {
Self {
goto_token: TokenReference::symbol("goto").unwrap(),
label_name,
}
}
pub fn goto_token(&self) -> &TokenReference<'a> {
&self.goto_token
}
pub fn label_name(&self) -> &TokenReference<'a> {
&self.label_name
}
pub fn with_goto_token(self, goto_token: TokenReference<'a>) -> Self {
Self { goto_token, ..self }
}
pub fn with_label_name(self, label_name: TokenReference<'a>) -> Self {
Self { label_name, ..self }
}
}
#[derive(Clone, Debug, Display, PartialEq, Owned, Node, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[display(fmt = "{}{}{}", "left_colons", "name", "right_colons")]
pub struct Label<'a> {
#[cfg_attr(feature = "serde", serde(borrow))]
pub(crate) left_colons: TokenReference<'a>,
pub(crate) name: TokenReference<'a>,
pub(crate) right_colons: TokenReference<'a>,
}
impl<'a> Label<'a> {
pub fn new(name: TokenReference<'a>) -> Self {
Self {
left_colons: TokenReference::symbol("::").unwrap(),
name,
right_colons: TokenReference::symbol("::").unwrap(),
}
}
pub fn left_colons(&self) -> &TokenReference<'a> {
&self.left_colons
}
pub fn name(&self) -> &TokenReference<'a> {
&self.name
}
pub fn right_colons(&self) -> &TokenReference<'a> {
&self.right_colons
}
pub fn with_left_colons(self, left_colons: TokenReference<'a>) -> Self {
Self {
left_colons,
..self
}
}
pub fn with_name(self, name: TokenReference<'a>) -> Self {
Self { name, ..self }
}
pub fn with_right_colons(self, right_colons: TokenReference<'a>) -> Self {
Self {
right_colons,
..self
}
}
}