aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/parser.rs
diff options
context:
space:
mode:
authorChristopher Durham <[email protected]>2018-01-27 23:51:12 +0000
committerGitHub <[email protected]>2018-01-27 23:51:12 +0000
commite6e61251abb68b3e6a47fd3708f4dea6059a9ec3 (patch)
treec22cfa06a26add11f3aefca3806f0009dd25d923 /src/parser/event_parser/parser.rs
parent357cd3358167daa38f3ff34d225e1501faff6015 (diff)
parent9140b3e7286efae57ee8c49c7bfcad8737f9c6fc (diff)
Merge pull request #12 from CAD97/enforce-fmt
Enforce rustfmt format
Diffstat (limited to 'src/parser/event_parser/parser.rs')
-rw-r--r--src/parser/event_parser/parser.rs46
1 files changed, 32 insertions, 14 deletions
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 @@
1use {Token, SyntaxKind, TextUnit}; 1use {SyntaxKind, TextUnit, Token};
2use super::Event; 2use super::Event;
3use super::super::is_insignificant; 3use super::super::is_insignificant;
4use syntax_kinds::{L_CURLY, R_CURLY, ERROR}; 4use syntax_kinds::{ERROR, L_CURLY, R_CURLY};
5use tree::{EOF, TOMBSTONE}; 5use tree::{EOF, TOMBSTONE};
6 6
7pub(crate) struct Marker { 7pub(crate) struct Marker {
8 pos: u32 8 pos: u32,
9} 9}
10 10
11impl Marker { 11impl 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
53pub(crate) struct CompleteMarker { 58pub(crate) struct CompleteMarker {
54 pos: u32 59 pos: u32,
55} 60}
56 61
57impl CompleteMarker { 62impl 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
70pub(crate) struct TokenSet { 78pub(crate) struct TokenSet {
71 pub tokens: &'static [SyntaxKind] 79 pub tokens: &'static [SyntaxKind],
72} 80}
73 81
74impl TokenSet { 82impl TokenSet {
@@ -90,7 +98,6 @@ macro_rules! token_set {
90 }; 98 };
91} 99}
92 100
93
94pub(crate) struct Parser<'t> { 101pub(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
211impl<'t, 'p> ErrorBuilder<'p, 't> { 226impl<'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 {