aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/input.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-20 19:58:56 +0000
committerAleksey Kladov <[email protected]>2019-02-20 20:02:24 +0000
commit4c1f9b8d4e9ab9ba3b16d2b03f3c8bcc7f61706e (patch)
tree4e9ae2abecdf31bd849f3a6d5e568a495081f9a4 /crates/ra_syntax/src/parsing/input.rs
parentcce23fddba4241202ebd29cce44db4ce9a08793a (diff)
remove TokenPos
Diffstat (limited to 'crates/ra_syntax/src/parsing/input.rs')
-rw-r--r--crates/ra_syntax/src/parsing/input.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/parsing/input.rs b/crates/ra_syntax/src/parsing/input.rs
index 0f1810df5..96c03bb11 100644
--- a/crates/ra_syntax/src/parsing/input.rs
+++ b/crates/ra_syntax/src/parsing/input.rs
@@ -1,33 +1,29 @@
1use crate::{ 1use crate::{
2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, 2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
3 parsing::{ 3 parsing::{
4 TokenPos, TokenSource, 4 TokenSource,
5 lexer::Token, 5 lexer::Token,
6 }, 6 },
7}; 7};
8 8
9impl<'t> TokenSource for ParserInput<'t> { 9impl<'t> TokenSource for ParserInput<'t> {
10 fn token_kind(&self, pos: TokenPos) -> SyntaxKind { 10 fn token_kind(&self, pos: usize) -> SyntaxKind {
11 let idx = pos.0 as usize; 11 if !(pos < self.tokens.len()) {
12 if !(idx < self.tokens.len()) {
13 return EOF; 12 return EOF;
14 } 13 }
15 self.tokens[idx].kind 14 self.tokens[pos].kind
16 } 15 }
17 fn is_token_joint_to_next(&self, pos: TokenPos) -> bool { 16 fn is_token_joint_to_next(&self, pos: usize) -> bool {
18 let idx_curr = pos.0 as usize; 17 if !(pos + 1 < self.tokens.len()) {
19 let idx_next = pos.0 as usize + 1;
20 if !(idx_next < self.tokens.len()) {
21 return true; 18 return true;
22 } 19 }
23 self.start_offsets[idx_curr] + self.tokens[idx_curr].len == self.start_offsets[idx_next] 20 self.start_offsets[pos] + self.tokens[pos].len == self.start_offsets[pos + 1]
24 } 21 }
25 fn is_keyword(&self, pos: TokenPos, kw: &str) -> bool { 22 fn is_keyword(&self, pos: usize, kw: &str) -> bool {
26 let idx = pos.0 as usize; 23 if !(pos < self.tokens.len()) {
27 if !(idx < self.tokens.len()) {
28 return false; 24 return false;
29 } 25 }
30 let range = TextRange::offset_len(self.start_offsets[idx], self.tokens[idx].len); 26 let range = TextRange::offset_len(self.start_offsets[pos], self.tokens[pos].len);
31 27
32 self.text[range] == *kw 28 self.text[range] == *kw
33 } 29 }