aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-28 11:07:10 +0100
committerAleksey Kladov <[email protected]>2018-07-28 11:07:10 +0100
commit8d9961b75377a7bd2656b5aa1451710de8c86f60 (patch)
treec2dcedf487d2ad4674edb012dd579aa74173d8c2 /src/parser
parent52dc0ddc84544a59d3a2580d9944d0482a633349 (diff)
Migrate to text-unit
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event.rs8
-rw-r--r--src/parser/input.rs4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/parser/event.rs b/src/parser/event.rs
index 1c0905a38..ac8a55de9 100644
--- a/src/parser/event.rs
+++ b/src/parser/event.rs
@@ -1,5 +1,7 @@
1use {ErrorMsg, File, FileBuilder, Sink, SyntaxKind, TextUnit, Token}; 1use {
2use syntax_kinds::TOMBSTONE; 2 ErrorMsg, File, FileBuilder, Sink, SyntaxKind, Token,
3 syntax_kinds::TOMBSTONE,
4};
3use super::is_insignificant; 5use super::is_insignificant;
4 6
5/// `Parser` produces a flat list of `Event`s. 7/// `Parser` produces a flat list of `Event`s.
@@ -133,7 +135,7 @@ pub(super) fn to_file(text: String, tokens: &[Token], events: Vec<Event>) -> Fil
133 builder.leaf(token.kind, token.len); 135 builder.leaf(token.kind, token.len);
134 idx += 1 136 idx += 1
135 } 137 }
136 let mut len = TextUnit::new(0); 138 let mut len = 0.into();
137 for _ in 0..n_raw_tokens { 139 for _ in 0..n_raw_tokens {
138 len += tokens[idx].len; 140 len += tokens[idx].len;
139 idx += 1; 141 idx += 1;
diff --git a/src/parser/input.rs b/src/parser/input.rs
index 13589467b..9b400b959 100644
--- a/src/parser/input.rs
+++ b/src/parser/input.rs
@@ -14,7 +14,7 @@ impl<'t> ParserInput<'t> {
14 pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> ParserInput<'t> { 14 pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> ParserInput<'t> {
15 let mut tokens = Vec::new(); 15 let mut tokens = Vec::new();
16 let mut start_offsets = Vec::new(); 16 let mut start_offsets = Vec::new();
17 let mut len = TextUnit::new(0); 17 let mut len = 0.into();
18 for &token in raw_tokens.iter() { 18 for &token in raw_tokens.iter() {
19 if !is_insignificant(token.kind) { 19 if !is_insignificant(token.kind) {
20 tokens.push(token); 20 tokens.push(token);
@@ -44,7 +44,7 @@ impl<'t> ParserInput<'t> {
44 if !(idx < self.tokens.len()) { 44 if !(idx < self.tokens.len()) {
45 return ""; 45 return "";
46 } 46 }
47 let range = TextRange::from_len(self.start_offsets[idx], self.tokens[idx].len); 47 let range = TextRange::offset_len(self.start_offsets[idx], self.tokens[idx].len);
48 &self.text[range] 48 &self.text[range]
49 } 49 }
50} 50}