aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/parsing.rs29
-rw-r--r--crates/ra_syntax/src/parsing/event.rs (renamed from crates/ra_syntax/src/parsing/parser_impl/event.rs)4
-rw-r--r--crates/ra_syntax/src/parsing/input.rs (renamed from crates/ra_syntax/src/parsing/parser_impl/input.rs)3
-rw-r--r--crates/ra_syntax/src/parsing/parser_api.rs2
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs6
5 files changed, 30 insertions, 14 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.
diff --git a/crates/ra_syntax/src/parsing/parser_impl/event.rs b/crates/ra_syntax/src/parsing/event.rs
index 9663fba35..893a42e9a 100644
--- a/crates/ra_syntax/src/parsing/parser_impl/event.rs
+++ b/crates/ra_syntax/src/parsing/event.rs
@@ -20,7 +20,7 @@ use crate::{
20 }, 20 },
21 parsing::{ 21 parsing::{
22 lexer::Token, 22 lexer::Token,
23 parser_impl::TreeSink, 23 TreeSink,
24 }, 24 },
25}; 25};
26 26
@@ -113,7 +113,7 @@ impl<'a, S: TreeSink> EventProcessor<'a, S> {
113 } 113 }
114 114
115 /// Generate the syntax tree with the control of events. 115 /// Generate the syntax tree with the control of events.
116 pub(super) fn process(mut self) -> S { 116 pub(crate) fn process(mut self) -> S {
117 let mut forward_parents = Vec::new(); 117 let mut forward_parents = Vec::new();
118 118
119 for i in 0..self.events.len() { 119 for i in 0..self.events.len() {
diff --git a/crates/ra_syntax/src/parsing/parser_impl/input.rs b/crates/ra_syntax/src/parsing/input.rs
index 11b32b9ce..0f1810df5 100644
--- a/crates/ra_syntax/src/parsing/parser_impl/input.rs
+++ b/crates/ra_syntax/src/parsing/input.rs
@@ -1,8 +1,7 @@
1use crate::{ 1use crate::{
2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit, 2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
3 parsing::{ 3 parsing::{
4 TokenPos, 4 TokenPos, TokenSource,
5 parser_impl::TokenSource,
6 lexer::Token, 5 lexer::Token,
7 }, 6 },
8}; 7};
diff --git a/crates/ra_syntax/src/parsing/parser_api.rs b/crates/ra_syntax/src/parsing/parser_api.rs
index 92d7895d3..99f6183a4 100644
--- a/crates/ra_syntax/src/parsing/parser_api.rs
+++ b/crates/ra_syntax/src/parsing/parser_api.rs
@@ -8,7 +8,7 @@ use crate::{
8 parsing::{ 8 parsing::{
9 TokenSource, TokenPos, 9 TokenSource, TokenPos,
10 token_set::TokenSet, 10 token_set::TokenSet,
11 parser_impl::event::Event, 11 event::Event,
12 }, 12 },
13}; 13};
14 14
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index edf3fa291..f45326dff 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -4,8 +4,7 @@ use crate::{
4 syntax_node::{GreenNode, SyntaxNode}, 4 syntax_node::{GreenNode, SyntaxNode},
5 syntax_error::SyntaxError, 5 syntax_error::SyntaxError,
6 parsing::{ 6 parsing::{
7 grammar, 7 grammar, parse_with,
8 parser_impl,
9 builder::GreenBuilder, 8 builder::GreenBuilder,
10 parser_api::Parser, 9 parser_api::Parser,
11 lexer::{tokenize, Token}, 10 lexer::{tokenize, Token},
@@ -62,8 +61,7 @@ fn reparse_block<'node>(
62 if !is_balanced(&tokens) { 61 if !is_balanced(&tokens) {
63 return None; 62 return None;
64 } 63 }
65 let (green, new_errors) = 64 let (green, new_errors) = parse_with(GreenBuilder::new(), &text, &tokens, reparser);
66 parser_impl::parse_with(GreenBuilder::new(), &text, &tokens, reparser);
67 Some((node, green, new_errors)) 65 Some((node, green, new_errors))
68} 66}
69 67