aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-21 10:46:17 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-21 10:46:17 +0000
commitd77b5857c2420666e84dcd433f254e000e2843aa (patch)
tree416e333019e349bf4ee369f2548d9e6f6a9c67e9 /crates/ra_syntax/src/parsing.rs
parent18b0c509f77a8e06141fee6668532cced1ebf5d8 (diff)
parent46179230a05331b1debd4dfa3bb197fa38d92347 (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.rs32
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]
2mod token_set;
3mod builder; 1mod builder;
4mod lexer; 2mod lexer;
5mod event;
6mod input; 3mod input;
7mod parser;
8mod grammar;
9mod reparsing; 4mod reparsing;
10 5
6use ra_parser::{parse, ParseError};
7
11use crate::{ 8use 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
22pub use self::lexer::{tokenize, Token}; 17pub use self::lexer::{tokenize, Token};
23 18
24#[derive(Debug, Clone, PartialEq, Eq, Hash)]
25pub struct ParseError(pub String);
26
27pub(crate) use self::reparsing::incremental_reparse; 19pub(crate) use self::reparsing::incremental_reparse;
28 20
29pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { 21pub(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
35fn 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