From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_syntax/src/parser_impl/event.rs | 41 ++++++++----------------------- crates/ra_syntax/src/parser_impl/input.rs | 6 +---- 2 files changed, 11 insertions(+), 36 deletions(-) (limited to 'crates/ra_syntax/src/parser_impl') 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 { impl Event { pub(crate) fn tombstone() -> Self { - Event::Start { - kind: TOMBSTONE, - forward_parent: None, - } + Event::Start { kind: TOMBSTONE, forward_parent: None } } } @@ -109,14 +106,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { tokens: &'a [Token], events: &'a mut [Event], ) -> EventProcessor<'a, S> { - EventProcessor { - sink, - text_pos: 0.into(), - text, - token_pos: 0, - tokens, - events, - } + EventProcessor { sink, text_pos: 0.into(), text, token_pos: 0, tokens, events } } /// Generate the syntax tree with the control of events. @@ -125,14 +115,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { for i in 0..self.events.len() { match mem::replace(&mut self.events[i], Event::tombstone()) { - Event::Start { - kind: TOMBSTONE, .. - } => (), + Event::Start { kind: TOMBSTONE, .. } => (), - Event::Start { - kind, - forward_parent, - } => { + Event::Start { kind, forward_parent } => { // For events[A, B, C], B is A's forward_parent, C is B's forward_parent, // in the normal control flow, the parent-child relation: `A -> B -> C`, // while with the magic forward_parent, it writes: `C <- B <- A`. @@ -145,10 +130,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { idx += fwd as usize; // append `A`'s forward_parent `B` fp = match mem::replace(&mut self.events[idx], Event::tombstone()) { - Event::Start { - kind, - forward_parent, - } => { + Event::Start { kind, forward_parent } => { forward_parents.push(kind); forward_parent } @@ -174,10 +156,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { .sum::(); self.leaf(kind, len, n_raw_tokens); } - Event::Error { msg } => self.sink.error(SyntaxError::new( - SyntaxErrorKind::ParseError(msg), - self.text_pos, - )), + Event::Error { msg } => self + .sink + .error(SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos)), } } self.sink @@ -189,10 +170,8 @@ impl<'a, S: Sink> EventProcessor<'a, S> { self.sink.start_branch(kind); return; } - let n_trivias = self.tokens[self.token_pos..] - .iter() - .take_while(|it| it.kind.is_trivia()) - .count(); + let n_trivias = + self.tokens[self.token_pos..].iter().take_while(|it| it.kind.is_trivia()).count(); let leading_trivias = &self.tokens[self.token_pos..self.token_pos + n_trivias]; let mut trivia_end = self.text_pos + leading_trivias.iter().map(|it| it.len).sum::(); 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> { len += token.len; } - ParserInput { - text, - start_offsets, - tokens, - } + ParserInput { text, start_offsets, tokens } } /// Get the syntax kind of token at given input position. -- cgit v1.2.3