diff options
author | Christopher Durham <[email protected]> | 2018-01-27 23:31:23 +0000 |
---|---|---|
committer | Christopher Durham <[email protected]> | 2018-01-27 23:31:23 +0000 |
commit | 4de3c97b2afea55834cd16368f950133459d8c73 (patch) | |
tree | 9091b5dc1b116e5cbb47a535ffa922e66776c800 /src/parser | |
parent | 357cd3358167daa38f3ff34d225e1501faff6015 (diff) |
Enforce rustfmt format
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/event_parser/grammar/attributes.rs | 15 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/expressions.rs | 8 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 38 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 25 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/paths.rs | 4 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/types.rs | 2 | ||||
-rw-r--r-- | src/parser/event_parser/mod.rs | 2 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 46 | ||||
-rw-r--r-- | src/parser/mod.rs | 30 |
9 files changed, 80 insertions, 90 deletions
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) { | |||
12 | } | 12 | } |
13 | } | 13 | } |
14 | 14 | ||
15 | 15 | fn attribute(p: &mut Parser, inner: bool) { | |
16 | fn attribute(p: &mut Parser, inner: bool){ | ||
17 | let attr = p.start(); | 16 | let attr = p.start(); |
18 | assert!(p.at(POUND)); | 17 | assert!(p.at(POUND)); |
19 | p.bump(); | 18 | p.bump(); |
@@ -38,9 +37,7 @@ fn meta_item(p: &mut Parser) { | |||
38 | EQ => { | 37 | EQ => { |
39 | p.bump(); | 38 | p.bump(); |
40 | if !expressions::literal(p) { | 39 | if !expressions::literal(p) { |
41 | p.error() | 40 | p.error().message("expected literal").emit(); |
42 | .message("expected literal") | ||
43 | .emit(); | ||
44 | } | 41 | } |
45 | } | 42 | } |
46 | L_PAREN => meta_item_arg_list(p), | 43 | L_PAREN => meta_item_arg_list(p), |
@@ -48,9 +45,7 @@ fn meta_item(p: &mut Parser) { | |||
48 | } | 45 | } |
49 | meta_item.complete(p, META_ITEM); | 46 | meta_item.complete(p, META_ITEM); |
50 | } else { | 47 | } else { |
51 | p.error() | 48 | p.error().message("expected attribute value").emit() |
52 | .message("expected attribute value") | ||
53 | .emit() | ||
54 | } | 49 | } |
55 | } | 50 | } |
56 | 51 | ||
@@ -73,8 +68,8 @@ fn meta_item_arg_list(p: &mut Parser) { | |||
73 | p.error().message(message).emit(); | 68 | p.error().message(message).emit(); |
74 | p.bump(); | 69 | p.bump(); |
75 | err.complete(p, ERROR); | 70 | err.complete(p, ERROR); |
76 | continue | 71 | continue; |
77 | } | 72 | }, |
78 | } | 73 | } |
79 | if !p.at(R_PAREN) { | 74 | if !p.at(R_PAREN) { |
80 | p.expect(COMMA); | 75 | 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::*; | |||
2 | 2 | ||
3 | pub(super) fn literal(p: &mut Parser) -> bool { | 3 | pub(super) fn literal(p: &mut Parser) -> bool { |
4 | match p.current() { | 4 | match p.current() { |
5 | TRUE_KW | FALSE_KW | | 5 | TRUE_KW | FALSE_KW | INT_NUMBER | FLOAT_NUMBER | BYTE | CHAR | STRING | RAW_STRING |
6 | INT_NUMBER | FLOAT_NUMBER | | 6 | | BYTE_STRING | RAW_BYTE_STRING => { |
7 | BYTE | CHAR | | ||
8 | STRING | RAW_STRING | BYTE_STRING | RAW_BYTE_STRING => { | ||
9 | let lit = p.start(); | 7 | let lit = p.start(); |
10 | p.bump(); | 8 | p.bump(); |
11 | lit.complete(p, LITERAL); | 9 | lit.complete(p, LITERAL); |
12 | true | 10 | true |
13 | } | 11 | } |
14 | _ => false | 12 | _ => false, |
15 | } | 13 | } |
16 | } | 14 | } |
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) { | |||
7 | } | 7 | } |
8 | } | 8 | } |
9 | 9 | ||
10 | pub(super) const ITEM_FIRST: TokenSet = token_set![ | 10 | pub(super) const ITEM_FIRST: TokenSet = |
11 | EXTERN_KW, | 11 | token_set![EXTERN_KW, MOD_KW, USE_KW, STRUCT_KW, FN_KW, PUB_KW, POUND,]; |
12 | MOD_KW, | ||
13 | USE_KW, | ||
14 | STRUCT_KW, | ||
15 | FN_KW, | ||
16 | PUB_KW, | ||
17 | POUND, | ||
18 | ]; | ||
19 | 12 | ||
20 | fn item(p: &mut Parser) { | 13 | fn item(p: &mut Parser) { |
21 | let item = p.start(); | 14 | let item = p.start(); |
@@ -48,7 +41,7 @@ fn item(p: &mut Parser) { | |||
48 | let message = if err_token == SEMI { | 41 | let message = if err_token == SEMI { |
49 | //TODO: if the item is incomplete, this message is misleading | 42 | //TODO: if the item is incomplete, this message is misleading |
50 | "expected item, found `;`\n\ | 43 | "expected item, found `;`\n\ |
51 | consider removing this semicolon" | 44 | consider removing this semicolon" |
52 | } else { | 45 | } else { |
53 | "expected item" | 46 | "expected item" |
54 | }; | 47 | }; |
@@ -76,10 +69,9 @@ fn struct_item(p: &mut Parser) { | |||
76 | return; | 69 | return; |
77 | } | 70 | } |
78 | L_CURLY => named_fields(p), | 71 | L_CURLY => named_fields(p), |
79 | _ => { //TODO: special case `(` error message | 72 | _ => { |
80 | p.error() | 73 | //TODO: special case `(` error message |
81 | .message("expected `;` or `{`") | 74 | p.error().message("expected `;` or `{`").emit(); |
82 | .emit(); | ||
83 | return; | 75 | return; |
84 | } | 76 | } |
85 | } | 77 | } |
@@ -94,9 +86,7 @@ fn struct_item(p: &mut Parser) { | |||
94 | p.expect(SEMI); | 86 | p.expect(SEMI); |
95 | } | 87 | } |
96 | _ => { | 88 | _ => { |
97 | p.error() | 89 | p.error().message("expected `;`, `{`, or `(`").emit(); |
98 | .message("expected `;`, `{`, or `(`") | ||
99 | .emit(); | ||
100 | return; | 90 | return; |
101 | } | 91 | } |
102 | } | 92 | } |
@@ -177,7 +167,7 @@ fn use_item(p: &mut Parser) { | |||
177 | use_tree(p); | 167 | use_tree(p); |
178 | p.expect(SEMI); | 168 | p.expect(SEMI); |
179 | 169 | ||
180 | fn use_tree(p: &mut Parser){ | 170 | fn use_tree(p: &mut Parser) { |
181 | let la = p.raw_lookahead(1); | 171 | let la = p.raw_lookahead(1); |
182 | let m = p.start(); | 172 | let m = p.start(); |
183 | match (p.current(), la) { | 173 | match (p.current(), la) { |
@@ -209,9 +199,7 @@ fn use_item(p: &mut Parser) { | |||
209 | L_CURLY => nested_trees(p), | 199 | L_CURLY => nested_trees(p), |
210 | _ => { | 200 | _ => { |
211 | // is this unreachable? | 201 | // is this unreachable? |
212 | p.error() | 202 | p.error().message("expected `{` or `*`").emit(); |
213 | .message("expected `{` or `*`") | ||
214 | .emit(); | ||
215 | } | 203 | } |
216 | } | 204 | } |
217 | } | 205 | } |
@@ -222,7 +210,7 @@ fn use_item(p: &mut Parser) { | |||
222 | m.abandon(p); | 210 | m.abandon(p); |
223 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); | 211 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); |
224 | return; | 212 | return; |
225 | }, | 213 | } |
226 | } | 214 | } |
227 | m.complete(p, USE_TREE); | 215 | m.complete(p, USE_TREE); |
228 | } | 216 | } |
@@ -240,13 +228,9 @@ fn use_item(p: &mut Parser) { | |||
240 | } | 228 | } |
241 | } | 229 | } |
242 | 230 | ||
243 | |||
244 | fn fn_item(p: &mut Parser) { | 231 | fn fn_item(p: &mut Parser) { |
245 | assert!(p.at(FN_KW)); | 232 | assert!(p.at(FN_KW)); |
246 | p.bump(); | 233 | p.bump(); |
247 | 234 | ||
248 | p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) | 235 | p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ()); |
249 | && p.curly_block(|_| ()); | ||
250 | } | 236 | } |
251 | |||
252 | |||
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 @@ | |||
1 | use super::parser::{Parser, TokenSet}; | 1 | use super::parser::{Parser, TokenSet}; |
2 | use {SyntaxKind}; | 2 | use SyntaxKind; |
3 | use tree::EOF; | 3 | use tree::EOF; |
4 | use syntax_kinds::*; | 4 | use syntax_kinds::*; |
5 | 5 | ||
@@ -29,7 +29,7 @@ fn visibility(p: &mut Parser) { | |||
29 | } | 29 | } |
30 | p.expect(R_PAREN); | 30 | p.expect(R_PAREN); |
31 | } | 31 | } |
32 | _ => () | 32 | _ => (), |
33 | } | 33 | } |
34 | } | 34 | } |
35 | vis.complete(p, VISIBILITY); | 35 | vis.complete(p, VISIBILITY); |
@@ -53,9 +53,7 @@ impl<'p> Parser<'p> { | |||
53 | 53 | ||
54 | fn err_and_bump(&mut self, message: &str) { | 54 | fn err_and_bump(&mut self, message: &str) { |
55 | let err = self.start(); | 55 | let err = self.start(); |
56 | self.error() | 56 | self.error().message(message).emit(); |
57 | .message(message) | ||
58 | .emit(); | ||
59 | self.bump(); | 57 | self.bump(); |
60 | err.complete(self, ERROR); | 58 | err.complete(self, ERROR); |
61 | } | 59 | } |
@@ -65,15 +63,16 @@ impl<'p> Parser<'p> { | |||
65 | self.bump(); | 63 | self.bump(); |
66 | true | 64 | true |
67 | } else { | 65 | } else { |
68 | self.error() | 66 | self.error().message(format!("expected {:?}", kind)).emit(); |
69 | .message(format!("expected {:?}", kind)) | ||
70 | .emit(); | ||
71 | false | 67 | false |
72 | } | 68 | } |
73 | } | 69 | } |
74 | 70 | ||
75 | fn eat(&mut self, kind: SyntaxKind) -> bool { | 71 | fn eat(&mut self, kind: SyntaxKind) -> bool { |
76 | self.current() == kind && { self.bump(); true } | 72 | self.current() == kind && { |
73 | self.bump(); | ||
74 | true | ||
75 | } | ||
77 | } | 76 | } |
78 | } | 77 | } |
79 | 78 | ||
@@ -94,8 +93,7 @@ impl Lookahead for SyntaxKind { | |||
94 | 93 | ||
95 | impl Lookahead for [SyntaxKind; 2] { | 94 | impl Lookahead for [SyntaxKind; 2] { |
96 | fn is_ahead(self, p: &Parser) -> bool { | 95 | fn is_ahead(self, p: &Parser) -> bool { |
97 | p.current() == self[0] | 96 | p.current() == self[0] && p.raw_lookahead(1) == self[1] |
98 | && p.raw_lookahead(1) == self[1] | ||
99 | } | 97 | } |
100 | 98 | ||
101 | fn consume(p: &mut Parser) { | 99 | fn consume(p: &mut Parser) { |
@@ -106,9 +104,7 @@ impl Lookahead for [SyntaxKind; 2] { | |||
106 | 104 | ||
107 | impl Lookahead for [SyntaxKind; 3] { | 105 | impl Lookahead for [SyntaxKind; 3] { |
108 | fn is_ahead(self, p: &Parser) -> bool { | 106 | fn is_ahead(self, p: &Parser) -> bool { |
109 | p.current() == self[0] | 107 | p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] |
110 | && p.raw_lookahead(1) == self[1] | ||
111 | && p.raw_lookahead(2) == self[2] | ||
112 | } | 108 | } |
113 | 109 | ||
114 | fn consume(p: &mut Parser) { | 110 | fn consume(p: &mut Parser) { |
@@ -130,5 +126,4 @@ impl<'a> Lookahead for AnyOf<'a> { | |||
130 | fn consume(p: &mut Parser) { | 126 | fn consume(p: &mut Parser) { |
131 | p.bump(); | 127 | p.bump(); |
132 | } | 128 | } |
133 | |||
134 | } | 129 | } |
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) { | |||
34 | p.bump(); | 34 | p.bump(); |
35 | } | 35 | } |
36 | _ => { | 36 | _ => { |
37 | p.error() | 37 | p.error().message("expected identifier").emit(); |
38 | .message("expected identifier") | ||
39 | .emit(); | ||
40 | } | 38 | } |
41 | }; | 39 | }; |
42 | segment.complete(p, PATH_SEGMENT); | 40 | 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::*; | |||
2 | 2 | ||
3 | pub(super) fn type_ref(p: &mut Parser) { | 3 | pub(super) fn type_ref(p: &mut Parser) { |
4 | p.expect(IDENT); | 4 | p.expect(IDENT); |
5 | } \ No newline at end of file | 5 | } |
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 @@ | |||
1 | use {Token, SyntaxKind}; | 1 | use {SyntaxKind, Token}; |
2 | 2 | ||
3 | #[macro_use] | 3 | #[macro_use] |
4 | mod parser; | 4 | 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 @@ | |||
1 | use {Token, SyntaxKind, TextUnit}; | 1 | use {SyntaxKind, TextUnit, Token}; |
2 | use super::Event; | 2 | use super::Event; |
3 | use super::super::is_insignificant; | 3 | use super::super::is_insignificant; |
4 | use syntax_kinds::{L_CURLY, R_CURLY, ERROR}; | 4 | use syntax_kinds::{ERROR, L_CURLY, R_CURLY}; |
5 | use tree::{EOF, TOMBSTONE}; | 5 | use tree::{EOF, TOMBSTONE}; |
6 | 6 | ||
7 | pub(crate) struct Marker { | 7 | pub(crate) struct Marker { |
8 | pos: u32 | 8 | pos: u32, |
9 | } | 9 | } |
10 | 10 | ||
11 | impl Marker { | 11 | impl Marker { |
12 | pub fn complete(self, p: &mut Parser, kind: SyntaxKind) -> CompleteMarker { | 12 | pub fn complete(self, p: &mut Parser, kind: SyntaxKind) -> CompleteMarker { |
13 | match self.event(p) { | 13 | match self.event(p) { |
14 | &mut Event::Start { kind: ref mut slot, ..} => { | 14 | &mut Event::Start { |
15 | kind: ref mut slot, .. | ||
16 | } => { | ||
15 | *slot = kind; | 17 | *slot = kind; |
16 | } | 18 | } |
17 | _ => unreachable!(), | 19 | _ => unreachable!(), |
@@ -26,8 +28,11 @@ impl Marker { | |||
26 | let idx = self.pos as usize; | 28 | let idx = self.pos as usize; |
27 | if idx == p.events.len() - 1 { | 29 | if idx == p.events.len() - 1 { |
28 | match p.events.pop() { | 30 | match p.events.pop() { |
29 | Some(Event::Start { kind: TOMBSTONE, forward_parent: None }) => (), | 31 | Some(Event::Start { |
30 | _ => unreachable!() | 32 | kind: TOMBSTONE, |
33 | forward_parent: None, | ||
34 | }) => (), | ||
35 | _ => unreachable!(), | ||
31 | } | 36 | } |
32 | } | 37 | } |
33 | ::std::mem::forget(self); | 38 | ::std::mem::forget(self); |
@@ -51,14 +56,17 @@ impl Drop for Marker { | |||
51 | } | 56 | } |
52 | 57 | ||
53 | pub(crate) struct CompleteMarker { | 58 | pub(crate) struct CompleteMarker { |
54 | pos: u32 | 59 | pos: u32, |
55 | } | 60 | } |
56 | 61 | ||
57 | impl CompleteMarker { | 62 | impl CompleteMarker { |
58 | pub(crate) fn precede(self, p: &mut Parser) -> Marker { | 63 | pub(crate) fn precede(self, p: &mut Parser) -> Marker { |
59 | let m = p.start(); | 64 | let m = p.start(); |
60 | match p.events[self.pos as usize] { | 65 | match p.events[self.pos as usize] { |
61 | Event::Start { ref mut forward_parent, ..} => { | 66 | Event::Start { |
67 | ref mut forward_parent, | ||
68 | .. | ||
69 | } => { | ||
62 | *forward_parent = Some(m.pos - self.pos); | 70 | *forward_parent = Some(m.pos - self.pos); |
63 | } | 71 | } |
64 | _ => unreachable!(), | 72 | _ => unreachable!(), |
@@ -68,7 +76,7 @@ impl CompleteMarker { | |||
68 | } | 76 | } |
69 | 77 | ||
70 | pub(crate) struct TokenSet { | 78 | pub(crate) struct TokenSet { |
71 | pub tokens: &'static [SyntaxKind] | 79 | pub tokens: &'static [SyntaxKind], |
72 | } | 80 | } |
73 | 81 | ||
74 | impl TokenSet { | 82 | impl TokenSet { |
@@ -90,7 +98,6 @@ macro_rules! token_set { | |||
90 | }; | 98 | }; |
91 | } | 99 | } |
92 | 100 | ||
93 | |||
94 | pub(crate) struct Parser<'t> { | 101 | pub(crate) struct Parser<'t> { |
95 | #[allow(unused)] | 102 | #[allow(unused)] |
96 | text: &'t str, | 103 | text: &'t str, |
@@ -150,8 +157,13 @@ impl<'t> Parser<'t> { | |||
150 | } | 157 | } |
151 | 158 | ||
152 | pub(crate) fn start(&mut self) -> Marker { | 159 | pub(crate) fn start(&mut self) -> Marker { |
153 | let m = Marker { pos: self.events.len() as u32 }; | 160 | let m = Marker { |
154 | self.event(Event::Start { kind: TOMBSTONE, forward_parent: None }); | 161 | pos: self.events.len() as u32, |
162 | }; | ||
163 | self.event(Event::Start { | ||
164 | kind: TOMBSTONE, | ||
165 | forward_parent: None, | ||
166 | }); | ||
155 | m | 167 | m |
156 | } | 168 | } |
157 | 169 | ||
@@ -168,7 +180,10 @@ impl<'t> Parser<'t> { | |||
168 | _ => (), | 180 | _ => (), |
169 | } | 181 | } |
170 | self.pos += 1; | 182 | self.pos += 1; |
171 | self.event(Event::Token { kind, n_raw_tokens: 1 }); | 183 | self.event(Event::Token { |
184 | kind, | ||
185 | n_raw_tokens: 1, | ||
186 | }); | ||
172 | kind | 187 | kind |
173 | } | 188 | } |
174 | 189 | ||
@@ -210,7 +225,10 @@ pub(crate) struct ErrorBuilder<'p, 't: 'p> { | |||
210 | 225 | ||
211 | impl<'t, 'p> ErrorBuilder<'p, 't> { | 226 | impl<'t, 'p> ErrorBuilder<'p, 't> { |
212 | fn new(parser: &'p mut Parser<'t>) -> Self { | 227 | fn new(parser: &'p mut Parser<'t>) -> Self { |
213 | ErrorBuilder { message: None, parser } | 228 | ErrorBuilder { |
229 | message: None, | ||
230 | parser, | ||
231 | } | ||
214 | } | 232 | } |
215 | 233 | ||
216 | pub fn message<M: Into<String>>(mut self, m: M) -> Self { | 234 | pub fn message<M: Into<String>>(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 @@ | |||
1 | use {Token, File, FileBuilder, Sink, SyntaxKind}; | 1 | use {File, FileBuilder, Sink, SyntaxKind, Token}; |
2 | 2 | ||
3 | use syntax_kinds::*; | 3 | use syntax_kinds::*; |
4 | use tree::TOMBSTONE; | 4 | use tree::TOMBSTONE; |
@@ -6,17 +6,12 @@ use tree::TOMBSTONE; | |||
6 | mod event_parser; | 6 | mod event_parser; |
7 | use self::event_parser::Event; | 7 | use self::event_parser::Event; |
8 | 8 | ||
9 | |||
10 | pub fn parse(text: String, tokens: &[Token]) -> File { | 9 | pub fn parse(text: String, tokens: &[Token]) -> File { |
11 | let events = event_parser::parse(&text, tokens); | 10 | let events = event_parser::parse(&text, tokens); |
12 | from_events_to_file(text, tokens, events) | 11 | from_events_to_file(text, tokens, events) |
13 | } | 12 | } |
14 | 13 | ||
15 | fn from_events_to_file( | 14 | fn from_events_to_file(text: String, tokens: &[Token], events: Vec<Event>) -> File { |
16 | text: String, | ||
17 | tokens: &[Token], | ||
18 | events: Vec<Event>, | ||
19 | ) -> File { | ||
20 | let mut builder = FileBuilder::new(text); | 15 | let mut builder = FileBuilder::new(text); |
21 | let mut idx = 0; | 16 | let mut idx = 0; |
22 | 17 | ||
@@ -26,18 +21,23 @@ fn from_events_to_file( | |||
26 | for (i, event) in events.iter().enumerate() { | 21 | for (i, event) in events.iter().enumerate() { |
27 | if holes.last() == Some(&i) { | 22 | if holes.last() == Some(&i) { |
28 | holes.pop(); | 23 | holes.pop(); |
29 | continue | 24 | continue; |
30 | } | 25 | } |
31 | 26 | ||
32 | match event { | 27 | match event { |
33 | &Event::Start { kind: TOMBSTONE, .. } => (), | 28 | &Event::Start { |
29 | kind: TOMBSTONE, .. | ||
30 | } => (), | ||
34 | 31 | ||
35 | &Event::Start { .. } => { | 32 | &Event::Start { .. } => { |
36 | forward_parents.clear(); | 33 | forward_parents.clear(); |
37 | let mut idx = i; | 34 | let mut idx = i; |
38 | loop { | 35 | loop { |
39 | let (kind, fwd) = match events[idx] { | 36 | let (kind, fwd) = match events[idx] { |
40 | Event::Start { kind, forward_parent } => (kind, forward_parent), | 37 | Event::Start { |
38 | kind, | ||
39 | forward_parent, | ||
40 | } => (kind, forward_parent), | ||
41 | _ => unreachable!(), | 41 | _ => unreachable!(), |
42 | }; | 42 | }; |
43 | forward_parents.push((idx, kind)); | 43 | forward_parents.push((idx, kind)); |
@@ -64,8 +64,11 @@ fn from_events_to_file( | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | builder.finish_internal() | 66 | builder.finish_internal() |
67 | }, | 67 | } |
68 | &Event::Token { kind: _, mut n_raw_tokens } => loop { | 68 | &Event::Token { |
69 | kind: _, | ||
70 | mut n_raw_tokens, | ||
71 | } => loop { | ||
69 | let token = tokens[idx]; | 72 | let token = tokens[idx]; |
70 | if !is_insignificant(token.kind) { | 73 | if !is_insignificant(token.kind) { |
71 | n_raw_tokens -= 1; | 74 | n_raw_tokens -= 1; |
@@ -76,8 +79,7 @@ fn from_events_to_file( | |||
76 | break; | 79 | break; |
77 | } | 80 | } |
78 | }, | 81 | }, |
79 | &Event::Error { ref message } => | 82 | &Event::Error { ref message } => builder.error().message(message.clone()).emit(), |
80 | builder.error().message(message.clone()).emit(), | ||
81 | } | 83 | } |
82 | } | 84 | } |
83 | builder.finish() | 85 | builder.finish() |