aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing/input.rs')
-rw-r--r--crates/ra_syntax/src/parsing/input.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/crates/ra_syntax/src/parsing/input.rs b/crates/ra_syntax/src/parsing/input.rs
index 96c03bb11..31c6a3b9b 100644
--- a/crates/ra_syntax/src/parsing/input.rs
+++ b/crates/ra_syntax/src/parsing/input.rs
@@ -1,11 +1,30 @@
1use ra_parser::TokenSource;
2
1use crate::{ 3use crate::{
2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, 4 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
3 parsing::{ 5 parsing::lexer::Token,
4 TokenSource,
5 lexer::Token,
6 },
7}; 6};
8 7
8pub(crate) struct ParserInput<'t> {
9 text: &'t str,
10 /// start position of each token(expect whitespace and comment)
11 /// ```non-rust
12 /// struct Foo;
13 /// ^------^---
14 /// | | ^-
15 /// 0 7 10
16 /// ```
17 /// (token, start_offset): `[(struct, 0), (Foo, 7), (;, 10)]`
18 start_offsets: Vec<TextUnit>,
19 /// non-whitespace/comment tokens
20 /// ```non-rust
21 /// struct Foo {}
22 /// ^^^^^^ ^^^ ^^
23 /// ```
24 /// tokens: `[struct, Foo, {, }]`
25 tokens: Vec<Token>,
26}
27
9impl<'t> TokenSource for ParserInput<'t> { 28impl<'t> TokenSource for ParserInput<'t> {
10 fn token_kind(&self, pos: usize) -> SyntaxKind { 29 fn token_kind(&self, pos: usize) -> SyntaxKind {
11 if !(pos < self.tokens.len()) { 30 if !(pos < self.tokens.len()) {
@@ -29,26 +48,6 @@ impl<'t> TokenSource for ParserInput<'t> {
29 } 48 }
30} 49}
31 50
32pub(crate) struct ParserInput<'t> {
33 text: &'t str,
34 /// start position of each token(expect whitespace and comment)
35 /// ```non-rust
36 /// struct Foo;
37 /// ^------^---
38 /// | | ^-
39 /// 0 7 10
40 /// ```
41 /// (token, start_offset): `[(struct, 0), (Foo, 7), (;, 10)]`
42 start_offsets: Vec<TextUnit>,
43 /// non-whitespace/comment tokens
44 /// ```non-rust
45 /// struct Foo {}
46 /// ^^^^^^ ^^^ ^^
47 /// ```
48 /// tokens: `[struct, Foo, {, }]`
49 tokens: Vec<Token>,
50}
51
52impl<'t> ParserInput<'t> { 51impl<'t> ParserInput<'t> {
53 /// Generate input from tokens(expect comment and whitespace). 52 /// Generate input from tokens(expect comment and whitespace).
54 pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> ParserInput<'t> { 53 pub fn new(text: &'t str, raw_tokens: &'t [Token]) -> ParserInput<'t> {