aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/parser_impl/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing/parser_impl/input.rs')
-rw-r--r--crates/ra_syntax/src/parsing/parser_impl/input.rs32
1 files changed, 4 insertions, 28 deletions
diff --git a/crates/ra_syntax/src/parsing/parser_impl/input.rs b/crates/ra_syntax/src/parsing/parser_impl/input.rs
index 8ebbd3825..e9735e526 100644
--- a/crates/ra_syntax/src/parsing/parser_impl/input.rs
+++ b/crates/ra_syntax/src/parsing/parser_impl/input.rs
@@ -1,22 +1,21 @@
1use crate::{ 1use crate::{
2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, 2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
3 parsing::{ 3 parsing::{
4 TokenPos,
4 parser_impl::TokenSource, 5 parser_impl::TokenSource,
5 lexer::Token, 6 lexer::Token,
6 }, 7 },
7}; 8};
8 9
9use std::ops::{Add, AddAssign};
10
11impl<'t> TokenSource for ParserInput<'t> { 10impl<'t> TokenSource for ParserInput<'t> {
12 fn token_kind(&self, pos: InputPosition) -> SyntaxKind { 11 fn token_kind(&self, pos: TokenPos) -> SyntaxKind {
13 let idx = pos.0 as usize; 12 let idx = pos.0 as usize;
14 if !(idx < self.tokens.len()) { 13 if !(idx < self.tokens.len()) {
15 return EOF; 14 return EOF;
16 } 15 }
17 self.tokens[idx].kind 16 self.tokens[idx].kind
18 } 17 }
19 fn is_token_joint_to_next(&self, pos: InputPosition) -> bool { 18 fn is_token_joint_to_next(&self, pos: TokenPos) -> bool {
20 let idx_curr = pos.0 as usize; 19 let idx_curr = pos.0 as usize;
21 let idx_next = pos.0 as usize; 20 let idx_next = pos.0 as usize;
22 if !(idx_next < self.tokens.len()) { 21 if !(idx_next < self.tokens.len()) {
@@ -24,7 +23,7 @@ impl<'t> TokenSource for ParserInput<'t> {
24 } 23 }
25 self.start_offsets[idx_curr] + self.tokens[idx_curr].len == self.start_offsets[idx_next] 24 self.start_offsets[idx_curr] + self.tokens[idx_curr].len == self.start_offsets[idx_next]
26 } 25 }
27 fn is_keyword(&self, pos: InputPosition, kw: &str) -> bool { 26 fn is_keyword(&self, pos: TokenPos, kw: &str) -> bool {
28 let idx = pos.0 as usize; 27 let idx = pos.0 as usize;
29 if !(idx < self.tokens.len()) { 28 if !(idx < self.tokens.len()) {
30 return false; 29 return false;
@@ -72,26 +71,3 @@ impl<'t> ParserInput<'t> {
72 ParserInput { text, start_offsets, tokens } 71 ParserInput { text, start_offsets, tokens }
73 } 72 }
74} 73}
75
76#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
77pub(crate) struct InputPosition(u32);
78
79impl InputPosition {
80 pub fn new() -> Self {
81 InputPosition(0)
82 }
83}
84
85impl Add<u32> for InputPosition {
86 type Output = InputPosition;
87
88 fn add(self, rhs: u32) -> InputPosition {
89 InputPosition(self.0 + rhs)
90 }
91}
92
93impl AddAssign<u32> for InputPosition {
94 fn add_assign(&mut self, rhs: u32) {
95 self.0 += rhs
96 }
97}