diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing/parser_impl/input.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/parser_impl/input.rs | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/crates/ra_syntax/src/parsing/parser_impl/input.rs b/crates/ra_syntax/src/parsing/parser_impl/input.rs deleted file mode 100644 index 11b32b9ce..000000000 --- a/crates/ra_syntax/src/parsing/parser_impl/input.rs +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | use crate::{ | ||
2 | SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, | ||
3 | parsing::{ | ||
4 | TokenPos, | ||
5 | parser_impl::TokenSource, | ||
6 | lexer::Token, | ||
7 | }, | ||
8 | }; | ||
9 | |||
10 | impl<'t> TokenSource for ParserInput<'t> { | ||
11 | fn token_kind(&self, pos: TokenPos) -> SyntaxKind { | ||
12 | let idx = pos.0 as usize; | ||
13 | if !(idx < self.tokens.len()) { | ||
14 | return EOF; | ||
15 | } | ||
16 | self.tokens[idx].kind | ||
17 | } | ||
18 | fn is_token_joint_to_next(&self, pos: TokenPos) -> bool { | ||
19 | let idx_curr = pos.0 as usize; | ||
20 | let idx_next = pos.0 as usize + 1; | ||
21 | if !(idx_next < self.tokens.len()) { | ||
22 | return true; | ||
23 | } | ||
24 | self.start_offsets[idx_curr] + self.tokens[idx_curr].len == self.start_offsets[idx_next] | ||
25 | } | ||
26 | fn is_keyword(&self, pos: TokenPos, kw: &str) -> bool { | ||
27 | let idx = pos.0 as usize; | ||
28 | if !(idx < self.tokens.len()) { | ||
29 | return false; | ||
30 | } | ||
31 | let range = TextRange::offset_len(self.start_offsets[idx], self.tokens[idx].len); | ||
32 | |||
33 | self.text[range] == *kw | ||
34 | } | ||
35 | } | ||
36 | |||
37 | pub(crate) struct ParserInput<'t> { | ||
38 | text: &'t str, | ||
39 | /// start position of each token(expect whitespace and comment) | ||
40 | /// ```non-rust | ||
41 | /// struct Foo; | ||
42 | /// ^------^--- | ||
43 | /// | | ^- | ||
44 | /// 0 7 10 | ||
45 | /// ``` | ||
46 | /// (token, start_offset): `[(struct, 0), (Foo, 7), (;, 10)]` | ||
47 | start_offsets: Vec<TextUnit>, | ||
48 | /// non-whitespace/comment tokens | ||
49 | /// ```non-rust | ||
50 | /// struct Foo {} | ||
51 | /// ^^^^^^ ^^^ ^^ | ||
52 | /// ``` | ||
53 | /// tokens: `[struct, Foo, {, }]` | ||
54 | tokens: Vec<Token>, | ||
55 | } | ||
56 | |||
57 | impl<'t> ParserInput<'t> { | ||
58 | /// Generate input from tokens(expect comment and whitespace). | ||
59 | pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> ParserInput<'t> { | ||
60 | let mut tokens = Vec::new(); | ||
61 | let mut start_offsets = Vec::new(); | ||
62 | let mut len = 0.into(); | ||
63 | for &token in raw_tokens.iter() { | ||
64 | if !token.kind.is_trivia() { | ||
65 | tokens.push(token); | ||
66 | start_offsets.push(len); | ||
67 | } | ||
68 | len += token.len; | ||
69 | } | ||
70 | |||
71 | ParserInput { text, start_offsets, tokens } | ||
72 | } | ||
73 | } | ||