diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
commit | d77b5857c2420666e84dcd433f254e000e2843aa (patch) | |
tree | 416e333019e349bf4ee369f2548d9e6f6a9c67e9 /crates/ra_syntax/src/parsing.rs | |
parent | 18b0c509f77a8e06141fee6668532cced1ebf5d8 (diff) | |
parent | 46179230a05331b1debd4dfa3bb197fa38d92347 (diff) |
Merge #867
867: This moves the parser to separate crate r=matklad a=matklad
That makes parser independent form both the token and the tree representation.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing.rs | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs index 7e1b32035..0a11600e1 100644 --- a/crates/ra_syntax/src/parsing.rs +++ b/crates/ra_syntax/src/parsing.rs | |||
@@ -1,50 +1,28 @@ | |||
1 | #[macro_use] | ||
2 | mod token_set; | ||
3 | mod builder; | 1 | mod builder; |
4 | mod lexer; | 2 | mod lexer; |
5 | mod event; | ||
6 | mod input; | 3 | mod input; |
7 | mod parser; | ||
8 | mod grammar; | ||
9 | mod reparsing; | 4 | mod reparsing; |
10 | 5 | ||
6 | use ra_parser::{parse, ParseError}; | ||
7 | |||
11 | use crate::{ | 8 | use crate::{ |
12 | SyntaxKind, SyntaxError, | 9 | SyntaxKind, SyntaxError, |
13 | parsing::{ | 10 | parsing::{ |
14 | builder::TreeBuilder, | 11 | builder::TreeBuilder, |
15 | input::ParserInput, | 12 | input::ParserInput, |
16 | event::process, | ||
17 | parser::Parser, | ||
18 | }, | 13 | }, |
19 | syntax_node::GreenNode, | 14 | syntax_node::GreenNode, |
20 | }; | 15 | }; |
21 | 16 | ||
22 | pub use self::lexer::{tokenize, Token}; | 17 | pub use self::lexer::{tokenize, Token}; |
23 | 18 | ||
24 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
25 | pub struct ParseError(pub String); | ||
26 | |||
27 | pub(crate) use self::reparsing::incremental_reparse; | 19 | pub(crate) use self::reparsing::incremental_reparse; |
28 | 20 | ||
29 | pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { | 21 | pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { |
30 | let tokens = tokenize(&text); | 22 | let tokens = tokenize(&text); |
31 | let tree_sink = TreeBuilder::new(text, &tokens); | 23 | let token_source = ParserInput::new(text, &tokens); |
32 | parse_with(tree_sink, text, &tokens, grammar::root) | 24 | let mut tree_sink = TreeBuilder::new(text, &tokens); |
33 | } | 25 | parse(&token_source, &mut tree_sink); |
34 | |||
35 | fn parse_with<S: TreeSink>( | ||
36 | mut tree_sink: S, | ||
37 | text: &str, | ||
38 | tokens: &[Token], | ||
39 | f: fn(&mut Parser), | ||
40 | ) -> S::Tree { | ||
41 | let events = { | ||
42 | let input = ParserInput::new(text, &tokens); | ||
43 | let mut p = Parser::new(&input); | ||
44 | f(&mut p); | ||
45 | p.finish() | ||
46 | }; | ||
47 | process(&mut tree_sink, events); | ||
48 | tree_sink.finish() | 26 | tree_sink.finish() |
49 | } | 27 | } |
50 | 28 | ||