Skip to content

Commit 14a7ffd

Browse files
committed
Enforce rustfmt format
1 parent da9bfac commit 14a7ffd

26 files changed

+291
-266
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
language: rust
22
rust:
33
- stable
4+
5+
matrix:
6+
include:
7+
- rust: nightly-2018-01-26
8+
before_script:
9+
- rustup component add rustfmt-preview
10+
script:
11+
- cargo fmt -- --write-mode=diff
12+
13+
script:
14+
- cargo test

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ file = "1.1.1"
1313
ron = "0.1.5"
1414

1515
[dev-dependencies]
16-
testutils = { path = "./tests/testutils" }
16+
testutils = { path = "./tests/testutils" }

rustfmt.toml

Whitespace-only changes.

src/bin/gen.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ extern crate serde;
22
#[macro_use]
33
extern crate serde_derive;
44

5-
extern crate ron;
65
extern crate file;
6+
extern crate ron;
77

88
use std::path::PathBuf;
99
use std::fmt::Write;
@@ -33,11 +33,12 @@ impl Grammar {
3333
acc.push_str("use tree::{SyntaxKind, SyntaxInfo};\n");
3434
acc.push_str("\n");
3535

36-
let syntax_kinds: Vec<String> =
37-
self.keywords.iter().map(|kw| kw_token(kw))
38-
.chain(self.tokens.iter().cloned())
39-
.chain(self.nodes.iter().cloned())
40-
.collect();
36+
let syntax_kinds: Vec<String> = self.keywords
37+
.iter()
38+
.map(|kw| kw_token(kw))
39+
.chain(self.tokens.iter().cloned())
40+
.chain(self.nodes.iter().cloned())
41+
.collect();
4142

4243
for (idx, kind) in syntax_kinds.iter().enumerate() {
4344
let sname = scream(kind);
@@ -48,7 +49,11 @@ impl Grammar {
4849
).unwrap();
4950
}
5051
acc.push_str("\n");
51-
write!(acc, "static INFOS: [SyntaxInfo; {}] = [\n", syntax_kinds.len()).unwrap();
52+
write!(
53+
acc,
54+
"static INFOS: [SyntaxInfo; {}] = [\n",
55+
syntax_kinds.len()
56+
).unwrap();
5257
for kind in syntax_kinds.iter() {
5358
let sname = scream(kind);
5459
write!(
@@ -91,4 +96,4 @@ fn scream(word: &str) -> String {
9196

9297
fn kw_token(keyword: &str) -> String {
9398
format!("{}_KW", scream(keyword))
94-
}
99+
}

src/bin/parse-rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate libsyntax2;
22

33
use std::io::Read;
44

5-
use libsyntax2::{tokenize, parse};
5+
use libsyntax2::{parse, tokenize};
66
use libsyntax2::utils::dump_tree;
77

88
fn main() {

src/lexer/classes.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use unicode_xid::UnicodeXID;
22

33
pub fn is_ident_start(c: char) -> bool {
4-
(c >= 'a' && c <= 'z')
5-
|| (c >= 'A' && c <= 'Z')
6-
|| c == '_'
4+
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
75
|| (c > '\x7f' && UnicodeXID::is_xid_start(c))
86
}
97

108
pub fn is_ident_continue(c: char) -> bool {
11-
(c >= 'a' && c <= 'z')
12-
|| (c >= 'A' && c <= 'Z')
13-
|| (c >= '0' && c <= '9')
14-
|| c == '_'
9+
(c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'
1510
|| (c > '\x7f' && UnicodeXID::is_xid_continue(c))
1611
}
1712

src/lexer/comments.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use lexer::ptr::Ptr;
22

3-
use {SyntaxKind};
3+
use SyntaxKind;
44
use syntax_kinds::*;
55

66
pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
@@ -23,7 +23,6 @@ pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
2323
}
2424
}
2525

26-
2726
fn bump_until_eol(ptr: &mut Ptr) {
2827
loop {
2928
if ptr.next_is('\n') || ptr.next_is('\r') && ptr.nnext_is('\n') {
@@ -33,4 +32,4 @@ fn bump_until_eol(ptr: &mut Ptr) {
3332
break;
3433
}
3534
}
36-
}
35+
}

src/lexer/mod.rs

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use {Token, SyntaxKind};
1+
use {SyntaxKind, Token};
22
use syntax_kinds::*;
33

44
mod ptr;
@@ -11,10 +11,11 @@ mod numbers;
1111
use self::numbers::scan_number;
1212

1313
mod strings;
14-
use self::strings::{is_string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string};
14+
use self::strings::{is_string_literal_start, scan_byte_char_or_string, scan_char, scan_raw_string,
15+
scan_string};
1516

1617
mod comments;
17-
use self::comments::{scan_shebang, scan_comment};
18+
use self::comments::{scan_comment, scan_shebang};
1819

1920
pub fn tokenize(text: &str) -> Vec<Token> {
2021
let mut text = text;
@@ -45,10 +46,10 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
4546
match c {
4647
'#' => if scan_shebang(ptr) {
4748
return SHEBANG;
48-
}
49+
},
4950
'/' => if let Some(kind) = scan_comment(ptr) {
5051
return kind;
51-
}
52+
},
5253
_ => (),
5354
}
5455

@@ -89,79 +90,91 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
8990
'%' => return PERCENT,
9091

9192
// Multi-byte tokens.
92-
'.' => return match (ptr.next(), ptr.nnext()) {
93-
(Some('.'), Some('.')) => {
94-
ptr.bump();
95-
ptr.bump();
96-
DOTDOTDOT
97-
},
98-
(Some('.'), Some('=')) => {
99-
ptr.bump();
100-
ptr.bump();
101-
DOTDOTEQ
102-
},
103-
(Some('.'), _) => {
104-
ptr.bump();
105-
DOTDOT
106-
},
107-
_ => DOT
108-
},
109-
':' => return match ptr.next() {
110-
Some(':') => {
111-
ptr.bump();
112-
COLONCOLON
93+
'.' => {
94+
return match (ptr.next(), ptr.nnext()) {
95+
(Some('.'), Some('.')) => {
96+
ptr.bump();
97+
ptr.bump();
98+
DOTDOTDOT
99+
}
100+
(Some('.'), Some('=')) => {
101+
ptr.bump();
102+
ptr.bump();
103+
DOTDOTEQ
104+
}
105+
(Some('.'), _) => {
106+
ptr.bump();
107+
DOTDOT
108+
}
109+
_ => DOT,
113110
}
114-
_ => COLON
115-
},
116-
'=' => return match ptr.next() {
117-
Some('=') => {
118-
ptr.bump();
119-
EQEQ
111+
}
112+
':' => {
113+
return match ptr.next() {
114+
Some(':') => {
115+
ptr.bump();
116+
COLONCOLON
117+
}
118+
_ => COLON,
120119
}
121-
Some('>') => {
122-
ptr.bump();
123-
FAT_ARROW
120+
}
121+
'=' => {
122+
return match ptr.next() {
123+
Some('=') => {
124+
ptr.bump();
125+
EQEQ
126+
}
127+
Some('>') => {
128+
ptr.bump();
129+
FAT_ARROW
130+
}
131+
_ => EQ,
124132
}
125-
_ => EQ,
126-
},
127-
'!' => return match ptr.next() {
128-
Some('=') => {
133+
}
134+
'!' => {
135+
return match ptr.next() {
136+
Some('=') => {
137+
ptr.bump();
138+
NEQ
139+
}
140+
_ => EXCL,
141+
}
142+
}
143+
'-' => {
144+
return if ptr.next_is('>') {
129145
ptr.bump();
130-
NEQ
146+
THIN_ARROW
147+
} else {
148+
MINUS
131149
}
132-
_ => EXCL,
133-
},
134-
'-' => return if ptr.next_is('>') {
135-
ptr.bump();
136-
THIN_ARROW
137-
} else {
138-
MINUS
139-
},
150+
}
140151

141152
// If the character is an ident start not followed by another single
142153
// quote, then this is a lifetime name:
143-
'\'' => return if ptr.next_is_p(is_ident_start) && !ptr.nnext_is('\'') {
144-
ptr.bump();
145-
while ptr.next_is_p(is_ident_continue) {
146-
ptr.bump();
147-
}
148-
// lifetimes shouldn't end with a single quote
149-
// if we find one, then this is an invalid character literal
150-
if ptr.next_is('\'') {
154+
'\'' => {
155+
return if ptr.next_is_p(is_ident_start) && !ptr.nnext_is('\'') {
151156
ptr.bump();
152-
return CHAR; // TODO: error reporting
153-
}
154-
LIFETIME
155-
} else {
156-
scan_char(ptr);
157-
scan_literal_suffix(ptr);
158-
CHAR
159-
},
157+
while ptr.next_is_p(is_ident_continue) {
158+
ptr.bump();
159+
}
160+
// lifetimes shouldn't end with a single quote
161+
// if we find one, then this is an invalid character literal
162+
if ptr.next_is('\'') {
163+
ptr.bump();
164+
return CHAR; // TODO: error reporting
165+
}
166+
LIFETIME
167+
} else {
168+
scan_char(ptr);
169+
scan_literal_suffix(ptr);
170+
CHAR
171+
};
172+
}
160173
'b' => {
161174
let kind = scan_byte_char_or_string(ptr);
162175
scan_literal_suffix(ptr);
163-
return kind
164-
},
176+
return kind;
177+
}
165178
'"' => {
166179
scan_string(ptr);
167180
scan_literal_suffix(ptr);

src/lexer/numbers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use lexer::ptr::Ptr;
22
use lexer::classes::*;
33

4-
use {SyntaxKind};
4+
use SyntaxKind;
55
use syntax_kinds::*;
66

77
pub(crate) fn scan_number(c: char, ptr: &mut Ptr) -> SyntaxKind {
@@ -49,10 +49,10 @@ fn scan_digits(ptr: &mut Ptr, allow_hex: bool) {
4949
'_' | '0'...'9' => {
5050
ptr.bump();
5151
}
52-
'a'...'f' | 'A' ... 'F' if allow_hex => {
52+
'a'...'f' | 'A'...'F' if allow_hex => {
5353
ptr.bump();
5454
}
55-
_ => return
55+
_ => return,
5656
}
5757
}
5858
}

src/lexer/ptr.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use {TextUnit};
1+
use TextUnit;
22

33
use std::str::Chars;
44

@@ -9,7 +9,10 @@ pub(crate) struct Ptr<'s> {
99

1010
impl<'s> Ptr<'s> {
1111
pub fn new(text: &'s str) -> Ptr<'s> {
12-
Ptr { text, len: TextUnit::new(0) }
12+
Ptr {
13+
text,
14+
len: TextUnit::new(0),
15+
}
1316
}
1417

1518
pub fn into_len(self) -> TextUnit {
@@ -53,7 +56,7 @@ impl<'s> Ptr<'s> {
5356
match self.next() {
5457
Some(c) if pred(c) => {
5558
self.bump();
56-
},
59+
}
5760
_ => return,
5861
}
5962
}
@@ -66,6 +69,6 @@ impl<'s> Ptr<'s> {
6669

6770
fn chars(&self) -> Chars {
6871
let len: u32 = self.len.into();
69-
self.text[len as usize ..].chars()
72+
self.text[len as usize..].chars()
7073
}
7174
}

0 commit comments

Comments
 (0)