diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing.rs | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs index 0a11600e1..cf573801c 100644 --- a/crates/ra_syntax/src/parsing.rs +++ b/crates/ra_syntax/src/parsing.rs | |||
@@ -1,17 +1,18 @@ | |||
1 | mod builder; | 1 | //! Lexing, bridging to ra_parser (which does the actual parsing) and |
2 | //! incremental reparsing. | ||
3 | |||
2 | mod lexer; | 4 | mod lexer; |
3 | mod input; | 5 | mod input; |
6 | mod builder; | ||
4 | mod reparsing; | 7 | mod reparsing; |
5 | 8 | ||
6 | use ra_parser::{parse, ParseError}; | ||
7 | |||
8 | use crate::{ | 9 | use crate::{ |
9 | SyntaxKind, SyntaxError, | 10 | SyntaxError, |
11 | syntax_node::GreenNode, | ||
10 | parsing::{ | 12 | parsing::{ |
11 | builder::TreeBuilder, | 13 | builder::TreeBuilder, |
12 | input::ParserInput, | 14 | input::ParserInput, |
13 | }, | 15 | }, |
14 | syntax_node::GreenNode, | ||
15 | }; | 16 | }; |
16 | 17 | ||
17 | pub use self::lexer::{tokenize, Token}; | 18 | pub use self::lexer::{tokenize, Token}; |
@@ -22,37 +23,6 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { | |||
22 | let tokens = tokenize(&text); | 23 | let tokens = tokenize(&text); |
23 | let token_source = ParserInput::new(text, &tokens); | 24 | let token_source = ParserInput::new(text, &tokens); |
24 | let mut tree_sink = TreeBuilder::new(text, &tokens); | 25 | let mut tree_sink = TreeBuilder::new(text, &tokens); |
25 | parse(&token_source, &mut tree_sink); | 26 | ra_parser::parse(&token_source, &mut tree_sink); |
26 | tree_sink.finish() | 27 | tree_sink.finish() |
27 | } | 28 | } |
28 | |||
29 | /// `TreeSink` abstracts details of a particular syntax tree implementation. | ||
30 | trait TreeSink { | ||
31 | type Tree; | ||
32 | |||
33 | /// Adds new leaf to the current branch. | ||
34 | fn leaf(&mut self, kind: SyntaxKind, n_tokens: u8); | ||
35 | |||
36 | /// Start new branch and make it current. | ||
37 | fn start_branch(&mut self, kind: SyntaxKind, root: bool); | ||
38 | |||
39 | /// Finish current branch and restore previous | ||
40 | /// branch as current. | ||
41 | fn finish_branch(&mut self, root: bool); | ||
42 | |||
43 | fn error(&mut self, error: ParseError); | ||
44 | |||
45 | /// Complete tree building. Make sure that | ||
46 | /// `start_branch` and `finish_branch` calls | ||
47 | /// are paired! | ||
48 | fn finish(self) -> Self::Tree; | ||
49 | } | ||
50 | |||
51 | /// `TokenSource` abstracts the source of the tokens parser operates one. | ||
52 | /// | ||
53 | /// Hopefully this will allow us to treat text and token trees in the same way! | ||
54 | trait TokenSource { | ||
55 | fn token_kind(&self, pos: usize) -> SyntaxKind; | ||
56 | fn is_token_joint_to_next(&self, pos: usize) -> bool; | ||
57 | fn is_keyword(&self, pos: usize, kw: &str) -> bool; | ||
58 | } | ||