From 4de3c97b2afea55834cd16368f950133459d8c73 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sat, 27 Jan 2018 18:31:23 -0500 Subject: Enforce rustfmt format --- src/parser/event_parser/grammar/attributes.rs | 15 +++------ src/parser/event_parser/grammar/expressions.rs | 8 ++--- src/parser/event_parser/grammar/items.rs | 38 ++++++--------------- src/parser/event_parser/grammar/mod.rs | 25 ++++++-------- src/parser/event_parser/grammar/paths.rs | 4 +-- src/parser/event_parser/grammar/types.rs | 2 +- src/parser/event_parser/mod.rs | 2 +- src/parser/event_parser/parser.rs | 46 ++++++++++++++++++-------- src/parser/mod.rs | 30 +++++++++-------- 9 files changed, 80 insertions(+), 90 deletions(-) (limited to 'src/parser') diff --git a/src/parser/event_parser/grammar/attributes.rs b/src/parser/event_parser/grammar/attributes.rs index 045840059..8bf04afce 100644 --- a/src/parser/event_parser/grammar/attributes.rs +++ b/src/parser/event_parser/grammar/attributes.rs @@ -12,8 +12,7 @@ pub(super) fn outer_attributes(p: &mut Parser) { } } - -fn attribute(p: &mut Parser, inner: bool){ +fn attribute(p: &mut Parser, inner: bool) { let attr = p.start(); assert!(p.at(POUND)); p.bump(); @@ -38,9 +37,7 @@ fn meta_item(p: &mut Parser) { EQ => { p.bump(); if !expressions::literal(p) { - p.error() - .message("expected literal") - .emit(); + p.error().message("expected literal").emit(); } } L_PAREN => meta_item_arg_list(p), @@ -48,9 +45,7 @@ fn meta_item(p: &mut Parser) { } meta_item.complete(p, META_ITEM); } else { - p.error() - .message("expected attribute value") - .emit() + p.error().message("expected attribute value").emit() } } @@ -73,8 +68,8 @@ fn meta_item_arg_list(p: &mut Parser) { p.error().message(message).emit(); p.bump(); err.complete(p, ERROR); - continue - } + continue; + }, } if !p.at(R_PAREN) { p.expect(COMMA); diff --git a/src/parser/event_parser/grammar/expressions.rs b/src/parser/event_parser/grammar/expressions.rs index a943b8c81..c81dc6c35 100644 --- a/src/parser/event_parser/grammar/expressions.rs +++ b/src/parser/event_parser/grammar/expressions.rs @@ -2,15 +2,13 @@ use super::*; pub(super) fn literal(p: &mut Parser) -> bool { match p.current() { - TRUE_KW | FALSE_KW | - INT_NUMBER | FLOAT_NUMBER | - BYTE | CHAR | - STRING | RAW_STRING | BYTE_STRING | RAW_BYTE_STRING => { + TRUE_KW | FALSE_KW | INT_NUMBER | FLOAT_NUMBER | BYTE | CHAR | STRING | RAW_STRING + | BYTE_STRING | RAW_BYTE_STRING => { let lit = p.start(); p.bump(); lit.complete(p, LITERAL); true } - _ => false + _ => false, } } diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 7706690cc..e569e5047 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -7,15 +7,8 @@ pub(super) fn mod_contents(p: &mut Parser) { } } -pub(super) const ITEM_FIRST: TokenSet = token_set![ - EXTERN_KW, - MOD_KW, - USE_KW, - STRUCT_KW, - FN_KW, - PUB_KW, - POUND, -]; +pub(super) const ITEM_FIRST: TokenSet = + token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; fn item(p: &mut Parser) { let item = p.start(); @@ -48,7 +41,7 @@ fn item(p: &mut Parser) { let message = if err_token == SEMI { //TODO: if the item is incomplete, this message is misleading "expected item, found `;`\n\ - consider removing this semicolon" + consider removing this semicolon" } else { "expected item" }; @@ -76,10 +69,9 @@ fn struct_item(p: &mut Parser) { return; } L_CURLY => named_fields(p), - _ => { //TODO: special case `(` error message - p.error() - .message("expected `;` or `{`") - .emit(); + _ => { + //TODO: special case `(` error message + p.error().message("expected `;` or `{`").emit(); return; } } @@ -94,9 +86,7 @@ fn struct_item(p: &mut Parser) { p.expect(SEMI); } _ => { - p.error() - .message("expected `;`, `{`, or `(`") - .emit(); + p.error().message("expected `;`, `{`, or `(`").emit(); return; } } @@ -177,7 +167,7 @@ fn use_item(p: &mut Parser) { use_tree(p); p.expect(SEMI); - fn use_tree(p: &mut Parser){ + fn use_tree(p: &mut Parser) { let la = p.raw_lookahead(1); let m = p.start(); match (p.current(), la) { @@ -209,9 +199,7 @@ fn use_item(p: &mut Parser) { L_CURLY => nested_trees(p), _ => { // is this unreachable? - p.error() - .message("expected `{` or `*`") - .emit(); + p.error().message("expected `{` or `*`").emit(); } } } @@ -222,7 +210,7 @@ fn use_item(p: &mut Parser) { m.abandon(p); p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); return; - }, + } } m.complete(p, USE_TREE); } @@ -240,13 +228,9 @@ fn use_item(p: &mut Parser) { } } - fn fn_item(p: &mut Parser) { assert!(p.at(FN_KW)); p.bump(); - p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) - && p.curly_block(|_| ()); + p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ()); } - - diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 6e4f72096..c6ab1fbe2 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -1,5 +1,5 @@ use super::parser::{Parser, TokenSet}; -use {SyntaxKind}; +use SyntaxKind; use tree::EOF; use syntax_kinds::*; @@ -29,7 +29,7 @@ fn visibility(p: &mut Parser) { } p.expect(R_PAREN); } - _ => () + _ => (), } } vis.complete(p, VISIBILITY); @@ -53,9 +53,7 @@ impl<'p> Parser<'p> { fn err_and_bump(&mut self, message: &str) { let err = self.start(); - self.error() - .message(message) - .emit(); + self.error().message(message).emit(); self.bump(); err.complete(self, ERROR); } @@ -65,15 +63,16 @@ impl<'p> Parser<'p> { self.bump(); true } else { - self.error() - .message(format!("expected {:?}", kind)) - .emit(); + self.error().message(format!("expected {:?}", kind)).emit(); false } } fn eat(&mut self, kind: SyntaxKind) -> bool { - self.current() == kind && { self.bump(); true } + self.current() == kind && { + self.bump(); + true + } } } @@ -94,8 +93,7 @@ impl Lookahead for SyntaxKind { impl Lookahead for [SyntaxKind; 2] { fn is_ahead(self, p: &Parser) -> bool { - p.current() == self[0] - && p.raw_lookahead(1) == self[1] + p.current() == self[0] && p.raw_lookahead(1) == self[1] } fn consume(p: &mut Parser) { @@ -106,9 +104,7 @@ impl Lookahead for [SyntaxKind; 2] { impl Lookahead for [SyntaxKind; 3] { fn is_ahead(self, p: &Parser) -> bool { - p.current() == self[0] - && p.raw_lookahead(1) == self[1] - && p.raw_lookahead(2) == self[2] + p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] } fn consume(p: &mut Parser) { @@ -130,5 +126,4 @@ impl<'a> Lookahead for AnyOf<'a> { fn consume(p: &mut Parser) { p.bump(); } - } diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index b58c59aef..4e028073a 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -34,9 +34,7 @@ fn path_segment(p: &mut Parser, first: bool) { p.bump(); } _ => { - p.error() - .message("expected identifier") - .emit(); + p.error().message("expected identifier").emit(); } }; segment.complete(p, PATH_SEGMENT); diff --git a/src/parser/event_parser/grammar/types.rs b/src/parser/event_parser/grammar/types.rs index c431643d7..1a3d44a0a 100644 --- a/src/parser/event_parser/grammar/types.rs +++ b/src/parser/event_parser/grammar/types.rs @@ -2,4 +2,4 @@ use super::*; pub(super) fn type_ref(p: &mut Parser) { p.expect(IDENT); -} \ No newline at end of file +} diff --git a/src/parser/event_parser/mod.rs b/src/parser/event_parser/mod.rs index b9ffded9d..65aea017b 100644 --- a/src/parser/event_parser/mod.rs +++ b/src/parser/event_parser/mod.rs @@ -1,4 +1,4 @@ -use {Token, SyntaxKind}; +use {SyntaxKind, Token}; #[macro_use] mod parser; diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index 18231e493..5ba3071cb 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs @@ -1,17 +1,19 @@ -use {Token, SyntaxKind, TextUnit}; +use {SyntaxKind, TextUnit, Token}; use super::Event; use super::super::is_insignificant; -use syntax_kinds::{L_CURLY, R_CURLY, ERROR}; +use syntax_kinds::{ERROR, L_CURLY, R_CURLY}; use tree::{EOF, TOMBSTONE}; pub(crate) struct Marker { - pos: u32 + pos: u32, } impl Marker { pub fn complete(self, p: &mut Parser, kind: SyntaxKind) -> CompleteMarker { match self.event(p) { - &mut Event::Start { kind: ref mut slot, ..} => { + &mut Event::Start { + kind: ref mut slot, .. + } => { *slot = kind; } _ => unreachable!(), @@ -26,8 +28,11 @@ impl Marker { let idx = self.pos as usize; if idx == p.events.len() - 1 { match p.events.pop() { - Some(Event::Start { kind: TOMBSTONE, forward_parent: None }) => (), - _ => unreachable!() + Some(Event::Start { + kind: TOMBSTONE, + forward_parent: None, + }) => (), + _ => unreachable!(), } } ::std::mem::forget(self); @@ -51,14 +56,17 @@ impl Drop for Marker { } pub(crate) struct CompleteMarker { - pos: u32 + pos: u32, } impl CompleteMarker { pub(crate) fn precede(self, p: &mut Parser) -> Marker { let m = p.start(); match p.events[self.pos as usize] { - Event::Start { ref mut forward_parent, ..} => { + Event::Start { + ref mut forward_parent, + .. + } => { *forward_parent = Some(m.pos - self.pos); } _ => unreachable!(), @@ -68,7 +76,7 @@ impl CompleteMarker { } pub(crate) struct TokenSet { - pub tokens: &'static [SyntaxKind] + pub tokens: &'static [SyntaxKind], } impl TokenSet { @@ -90,7 +98,6 @@ macro_rules! token_set { }; } - pub(crate) struct Parser<'t> { #[allow(unused)] text: &'t str, @@ -150,8 +157,13 @@ impl<'t> Parser<'t> { } pub(crate) fn start(&mut self) -> Marker { - let m = Marker { pos: self.events.len() as u32 }; - self.event(Event::Start { kind: TOMBSTONE, forward_parent: None }); + let m = Marker { + pos: self.events.len() as u32, + }; + self.event(Event::Start { + kind: TOMBSTONE, + forward_parent: None, + }); m } @@ -168,7 +180,10 @@ impl<'t> Parser<'t> { _ => (), } self.pos += 1; - self.event(Event::Token { kind, n_raw_tokens: 1 }); + self.event(Event::Token { + kind, + n_raw_tokens: 1, + }); kind } @@ -210,7 +225,10 @@ pub(crate) struct ErrorBuilder<'p, 't: 'p> { impl<'t, 'p> ErrorBuilder<'p, 't> { fn new(parser: &'p mut Parser<'t>) -> Self { - ErrorBuilder { message: None, parser } + ErrorBuilder { + message: None, + parser, + } } pub fn message>(mut self, m: M) -> Self { diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 5ec4b8e93..d04ed1e75 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,4 +1,4 @@ -use {Token, File, FileBuilder, Sink, SyntaxKind}; +use {File, FileBuilder, Sink, SyntaxKind, Token}; use syntax_kinds::*; use tree::TOMBSTONE; @@ -6,17 +6,12 @@ use tree::TOMBSTONE; mod event_parser; use self::event_parser::Event; - pub fn parse(text: String, tokens: &[Token]) -> File { let events = event_parser::parse(&text, tokens); from_events_to_file(text, tokens, events) } -fn from_events_to_file( - text: String, - tokens: &[Token], - events: Vec, -) -> File { +fn from_events_to_file(text: String, tokens: &[Token], events: Vec) -> File { let mut builder = FileBuilder::new(text); let mut idx = 0; @@ -26,18 +21,23 @@ fn from_events_to_file( for (i, event) in events.iter().enumerate() { if holes.last() == Some(&i) { holes.pop(); - continue + continue; } match event { - &Event::Start { kind: TOMBSTONE, .. } => (), + &Event::Start { + kind: TOMBSTONE, .. + } => (), &Event::Start { .. } => { forward_parents.clear(); let mut idx = i; loop { let (kind, fwd) = match events[idx] { - Event::Start { kind, forward_parent } => (kind, forward_parent), + Event::Start { + kind, + forward_parent, + } => (kind, forward_parent), _ => unreachable!(), }; forward_parents.push((idx, kind)); @@ -64,8 +64,11 @@ fn from_events_to_file( } } builder.finish_internal() - }, - &Event::Token { kind: _, mut n_raw_tokens } => loop { + } + &Event::Token { + kind: _, + mut n_raw_tokens, + } => loop { let token = tokens[idx]; if !is_insignificant(token.kind) { n_raw_tokens -= 1; @@ -76,8 +79,7 @@ fn from_events_to_file( break; } }, - &Event::Error { ref message } => - builder.error().message(message.clone()).emit(), + &Event::Error { ref message } => builder.error().message(message.clone()).emit(), } } builder.finish() -- cgit v1.2.3