1
- #[ derive( Clone ) ]
2
- pub ( crate ) struct Child {
3
- pub element : rnix:: SyntaxElement ,
4
- #[ allow( dead_code) ]
5
- pub pos : crate :: position:: Position ,
6
- }
7
-
8
1
pub ( crate ) struct Children {
9
- children : Vec < Child > ,
2
+ children : Vec < rnix :: SyntaxElement > ,
10
3
current_index : usize ,
11
4
}
12
5
@@ -20,44 +13,34 @@ impl Children {
20
13
build_ctx : & crate :: builder:: BuildCtx ,
21
14
node : & rnix:: SyntaxNode ,
22
15
) -> Children {
23
- let mut children = Vec :: new ( ) ;
16
+ let mut children: Vec < rnix :: SyntaxElement > = Vec :: new ( ) ;
24
17
25
18
let mut pos = build_ctx. pos_old . clone ( ) ;
26
19
27
20
for child in node. children_with_tokens ( ) {
28
21
match child {
29
22
rnix:: SyntaxElement :: Node ( node) => {
30
- children. push ( Child {
31
- element : node. clone ( ) . into ( ) ,
32
- pos : pos. clone ( ) ,
33
- } ) ;
23
+ children. push ( node. clone ( ) . into ( ) ) ;
34
24
pos. update ( & node. text ( ) . to_string ( ) ) ;
35
25
}
36
26
rnix:: SyntaxElement :: Token ( token) => {
37
27
match token. kind ( ) {
38
28
rnix:: SyntaxKind :: TOKEN_COMMENT => {
39
- children. push ( Child {
40
- element : crate :: builder:: make_isolated_token (
29
+ children. push (
30
+ crate :: builder:: make_isolated_token (
41
31
rnix:: SyntaxKind :: TOKEN_COMMENT ,
42
32
& dedent_comment ( & pos, token. text ( ) ) ,
43
33
)
44
34
. into ( ) ,
45
- pos : pos. clone ( ) ,
46
- } ) ;
35
+ ) ;
47
36
}
48
37
rnix:: SyntaxKind :: TOKEN_WHITESPACE => {
49
38
if crate :: utils:: count_newlines ( token. text ( ) ) > 0 {
50
- children. push ( Child {
51
- element : token. clone ( ) . into ( ) ,
52
- pos : pos. clone ( ) ,
53
- } ) ;
39
+ children. push ( token. clone ( ) . into ( ) ) ;
54
40
}
55
41
}
56
42
_ => {
57
- children. push ( Child {
58
- element : token. clone ( ) . into ( ) ,
59
- pos : pos. clone ( ) ,
60
- } ) ;
43
+ children. push ( token. clone ( ) . into ( ) ) ;
61
44
}
62
45
}
63
46
@@ -69,21 +52,21 @@ impl Children {
69
52
Children { children, current_index : 0 }
70
53
}
71
54
72
- pub fn get ( & mut self , index : usize ) -> Option < Child > {
55
+ pub fn get ( & mut self , index : usize ) -> Option < rnix :: SyntaxElement > {
73
56
if index + 1 > self . children . len ( ) {
74
57
None
75
58
} else {
76
59
Some ( self . children [ index] . clone ( ) )
77
60
}
78
61
}
79
62
80
- pub fn get_next ( & mut self ) -> Option < Child > {
63
+ pub fn get_next ( & mut self ) -> Option < rnix :: SyntaxElement > {
81
64
let child = self . get ( self . current_index ) ;
82
65
self . move_next ( ) ;
83
66
child
84
67
}
85
68
86
- pub fn get_remaining ( & mut self ) -> Vec < Child > {
69
+ pub fn get_remaining ( & mut self ) -> Vec < rnix :: SyntaxElement > {
87
70
let remaining = & self . children [ self . current_index ..self . children . len ( ) ] ;
88
71
self . current_index = self . children . len ( ) ;
89
72
remaining. to_vec ( )
@@ -93,11 +76,11 @@ impl Children {
93
76
self . current_index < self . children . len ( )
94
77
}
95
78
96
- pub fn peek_next ( & mut self ) -> Option < Child > {
79
+ pub fn peek_next ( & mut self ) -> Option < rnix :: SyntaxElement > {
97
80
self . get ( self . current_index )
98
81
}
99
82
100
- pub fn peek_prev ( & mut self ) -> Option < Child > {
83
+ pub fn peek_prev ( & mut self ) -> Option < rnix :: SyntaxElement > {
101
84
self . get ( self . current_index - 1 )
102
85
}
103
86
@@ -110,38 +93,32 @@ impl Children {
110
93
}
111
94
112
95
pub fn has_comments ( & self ) -> bool {
113
- self . children . iter ( ) . any ( |child| {
114
- child . element . kind ( ) == rnix :: SyntaxKind :: TOKEN_COMMENT
115
- } )
96
+ self . children
97
+ . iter ( )
98
+ . any ( |child| child . kind ( ) == rnix :: SyntaxKind :: TOKEN_COMMENT )
116
99
}
117
100
118
101
pub fn has_newlines ( & self ) -> bool {
119
102
self . children . iter ( ) . any ( |child| {
120
- child. element . kind ( ) == rnix:: SyntaxKind :: TOKEN_WHITESPACE
103
+ child. kind ( ) == rnix:: SyntaxKind :: TOKEN_WHITESPACE
121
104
&& crate :: utils:: has_newlines (
122
- child. element . as_token ( ) . as_ref ( ) . unwrap ( ) . text ( ) ,
105
+ child. as_token ( ) . as_ref ( ) . unwrap ( ) . text ( ) ,
123
106
)
124
107
} )
125
108
}
126
109
127
110
pub fn drain_trivia < F : FnMut ( Trivia ) > ( & mut self , mut callback : F ) {
128
111
while let Some ( child) = self . peek_next ( ) {
129
- match child. element . kind ( ) {
112
+ match child. kind ( ) {
130
113
rnix:: SyntaxKind :: TOKEN_COMMENT => {
131
114
callback ( Trivia :: Comment (
132
- child. element . into_token ( ) . unwrap ( ) . text ( ) . to_string ( ) ,
115
+ child. into_token ( ) . unwrap ( ) . text ( ) . to_string ( ) ,
133
116
) ) ;
134
117
self . move_next ( ) ;
135
118
}
136
119
rnix:: SyntaxKind :: TOKEN_WHITESPACE => {
137
120
callback ( Trivia :: Whitespace (
138
- child
139
- . element
140
- . as_token ( )
141
- . as_ref ( )
142
- . unwrap ( )
143
- . text ( )
144
- . to_string ( ) ,
121
+ child. as_token ( ) . as_ref ( ) . unwrap ( ) . text ( ) . to_string ( ) ,
145
122
) ) ;
146
123
self . move_next ( ) ;
147
124
}
0 commit comments