diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs index 6c2c5f78b..f74c365d5 100644 --- a/crates/ra_syntax/src/parsing.rs +++ b/crates/ra_syntax/src/parsing.rs | |||
@@ -2,14 +2,20 @@ | |||
2 | mod token_set; | 2 | mod token_set; |
3 | mod builder; | 3 | mod builder; |
4 | mod lexer; | 4 | mod lexer; |
5 | mod parser_impl; | 5 | mod event; |
6 | mod input; | ||
6 | mod parser_api; | 7 | mod parser_api; |
7 | mod grammar; | 8 | mod grammar; |
8 | mod reparsing; | 9 | mod reparsing; |
9 | 10 | ||
10 | use crate::{ | 11 | use crate::{ |
11 | SyntaxError, SyntaxKind, SmolStr, | 12 | SyntaxError, SyntaxKind, SmolStr, |
12 | parsing::builder::GreenBuilder, | 13 | parsing::{ |
14 | builder::GreenBuilder, | ||
15 | input::ParserInput, | ||
16 | event::EventProcessor, | ||
17 | parser_api::Parser, | ||
18 | }, | ||
13 | syntax_node::GreenNode, | 19 | syntax_node::GreenNode, |
14 | }; | 20 | }; |
15 | 21 | ||
@@ -19,9 +25,22 @@ pub(crate) use self::reparsing::incremental_reparse; | |||
19 | 25 | ||
20 | pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { | 26 | pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { |
21 | let tokens = tokenize(&text); | 27 | let tokens = tokenize(&text); |
22 | let (green, errors) = | 28 | parse_with(GreenBuilder::new(), text, &tokens, grammar::root) |
23 | parser_impl::parse_with(GreenBuilder::new(), text, &tokens, grammar::root); | 29 | } |
24 | (green, errors) | 30 | |
31 | fn parse_with<S: TreeSink>( | ||
32 | tree_sink: S, | ||
33 | text: &str, | ||
34 | tokens: &[Token], | ||
35 | f: fn(&mut Parser), | ||
36 | ) -> S::Tree { | ||
37 | let mut events = { | ||
38 | let input = ParserInput::new(text, &tokens); | ||
39 | let mut p = Parser::new(&input); | ||
40 | f(&mut p); | ||
41 | p.finish() | ||
42 | }; | ||
43 | EventProcessor::new(tree_sink, text, tokens, &mut events).process().finish() | ||
25 | } | 44 | } |
26 | 45 | ||
27 | /// `TreeSink` abstracts details of a particular syntax tree implementation. | 46 | /// `TreeSink` abstracts details of a particular syntax tree implementation. |