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/lexer/classes.rs | 9 +--- src/lexer/comments.rs | 5 +- src/lexer/mod.rs | 143 +++++++++++++++++++++++++++----------------------- src/lexer/numbers.rs | 6 +-- src/lexer/ptr.rs | 11 ++-- src/lexer/strings.rs | 33 ++++++------ 6 files changed, 108 insertions(+), 99 deletions(-) (limited to 'src/lexer') diff --git a/src/lexer/classes.rs b/src/lexer/classes.rs index 4235d2648..7fed008af 100644 --- a/src/lexer/classes.rs +++ b/src/lexer/classes.rs @@ -1,17 +1,12 @@ use unicode_xid::UnicodeXID; pub fn is_ident_start(c: char) -> bool { - (c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z') - || c == '_' + (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c > '\x7f' && UnicodeXID::is_xid_start(c)) } pub fn is_ident_continue(c: char) -> bool { - (c >= 'a' && c <= 'z') - || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') - || c == '_' + (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (c > '\x7f' && UnicodeXID::is_xid_continue(c)) } diff --git a/src/lexer/comments.rs b/src/lexer/comments.rs index 79782cc5b..b70f2c6c6 100644 --- a/src/lexer/comments.rs +++ b/src/lexer/comments.rs @@ -1,6 +1,6 @@ use lexer::ptr::Ptr; -use {SyntaxKind}; +use SyntaxKind; use syntax_kinds::*; pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { @@ -23,7 +23,6 @@ pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option { } } - fn bump_until_eol(ptr: &mut Ptr) { loop { if ptr.next_is('\n') || ptr.next_is('\r') && ptr.nnext_is('\n') { @@ -33,4 +32,4 @@ fn bump_until_eol(ptr: &mut Ptr) { break; } } -} \ No newline at end of file +} diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 842059a42..f62dfc507 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -1,4 +1,4 @@ -use {Token, SyntaxKind}; +use {SyntaxKind, Token}; use syntax_kinds::*; mod ptr; @@ -11,10 +11,11 @@ mod numbers; use self::numbers::scan_number; mod strings; -use self::strings::{is_string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string}; +use self::strings::{is_string_literal_start, scan_byte_char_or_string, scan_char, scan_raw_string, + scan_string}; mod comments; -use self::comments::{scan_shebang, scan_comment}; +use self::comments::{scan_comment, scan_shebang}; pub fn tokenize(text: &str) -> Vec { let mut text = text; @@ -45,10 +46,10 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { match c { '#' => if scan_shebang(ptr) { return SHEBANG; - } + }, '/' => if let Some(kind) = scan_comment(ptr) { return kind; - } + }, _ => (), } @@ -89,79 +90,91 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { '%' => return PERCENT, // Multi-byte tokens. - '.' => return match (ptr.next(), ptr.nnext()) { - (Some('.'), Some('.')) => { - ptr.bump(); - ptr.bump(); - DOTDOTDOT - }, - (Some('.'), Some('=')) => { - ptr.bump(); - ptr.bump(); - DOTDOTEQ - }, - (Some('.'), _) => { - ptr.bump(); - DOTDOT - }, - _ => DOT - }, - ':' => return match ptr.next() { - Some(':') => { - ptr.bump(); - COLONCOLON + '.' => { + return match (ptr.next(), ptr.nnext()) { + (Some('.'), Some('.')) => { + ptr.bump(); + ptr.bump(); + DOTDOTDOT + } + (Some('.'), Some('=')) => { + ptr.bump(); + ptr.bump(); + DOTDOTEQ + } + (Some('.'), _) => { + ptr.bump(); + DOTDOT + } + _ => DOT, } - _ => COLON - }, - '=' => return match ptr.next() { - Some('=') => { - ptr.bump(); - EQEQ + } + ':' => { + return match ptr.next() { + Some(':') => { + ptr.bump(); + COLONCOLON + } + _ => COLON, } - Some('>') => { - ptr.bump(); - FAT_ARROW + } + '=' => { + return match ptr.next() { + Some('=') => { + ptr.bump(); + EQEQ + } + Some('>') => { + ptr.bump(); + FAT_ARROW + } + _ => EQ, } - _ => EQ, - }, - '!' => return match ptr.next() { - Some('=') => { + } + '!' => { + return match ptr.next() { + Some('=') => { + ptr.bump(); + NEQ + } + _ => EXCL, + } + } + '-' => { + return if ptr.next_is('>') { ptr.bump(); - NEQ + THIN_ARROW + } else { + MINUS } - _ => EXCL, - }, - '-' => return if ptr.next_is('>') { - ptr.bump(); - THIN_ARROW - } else { - MINUS - }, + } // If the character is an ident start not followed by another single // quote, then this is a lifetime name: - '\'' => return if ptr.next_is_p(is_ident_start) && !ptr.nnext_is('\'') { - ptr.bump(); - while ptr.next_is_p(is_ident_continue) { + '\'' => { + return if ptr.next_is_p(is_ident_start) && !ptr.nnext_is('\'') { ptr.bump(); + while ptr.next_is_p(is_ident_continue) { + ptr.bump(); + } + // lifetimes shouldn't end with a single quote + // if we find one, then this is an invalid character literal + if ptr.next_is('\'') { + ptr.bump(); + return CHAR; // TODO: error reporting + } + LIFETIME + } else { + scan_char(ptr); + scan_literal_suffix(ptr); + CHAR } - // lifetimes shouldn't end with a single quote - // if we find one, then this is an invalid character literal - if ptr.next_is('\'') { - ptr.bump(); - return CHAR; // TODO: error reporting - } - LIFETIME - } else { - scan_char(ptr); - scan_literal_suffix(ptr); - CHAR - }, + } 'b' => { let kind = scan_byte_char_or_string(ptr); scan_literal_suffix(ptr); - return kind - }, + return kind; + } '"' => { scan_string(ptr); scan_literal_suffix(ptr); diff --git a/src/lexer/numbers.rs b/src/lexer/numbers.rs index 4c7edfe1c..95e42246f 100644 --- a/src/lexer/numbers.rs +++ b/src/lexer/numbers.rs @@ -1,7 +1,7 @@ use lexer::ptr::Ptr; use lexer::classes::*; -use {SyntaxKind}; +use SyntaxKind; use syntax_kinds::*; pub(crate) fn scan_number(c: char, ptr: &mut Ptr) -> SyntaxKind { @@ -49,10 +49,10 @@ fn scan_digits(ptr: &mut Ptr, allow_hex: bool) { '_' | '0'...'9' => { ptr.bump(); } - 'a'...'f' | 'A' ... 'F' if allow_hex => { + 'a'...'f' | 'A'...'F' if allow_hex => { ptr.bump(); } - _ => return + _ => return, } } } diff --git a/src/lexer/ptr.rs b/src/lexer/ptr.rs index ff6ef11fc..99d55b283 100644 --- a/src/lexer/ptr.rs +++ b/src/lexer/ptr.rs @@ -1,4 +1,4 @@ -use {TextUnit}; +use TextUnit; use std::str::Chars; @@ -9,7 +9,10 @@ pub(crate) struct Ptr<'s> { impl<'s> Ptr<'s> { pub fn new(text: &'s str) -> Ptr<'s> { - Ptr { text, len: TextUnit::new(0) } + Ptr { + text, + len: TextUnit::new(0), + } } pub fn into_len(self) -> TextUnit { @@ -53,7 +56,7 @@ impl<'s> Ptr<'s> { match self.next() { Some(c) if pred(c) => { self.bump(); - }, + } _ => return, } } @@ -66,6 +69,6 @@ impl<'s> Ptr<'s> { fn chars(&self) -> Chars { let len: u32 = self.len.into(); - self.text[len as usize ..].chars() + self.text[len as usize..].chars() } } diff --git a/src/lexer/strings.rs b/src/lexer/strings.rs index 116d31760..00a84ec85 100644 --- a/src/lexer/strings.rs +++ b/src/lexer/strings.rs @@ -1,17 +1,17 @@ -use {SyntaxKind}; +use SyntaxKind; use syntax_kinds::*; use lexer::ptr::Ptr; pub(crate) fn is_string_literal_start(c: char, c1: Option, c2: Option) -> bool { match (c, c1, c2) { - ('r', Some('"'), _) | - ('r', Some('#'), _) | - ('b', Some('"'), _) | - ('b', Some('\''), _) | - ('b', Some('r'), Some('"')) | - ('b', Some('r'), Some('#')) => true, - _ => false + ('r', Some('"'), _) + | ('r', Some('#'), _) + | ('b', Some('"'), _) + | ('b', Some('\''), _) + | ('b', Some('r'), Some('"')) + | ('b', Some('r'), Some('#')) => true, + _ => false, } } @@ -50,20 +50,20 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { pub(crate) fn scan_string(ptr: &mut Ptr) { while let Some(c) = ptr.bump() { if c == '"' { - return + return; } } } pub(crate) fn scan_raw_string(ptr: &mut Ptr) { if !ptr.next_is('"') { - return + return; } ptr.bump(); while let Some(c) = ptr.bump() { if c == '"' { - return + return; } } } @@ -71,32 +71,32 @@ pub(crate) fn scan_raw_string(ptr: &mut Ptr) { fn scan_byte(ptr: &mut Ptr) { if ptr.next_is('\'') { ptr.bump(); - return + return; } ptr.bump(); if ptr.next_is('\'') { ptr.bump(); - return + return; } } fn scan_byte_string(ptr: &mut Ptr) { while let Some(c) = ptr.bump() { if c == '"' { - return + return; } } } fn scan_raw_byte_string(ptr: &mut Ptr) { if !ptr.next_is('"') { - return + return; } ptr.bump(); while let Some(c) = ptr.bump() { if c == '"' { - return + return; } } } @@ -105,4 +105,3 @@ fn scan_char_or_byte(ptr: &mut Ptr) { //FIXME: deal with escape sequencies ptr.bump(); } - -- cgit v1.2.3