aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-07 16:56:33 +0000
committerAleksey Kladov <[email protected]>2018-01-07 16:56:33 +0000
commitbbf7e9bbd284f83d43e61604076a040baaf124a7 (patch)
tree8ac7d990f075c3d8fa5126de0ae5a49e55fb0df1
parentf194750a2a4d5f034e89b937e1271637b884a503 (diff)
Simiplify
-rw-r--r--src/parser/event_parser/parser.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs
index f8330af4e..923d0bd5a 100644
--- a/src/parser/event_parser/parser.rs
+++ b/src/parser/event_parser/parser.rs
@@ -5,8 +5,7 @@ use syntax_kinds::{L_CURLY, R_CURLY, ERROR};
5 5
6pub struct Parser<'t> { 6pub struct Parser<'t> {
7 text: &'t str, 7 text: &'t str,
8 raw_tokens: &'t [Token], 8 non_ws_tokens: Vec<(Token, TextUnit)>,
9 non_ws_tokens: Vec<(usize, TextUnit)>,
10 9
11 pos: usize, 10 pos: usize,
12 events: Vec<Event>, 11 events: Vec<Event>,
@@ -19,16 +18,15 @@ impl<'t> Parser<'t> {
19 pub(crate) fn new(text: &'t str, raw_tokens: &'t [Token]) -> Parser<'t> { 18 pub(crate) fn new(text: &'t str, raw_tokens: &'t [Token]) -> Parser<'t> {
20 let mut non_ws_tokens = Vec::new(); 19 let mut non_ws_tokens = Vec::new();
21 let mut len = TextUnit::new(0); 20 let mut len = TextUnit::new(0);
22 for (idx, &token) in raw_tokens.iter().enumerate() { 21 for &token in raw_tokens.iter() {
23 if !is_insignificant(token.kind) { 22 if !is_insignificant(token.kind) {
24 non_ws_tokens.push((idx, len)) 23 non_ws_tokens.push((token, len))
25 } 24 }
26 len += token.len; 25 len += token.len;
27 } 26 }
28 27
29 Parser { 28 Parser {
30 text, 29 text,
31 raw_tokens,
32 non_ws_tokens, 30 non_ws_tokens,
33 31
34 pos: 0, 32 pos: 0,
@@ -48,8 +46,8 @@ impl<'t> Parser<'t> {
48 return true 46 return true
49 } 47 }
50 if let Some(limit) = self.curly_limit { 48 if let Some(limit) = self.curly_limit {
51 let idx = self.non_ws_tokens[self.pos].0; 49 let token = self.non_ws_tokens[self.pos].0;
52 return limit == self.curly_level && self.raw_tokens[idx].kind == R_CURLY; 50 return limit == self.curly_level && token.kind == R_CURLY;
53 } 51 }
54 false 52 false
55 } 53 }
@@ -70,8 +68,8 @@ impl<'t> Parser<'t> {
70 if self.is_eof() { 68 if self.is_eof() {
71 return None; 69 return None;
72 } 70 }
73 let idx = self.non_ws_tokens[self.pos].0; 71 let token = self.non_ws_tokens[self.pos].0;
74 Some(self.raw_tokens[idx].kind) 72 Some(token.kind)
75 } 73 }
76 74
77 pub(crate) fn bump(&mut self) -> Option<SyntaxKind> { 75 pub(crate) fn bump(&mut self) -> Option<SyntaxKind> {
@@ -90,8 +88,8 @@ impl<'t> Parser<'t> {
90 if self.non_ws_tokens[self.pos..].len() < kinds.len() { 88 if self.non_ws_tokens[self.pos..].len() < kinds.len() {
91 return false 89 return false
92 } 90 }
93 kinds.iter().zip(self.non_ws_tokens[self.pos..].iter()) 91 kinds.iter().zip(self.non_ws_tokens[self.pos..].iter().map(|&(t, _)| t.kind))
94 .all(|(&k1, &(idx, _))| k1 == self.raw_tokens[idx].kind) 92 .all(|(&k1, k2)| k1 == k2)
95 } 93 }
96 94
97 pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool { 95 pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool {