aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parser_impl/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parser_impl/mod.rs')
-rw-r--r--crates/ra_syntax/src/parser_impl/mod.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/crates/ra_syntax/src/parser_impl/mod.rs b/crates/ra_syntax/src/parser_impl/mod.rs
index b343b404f..8d74cef0e 100644
--- a/crates/ra_syntax/src/parser_impl/mod.rs
+++ b/crates/ra_syntax/src/parser_impl/mod.rs
@@ -4,45 +4,44 @@ mod input;
4use std::cell::Cell; 4use std::cell::Cell;
5 5
6use { 6use {
7 TextUnit, SmolStr,
7 lexer::Token, 8 lexer::Token,
8 parser_api::Parser, 9 parser_api::Parser,
9 parser_impl::{ 10 parser_impl::{
10 event::{process, Event}, 11 event::{EventProcessor, Event},
11 input::{InputPosition, ParserInput}, 12 input::{InputPosition, ParserInput},
12 }, 13 },
13 TextUnit,
14}; 14};
15 15
16use SyntaxKind::{self, EOF, TOMBSTONE}; 16use SyntaxKind::{self, EOF, TOMBSTONE};
17 17
18pub(crate) trait Sink<'a> { 18pub(crate) trait Sink {
19 type Tree; 19 type Tree;
20 20
21 fn new(text: &'a str) -> Self; 21 fn leaf(&mut self, kind: SyntaxKind, text: SmolStr);
22
23 fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
24 fn start_internal(&mut self, kind: SyntaxKind); 22 fn start_internal(&mut self, kind: SyntaxKind);
25 fn finish_internal(&mut self); 23 fn finish_internal(&mut self);
26 fn error(&mut self, err: String); 24 fn error(&mut self, message: String, offset: TextUnit);
27 fn finish(self) -> Self::Tree; 25 fn finish(self) -> Self::Tree;
28} 26}
29 27
30/// Parse a sequence of tokens into the representative node tree 28/// Parse a sequence of tokens into the representative node tree
31pub(crate) fn parse_with<'a, S: Sink<'a>>( 29pub(crate) fn parse_with<S: Sink>(
32 text: &'a str, 30 sink: S,
31 text: &str,
33 tokens: &[Token], 32 tokens: &[Token],
34 parser: fn(&mut Parser), 33 parser: fn(&mut Parser),
35) -> S::Tree { 34) -> S::Tree {
36 let events = { 35 let mut events = {
37 let input = input::ParserInput::new(text, tokens); 36 let input = input::ParserInput::new(text, tokens);
38 let parser_impl = ParserImpl::new(&input); 37 let parser_impl = ParserImpl::new(&input);
39 let mut parser_api = Parser(parser_impl); 38 let mut parser_api = Parser(parser_impl);
40 parser(&mut parser_api); 39 parser(&mut parser_api);
41 parser_api.0.into_events() 40 parser_api.0.into_events()
42 }; 41 };
43 let mut sink = S::new(text); 42 EventProcessor::new(sink, text, tokens, &mut events)
44 process(&mut sink, tokens, events); 43 .process()
45 sink.finish() 44 .finish()
46} 45}
47 46
48/// Implementation details of `Parser`, extracted 47/// Implementation details of `Parser`, extracted