diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_syntax/src/parser_impl | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_syntax/src/parser_impl')
-rw-r--r-- | crates/ra_syntax/src/parser_impl/event.rs | 41 | ||||
-rw-r--r-- | crates/ra_syntax/src/parser_impl/input.rs | 6 |
2 files changed, 11 insertions, 36 deletions
diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 33e10ef85..677876ab5 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs | |||
@@ -86,10 +86,7 @@ pub(crate) enum Event { | |||
86 | 86 | ||
87 | impl Event { | 87 | impl Event { |
88 | pub(crate) fn tombstone() -> Self { | 88 | pub(crate) fn tombstone() -> Self { |
89 | Event::Start { | 89 | Event::Start { kind: TOMBSTONE, forward_parent: None } |
90 | kind: TOMBSTONE, | ||
91 | forward_parent: None, | ||
92 | } | ||
93 | } | 90 | } |
94 | } | 91 | } |
95 | 92 | ||
@@ -109,14 +106,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
109 | tokens: &'a [Token], | 106 | tokens: &'a [Token], |
110 | events: &'a mut [Event], | 107 | events: &'a mut [Event], |
111 | ) -> EventProcessor<'a, S> { | 108 | ) -> EventProcessor<'a, S> { |
112 | EventProcessor { | 109 | EventProcessor { sink, text_pos: 0.into(), text, token_pos: 0, tokens, events } |
113 | sink, | ||
114 | text_pos: 0.into(), | ||
115 | text, | ||
116 | token_pos: 0, | ||
117 | tokens, | ||
118 | events, | ||
119 | } | ||
120 | } | 110 | } |
121 | 111 | ||
122 | /// Generate the syntax tree with the control of events. | 112 | /// Generate the syntax tree with the control of events. |
@@ -125,14 +115,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
125 | 115 | ||
126 | for i in 0..self.events.len() { | 116 | for i in 0..self.events.len() { |
127 | match mem::replace(&mut self.events[i], Event::tombstone()) { | 117 | match mem::replace(&mut self.events[i], Event::tombstone()) { |
128 | Event::Start { | 118 | Event::Start { kind: TOMBSTONE, .. } => (), |
129 | kind: TOMBSTONE, .. | ||
130 | } => (), | ||
131 | 119 | ||
132 | Event::Start { | 120 | Event::Start { kind, forward_parent } => { |
133 | kind, | ||
134 | forward_parent, | ||
135 | } => { | ||
136 | // For events[A, B, C], B is A's forward_parent, C is B's forward_parent, | 121 | // For events[A, B, C], B is A's forward_parent, C is B's forward_parent, |
137 | // in the normal control flow, the parent-child relation: `A -> B -> C`, | 122 | // in the normal control flow, the parent-child relation: `A -> B -> C`, |
138 | // while with the magic forward_parent, it writes: `C <- B <- A`. | 123 | // while with the magic forward_parent, it writes: `C <- B <- A`. |
@@ -145,10 +130,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
145 | idx += fwd as usize; | 130 | idx += fwd as usize; |
146 | // append `A`'s forward_parent `B` | 131 | // append `A`'s forward_parent `B` |
147 | fp = match mem::replace(&mut self.events[idx], Event::tombstone()) { | 132 | fp = match mem::replace(&mut self.events[idx], Event::tombstone()) { |
148 | Event::Start { | 133 | Event::Start { kind, forward_parent } => { |
149 | kind, | ||
150 | forward_parent, | ||
151 | } => { | ||
152 | forward_parents.push(kind); | 134 | forward_parents.push(kind); |
153 | forward_parent | 135 | forward_parent |
154 | } | 136 | } |
@@ -174,10 +156,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
174 | .sum::<TextUnit>(); | 156 | .sum::<TextUnit>(); |
175 | self.leaf(kind, len, n_raw_tokens); | 157 | self.leaf(kind, len, n_raw_tokens); |
176 | } | 158 | } |
177 | Event::Error { msg } => self.sink.error(SyntaxError::new( | 159 | Event::Error { msg } => self |
178 | SyntaxErrorKind::ParseError(msg), | 160 | .sink |
179 | self.text_pos, | 161 | .error(SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos)), |
180 | )), | ||
181 | } | 162 | } |
182 | } | 163 | } |
183 | self.sink | 164 | self.sink |
@@ -189,10 +170,8 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
189 | self.sink.start_branch(kind); | 170 | self.sink.start_branch(kind); |
190 | return; | 171 | return; |
191 | } | 172 | } |
192 | let n_trivias = self.tokens[self.token_pos..] | 173 | let n_trivias = |
193 | .iter() | 174 | self.tokens[self.token_pos..].iter().take_while(|it| it.kind.is_trivia()).count(); |
194 | .take_while(|it| it.kind.is_trivia()) | ||
195 | .count(); | ||
196 | let leading_trivias = &self.tokens[self.token_pos..self.token_pos + n_trivias]; | 175 | let leading_trivias = &self.tokens[self.token_pos..self.token_pos + n_trivias]; |
197 | let mut trivia_end = | 176 | let mut trivia_end = |
198 | self.text_pos + leading_trivias.iter().map(|it| it.len).sum::<TextUnit>(); | 177 | self.text_pos + leading_trivias.iter().map(|it| it.len).sum::<TextUnit>(); |
diff --git a/crates/ra_syntax/src/parser_impl/input.rs b/crates/ra_syntax/src/parser_impl/input.rs index 7fde5b3ab..616a26fdc 100644 --- a/crates/ra_syntax/src/parser_impl/input.rs +++ b/crates/ra_syntax/src/parser_impl/input.rs | |||
@@ -36,11 +36,7 @@ impl<'t> ParserInput<'t> { | |||
36 | len += token.len; | 36 | len += token.len; |
37 | } | 37 | } |
38 | 38 | ||
39 | ParserInput { | 39 | ParserInput { text, start_offsets, tokens } |
40 | text, | ||
41 | start_offsets, | ||
42 | tokens, | ||
43 | } | ||
44 | } | 40 | } |
45 | 41 | ||
46 | /// Get the syntax kind of token at given input position. | 42 | /// Get the syntax kind of token at given input position. |