From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/ra_syntax/src/parser_impl/event.rs | 54 ++++++++++++++++++------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'crates/ra_syntax/src/parser_impl/event.rs') diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 928d2cc7a..79fa21389 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -7,14 +7,14 @@ //! tree builder: the parser produces a stream of events like //! `start node`, `finish node`, and `FileBuilder` converts //! this stream to a real tree. -use std::mem; use crate::{ - TextUnit, TextRange, SmolStr, lexer::Token, parser_impl::Sink, + SmolStr, SyntaxKind::{self, *}, + TextRange, TextUnit, }; - +use std::mem; /// `Parser` produces a flat list of `Event`s. /// They are converted to a tree-structure in @@ -89,20 +89,28 @@ pub(super) struct EventProcessor<'a, S: Sink> { } impl<'a, S: Sink> EventProcessor<'a, S> { - pub(super) fn new(sink: S, text: &'a str, tokens: &'a[Token], events: &'a mut [Event]) -> EventProcessor<'a, S> { + pub(super) fn new( + sink: S, + text: &'a str, + tokens: &'a [Token], + events: &'a mut [Event], + ) -> EventProcessor<'a, S> { EventProcessor { sink, text_pos: 0.into(), text, token_pos: 0, tokens, - events + events, } } pub(super) fn process(mut self) -> S { fn tombstone() -> Event { - Event::Start { kind: TOMBSTONE, forward_parent: None } + Event::Start { + kind: TOMBSTONE, + forward_parent: None, + } } let mut forward_parents = Vec::new(); @@ -112,7 +120,10 @@ impl<'a, S: Sink> EventProcessor<'a, S> { kind: TOMBSTONE, .. } => (), - Event::Start { kind, forward_parent } => { + Event::Start { + kind, + forward_parent, + } => { forward_parents.push(kind); let mut idx = i; let mut fp = forward_parent; @@ -125,7 +136,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { } => { forward_parents.push(kind); forward_parent - }, + } _ => unreachable!(), }; } @@ -136,7 +147,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { Event::Finish => { let last = i == self.events.len() - 1; self.finish(last); - }, + } Event::Token { kind, n_raw_tokens } => { self.eat_ws(); let n_raw_tokens = n_raw_tokens as usize; @@ -162,19 +173,16 @@ impl<'a, S: Sink> EventProcessor<'a, S> { .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::(); + let mut trivia_end = + self.text_pos + leading_trivias.iter().map(|it| it.len).sum::(); let n_attached_trivias = { - let leading_trivias = leading_trivias.iter().rev() - .map(|it| { - let next_end = trivia_end - it.len; - let range = TextRange::from_to(next_end, trivia_end); - trivia_end = next_end; - (it.kind, &self.text[range]) - }); + let leading_trivias = leading_trivias.iter().rev().map(|it| { + let next_end = trivia_end - it.len; + let range = TextRange::from_to(next_end, trivia_end); + trivia_end = next_end; + (it.kind, &self.text[range]) + }); n_attached_trivias(kind, leading_trivias) }; self.eat_n_trivias(n_trivias - n_attached_trivias); @@ -215,7 +223,10 @@ impl<'a, S: Sink> EventProcessor<'a, S> { } } -fn n_attached_trivias<'a>(kind: SyntaxKind, trivias: impl Iterator) -> usize { +fn n_attached_trivias<'a>( + kind: SyntaxKind, + trivias: impl Iterator, +) -> usize { match kind { STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | MODULE => { let mut res = 0; @@ -236,5 +247,4 @@ fn n_attached_trivias<'a>(kind: SyntaxKind, trivias: impl Iterator 0, } - } -- cgit v1.2.3