aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing.rs')
-rw-r--r--crates/ra_syntax/src/parsing.rs29
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 @@
2mod token_set; 2mod token_set;
3mod builder; 3mod builder;
4mod lexer; 4mod lexer;
5mod parser_impl; 5mod event;
6mod input;
6mod parser_api; 7mod parser_api;
7mod grammar; 8mod grammar;
8mod reparsing; 9mod reparsing;
9 10
10use crate::{ 11use 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
20pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { 26pub(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
31fn 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.