aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_syntax/src/lib.rs33
-rw-r--r--crates/ra_syntax/src/parsing.rs25
-rw-r--r--crates/ra_syntax/src/parsing/builder.rs (renamed from crates/ra_syntax/src/syntax_node/builder.rs)7
-rw-r--r--crates/ra_syntax/src/parsing/grammar.rs (renamed from crates/ra_syntax/src/grammar.rs)40
-rw-r--r--crates/ra_syntax/src/parsing/grammar/attributes.rs (renamed from crates/ra_syntax/src/grammar/attributes.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/expressions.rs (renamed from crates/ra_syntax/src/grammar/expressions.rs)4
-rw-r--r--crates/ra_syntax/src/parsing/grammar/expressions/atom.rs (renamed from crates/ra_syntax/src/grammar/expressions/atom.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/items.rs (renamed from crates/ra_syntax/src/grammar/items.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/items/consts.rs (renamed from crates/ra_syntax/src/grammar/items/consts.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/items/nominal.rs (renamed from crates/ra_syntax/src/grammar/items/nominal.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/items/traits.rs (renamed from crates/ra_syntax/src/grammar/items/traits.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/items/use_item.rs (renamed from crates/ra_syntax/src/grammar/items/use_item.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/params.rs (renamed from crates/ra_syntax/src/grammar/params.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/paths.rs (renamed from crates/ra_syntax/src/grammar/paths.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/patterns.rs (renamed from crates/ra_syntax/src/grammar/patterns.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/type_args.rs (renamed from crates/ra_syntax/src/grammar/type_args.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/type_params.rs (renamed from crates/ra_syntax/src/grammar/type_params.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/grammar/types.rs (renamed from crates/ra_syntax/src/grammar/types.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/lexer.rs (renamed from crates/ra_syntax/src/lexer.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/lexer/classes.rs (renamed from crates/ra_syntax/src/lexer/classes.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/lexer/comments.rs (renamed from crates/ra_syntax/src/lexer/comments.rs)2
-rw-r--r--crates/ra_syntax/src/parsing/lexer/numbers.rs (renamed from crates/ra_syntax/src/lexer/numbers.rs)6
-rw-r--r--crates/ra_syntax/src/parsing/lexer/ptr.rs (renamed from crates/ra_syntax/src/lexer/ptr.rs)0
-rw-r--r--crates/ra_syntax/src/parsing/lexer/strings.rs (renamed from crates/ra_syntax/src/lexer/strings.rs)7
-rw-r--r--crates/ra_syntax/src/parsing/parser_api.rs (renamed from crates/ra_syntax/src/parser_api.rs)30
-rw-r--r--crates/ra_syntax/src/parsing/parser_impl.rs (renamed from crates/ra_syntax/src/parser_impl.rs)31
-rw-r--r--crates/ra_syntax/src/parsing/parser_impl/event.rs (renamed from crates/ra_syntax/src/parser_impl/event.rs)11
-rw-r--r--crates/ra_syntax/src/parsing/parser_impl/input.rs (renamed from crates/ra_syntax/src/parser_impl/input.rs)5
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs (renamed from crates/ra_syntax/src/reparsing.rs)55
-rw-r--r--crates/ra_syntax/src/parsing/token_set.rs (renamed from crates/ra_syntax/src/token_set.rs)8
-rw-r--r--crates/ra_syntax/src/syntax_error.rs (renamed from crates/ra_syntax/src/syntax_node/syntax_error.rs)0
-rw-r--r--crates/ra_syntax/src/syntax_kinds.rs3
-rw-r--r--crates/ra_syntax/src/syntax_node.rs13
-rw-r--r--crates/ra_syntax/src/syntax_text.rs (renamed from crates/ra_syntax/src/syntax_node/syntax_text.rs)0
-rw-r--r--crates/ra_syntax/src/validation.rs2
-rw-r--r--crates/ra_syntax/src/validation/block.rs6
-rw-r--r--crates/ra_syntax/src/validation/byte.rs6
-rw-r--r--crates/ra_syntax/src/validation/byte_string.rs6
-rw-r--r--crates/ra_syntax/src/validation/char.rs6
-rw-r--r--crates/ra_syntax/src/validation/string.rs6
-rw-r--r--crates/tools/src/lib.rs2
41 files changed, 174 insertions, 140 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index cbba1d4ae..b12282b39 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -16,30 +16,29 @@
16#![allow(missing_docs)] 16#![allow(missing_docs)]
17//#![warn(unreachable_pub)] // rust-lang/rust#47816 17//#![warn(unreachable_pub)] // rust-lang/rust#47816
18 18
19mod syntax_kinds;
20mod syntax_node;
21mod syntax_text;
22mod syntax_error;
23mod parsing;
24mod string_lexing;
25mod validation;
26mod ptr;
27
19pub mod algo; 28pub mod algo;
20pub mod ast; 29pub mod ast;
21mod lexer;
22#[macro_use]
23mod token_set;
24mod grammar;
25mod parser_api;
26mod parser_impl;
27mod reparsing;
28mod string_lexing;
29mod syntax_kinds;
30/// Utilities for simple uses of the parser. 30/// Utilities for simple uses of the parser.
31pub mod utils; 31pub mod utils;
32mod validation;
33mod syntax_node;
34mod ptr;
35 32
36pub use rowan::{SmolStr, TextRange, TextUnit}; 33pub use rowan::{SmolStr, TextRange, TextUnit};
37pub use crate::{ 34pub use crate::{
38 ast::AstNode, 35 ast::AstNode,
39 lexer::{tokenize, Token},
40 syntax_kinds::SyntaxKind, 36 syntax_kinds::SyntaxKind,
41 syntax_node::{Direction, SyntaxError, SyntaxNode, WalkEvent, Location, TreeArc}, 37 syntax_error::{SyntaxError, SyntaxErrorKind, Location},
38 syntax_text::SyntaxText,
39 syntax_node::{Direction, SyntaxNode, WalkEvent, TreeArc},
42 ptr::{SyntaxNodePtr, AstPtr}, 40 ptr::{SyntaxNodePtr, AstPtr},
41 parsing::{tokenize, Token},
43}; 42};
44 43
45use ra_text_edit::AtomTextEdit; 44use ra_text_edit::AtomTextEdit;
@@ -59,9 +58,7 @@ impl SourceFile {
59 } 58 }
60 59
61 pub fn parse(text: &str) -> TreeArc<SourceFile> { 60 pub fn parse(text: &str) -> TreeArc<SourceFile> {
62 let tokens = tokenize(&text); 61 let (green, errors) = parsing::parse_text(text);
63 let (green, errors) =
64 parser_impl::parse_with(syntax_node::GreenBuilder::new(), text, &tokens, grammar::root);
65 SourceFile::new(green, errors) 62 SourceFile::new(green, errors)
66 } 63 }
67 64
@@ -70,7 +67,7 @@ impl SourceFile {
70 } 67 }
71 68
72 pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<TreeArc<SourceFile>> { 69 pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<TreeArc<SourceFile>> {
73 reparsing::incremental_reparse(self.syntax(), edit, self.errors()) 70 parsing::incremental_reparse(self.syntax(), edit, self.errors())
74 .map(|(green_node, errors)| SourceFile::new(green_node, errors)) 71 .map(|(green_node, errors)| SourceFile::new(green_node, errors))
75 } 72 }
76 73
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs
new file mode 100644
index 000000000..761accd7b
--- /dev/null
+++ b/crates/ra_syntax/src/parsing.rs
@@ -0,0 +1,25 @@
1#[macro_use]
2mod token_set;
3mod builder;
4mod lexer;
5mod parser_impl;
6mod parser_api;
7mod grammar;
8mod reparsing;
9
10use crate::{
11 SyntaxError,
12 parsing::builder::GreenBuilder,
13 syntax_node::GreenNode,
14};
15
16pub use self::lexer::{tokenize, Token};
17
18pub(crate) use self::reparsing::incremental_reparse;
19
20pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
21 let tokens = tokenize(&text);
22 let (green, errors) =
23 parser_impl::parse_with(GreenBuilder::new(), text, &tokens, grammar::root);
24 (green, errors)
25}
diff --git a/crates/ra_syntax/src/syntax_node/builder.rs b/crates/ra_syntax/src/parsing/builder.rs
index 8abd0f051..9090c60c2 100644
--- a/crates/ra_syntax/src/syntax_node/builder.rs
+++ b/crates/ra_syntax/src/parsing/builder.rs
@@ -1,8 +1,9 @@
1use crate::{ 1use crate::{
2 parser_impl::Sink, 2 parsing::parser_impl::Sink,
3 syntax_node::{GreenNode, RaTypes, SyntaxError}, 3 syntax_node::{GreenNode, RaTypes},
4 SmolStr, SyntaxKind, 4 SmolStr, SyntaxKind, SyntaxError,
5}; 5};
6
6use rowan::GreenNodeBuilder; 7use rowan::GreenNodeBuilder;
7 8
8pub(crate) struct GreenBuilder { 9pub(crate) struct GreenBuilder {
diff --git a/crates/ra_syntax/src/grammar.rs b/crates/ra_syntax/src/parsing/grammar.rs
index 060c0ccdf..bcdcd9f57 100644
--- a/crates/ra_syntax/src/grammar.rs
+++ b/crates/ra_syntax/src/parsing/grammar.rs
@@ -36,26 +36,46 @@ mod type_args;
36mod type_params; 36mod type_params;
37mod types; 37mod types;
38 38
39pub(crate) use self::{
40 expressions::block,
41 items::{
42 enum_variant_list, extern_item_list, impl_item_list, match_arm_list, mod_item_list,
43 named_field_def_list, named_field_list, token_tree, trait_item_list, use_tree_list,
44 },
45};
46use crate::{ 39use crate::{
47 parser_api::{CompletedMarker, Marker, Parser}, 40 SyntaxNode,
48 token_set::TokenSet,
49 SyntaxKind::{self, *}, 41 SyntaxKind::{self, *},
42 parsing::{
43 token_set::TokenSet,
44 parser_api::{CompletedMarker, Marker, Parser}
45 },
50}; 46};
51 47
52pub(crate) fn root(p: &mut Parser) { 48pub(super) fn root(p: &mut Parser) {
53 let m = p.start(); 49 let m = p.start();
54 p.eat(SHEBANG); 50 p.eat(SHEBANG);
55 items::mod_contents(p, false); 51 items::mod_contents(p, false);
56 m.complete(p, SOURCE_FILE); 52 m.complete(p, SOURCE_FILE);
57} 53}
58 54
55pub(super) fn reparser(node: &SyntaxNode) -> Option<fn(&mut Parser)> {
56 let res = match node.kind() {
57 BLOCK => expressions::block,
58 NAMED_FIELD_DEF_LIST => items::named_field_def_list,
59 NAMED_FIELD_LIST => items::named_field_list,
60 ENUM_VARIANT_LIST => items::enum_variant_list,
61 MATCH_ARM_LIST => items::match_arm_list,
62 USE_TREE_LIST => items::use_tree_list,
63 EXTERN_ITEM_LIST => items::extern_item_list,
64 TOKEN_TREE if node.first_child().unwrap().kind() == L_CURLY => items::token_tree,
65 ITEM_LIST => {
66 let parent = node.parent().unwrap();
67 match parent.kind() {
68 IMPL_BLOCK => items::impl_item_list,
69 TRAIT_DEF => items::trait_item_list,
70 MODULE => items::mod_item_list,
71 _ => return None,
72 }
73 }
74 _ => return None,
75 };
76 Some(res)
77}
78
59#[derive(Clone, Copy, PartialEq, Eq)] 79#[derive(Clone, Copy, PartialEq, Eq)]
60enum BlockLike { 80enum BlockLike {
61 Block, 81 Block,
diff --git a/crates/ra_syntax/src/grammar/attributes.rs b/crates/ra_syntax/src/parsing/grammar/attributes.rs
index cd30e8a45..cd30e8a45 100644
--- a/crates/ra_syntax/src/grammar/attributes.rs
+++ b/crates/ra_syntax/src/parsing/grammar/attributes.rs
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/parsing/grammar/expressions.rs
index 28fcb1f7d..d5a4f4d7b 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/parsing/grammar/expressions.rs
@@ -138,7 +138,7 @@ enum Op {
138} 138}
139 139
140fn current_op(p: &Parser) -> (u8, Op) { 140fn current_op(p: &Parser) -> (u8, Op) {
141 if let Some(t) = p.next3() { 141 if let Some(t) = p.current3() {
142 match t { 142 match t {
143 (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)), 143 (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)),
144 (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)), 144 (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)),
@@ -146,7 +146,7 @@ fn current_op(p: &Parser) -> (u8, Op) {
146 } 146 }
147 } 147 }
148 148
149 if let Some(t) = p.next2() { 149 if let Some(t) = p.current2() {
150 match t { 150 match t {
151 (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), 151 (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)),
152 (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), 152 (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)),
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/parsing/grammar/expressions/atom.rs
index e74305b6a..e74305b6a 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/parsing/grammar/expressions/atom.rs
diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/parsing/grammar/items.rs
index 4b962c1f3..4b962c1f3 100644
--- a/crates/ra_syntax/src/grammar/items.rs
+++ b/crates/ra_syntax/src/parsing/grammar/items.rs
diff --git a/crates/ra_syntax/src/grammar/items/consts.rs b/crates/ra_syntax/src/parsing/grammar/items/consts.rs
index 5a5852f83..5a5852f83 100644
--- a/crates/ra_syntax/src/grammar/items/consts.rs
+++ b/crates/ra_syntax/src/parsing/grammar/items/consts.rs
diff --git a/crates/ra_syntax/src/grammar/items/nominal.rs b/crates/ra_syntax/src/parsing/grammar/items/nominal.rs
index ff9b38f9c..ff9b38f9c 100644
--- a/crates/ra_syntax/src/grammar/items/nominal.rs
+++ b/crates/ra_syntax/src/parsing/grammar/items/nominal.rs
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/parsing/grammar/items/traits.rs
index d5a8ccd98..d5a8ccd98 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/parsing/grammar/items/traits.rs
diff --git a/crates/ra_syntax/src/grammar/items/use_item.rs b/crates/ra_syntax/src/parsing/grammar/items/use_item.rs
index 5111d37eb..5111d37eb 100644
--- a/crates/ra_syntax/src/grammar/items/use_item.rs
+++ b/crates/ra_syntax/src/parsing/grammar/items/use_item.rs
diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/parsing/grammar/params.rs
index 185386569..185386569 100644
--- a/crates/ra_syntax/src/grammar/params.rs
+++ b/crates/ra_syntax/src/parsing/grammar/params.rs
diff --git a/crates/ra_syntax/src/grammar/paths.rs b/crates/ra_syntax/src/parsing/grammar/paths.rs
index 33a11886c..33a11886c 100644
--- a/crates/ra_syntax/src/grammar/paths.rs
+++ b/crates/ra_syntax/src/parsing/grammar/paths.rs
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/parsing/grammar/patterns.rs
index 9d7da639d..9d7da639d 100644
--- a/crates/ra_syntax/src/grammar/patterns.rs
+++ b/crates/ra_syntax/src/parsing/grammar/patterns.rs
diff --git a/crates/ra_syntax/src/grammar/type_args.rs b/crates/ra_syntax/src/parsing/grammar/type_args.rs
index f889419c5..f889419c5 100644
--- a/crates/ra_syntax/src/grammar/type_args.rs
+++ b/crates/ra_syntax/src/parsing/grammar/type_args.rs
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/parsing/grammar/type_params.rs
index 40f998682..40f998682 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/parsing/grammar/type_params.rs
diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/parsing/grammar/types.rs
index adc189a29..adc189a29 100644
--- a/crates/ra_syntax/src/grammar/types.rs
+++ b/crates/ra_syntax/src/parsing/grammar/types.rs
diff --git a/crates/ra_syntax/src/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs
index f9362120e..f9362120e 100644
--- a/crates/ra_syntax/src/lexer.rs
+++ b/crates/ra_syntax/src/parsing/lexer.rs
diff --git a/crates/ra_syntax/src/lexer/classes.rs b/crates/ra_syntax/src/parsing/lexer/classes.rs
index 4235d2648..4235d2648 100644
--- a/crates/ra_syntax/src/lexer/classes.rs
+++ b/crates/ra_syntax/src/parsing/lexer/classes.rs
diff --git a/crates/ra_syntax/src/lexer/comments.rs b/crates/ra_syntax/src/parsing/lexer/comments.rs
index afe6886a1..8bbbe659b 100644
--- a/crates/ra_syntax/src/lexer/comments.rs
+++ b/crates/ra_syntax/src/parsing/lexer/comments.rs
@@ -1,4 +1,4 @@
1use crate::lexer::ptr::Ptr; 1use crate::parsing::lexer::ptr::Ptr;
2 2
3use crate::SyntaxKind::{self, *}; 3use crate::SyntaxKind::{self, *};
4 4
diff --git a/crates/ra_syntax/src/lexer/numbers.rs b/crates/ra_syntax/src/parsing/lexer/numbers.rs
index 46daf5e52..7f6abe1d5 100644
--- a/crates/ra_syntax/src/lexer/numbers.rs
+++ b/crates/ra_syntax/src/parsing/lexer/numbers.rs
@@ -1,5 +1,7 @@
1use crate::lexer::classes::*; 1use crate::parsing::lexer::{
2use crate::lexer::ptr::Ptr; 2 ptr::Ptr,
3 classes::*,
4};
3 5
4use crate::SyntaxKind::{self, *}; 6use crate::SyntaxKind::{self, *};
5 7
diff --git a/crates/ra_syntax/src/lexer/ptr.rs b/crates/ra_syntax/src/parsing/lexer/ptr.rs
index c341c4176..c341c4176 100644
--- a/crates/ra_syntax/src/lexer/ptr.rs
+++ b/crates/ra_syntax/src/parsing/lexer/ptr.rs
diff --git a/crates/ra_syntax/src/lexer/strings.rs b/crates/ra_syntax/src/parsing/lexer/strings.rs
index 5c1cf3e9c..f74acff9e 100644
--- a/crates/ra_syntax/src/lexer/strings.rs
+++ b/crates/ra_syntax/src/parsing/lexer/strings.rs
@@ -1,6 +1,7 @@
1use crate::SyntaxKind::{self, *}; 1use crate::{
2 2 parsing::lexer::ptr::Ptr,
3use crate::lexer::ptr::Ptr; 3 SyntaxKind::{self, *},
4};
4 5
5pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char>) -> bool { 6pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char>) -> bool {
6 match (c, c1, c2) { 7 match (c, c1, c2) {
diff --git a/crates/ra_syntax/src/parser_api.rs b/crates/ra_syntax/src/parsing/parser_api.rs
index 504df753e..781c407de 100644
--- a/crates/ra_syntax/src/parser_api.rs
+++ b/crates/ra_syntax/src/parsing/parser_api.rs
@@ -1,9 +1,11 @@
1use drop_bomb::DropBomb; 1use drop_bomb::DropBomb;
2 2
3use crate::{ 3use crate::{
4 parser_impl::ParserImpl,
5 token_set::TokenSet,
6 SyntaxKind::{self, ERROR}, 4 SyntaxKind::{self, ERROR},
5 parsing::{
6 token_set::TokenSet,
7 parser_impl::ParserImpl
8 },
7}; 9};
8 10
9/// `Parser` struct provides the low-level API for 11/// `Parser` struct provides the low-level API for
@@ -25,6 +27,22 @@ impl<'t> Parser<'t> {
25 self.nth(0) 27 self.nth(0)
26 } 28 }
27 29
30 /// Returns the kinds of the current two tokens, if they are not separated
31 /// by trivia.
32 ///
33 /// Useful for parsing things like `>>`.
34 pub(crate) fn current2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
35 self.0.current2()
36 }
37
38 /// Returns the kinds of the current three tokens, if they are not separated
39 /// by trivia.
40 ///
41 /// Useful for parsing things like `=>>`.
42 pub(crate) fn current3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
43 self.0.current3()
44 }
45
28 /// Lookahead operation: returns the kind of the next nth 46 /// Lookahead operation: returns the kind of the next nth
29 /// token. 47 /// token.
30 pub(crate) fn nth(&self, n: u32) -> SyntaxKind { 48 pub(crate) fn nth(&self, n: u32) -> SyntaxKind {
@@ -41,14 +59,6 @@ impl<'t> Parser<'t> {
41 kinds.contains(self.current()) 59 kinds.contains(self.current())
42 } 60 }
43 61
44 pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
45 self.0.next2()
46 }
47
48 pub(crate) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
49 self.0.next3()
50 }
51
52 /// Checks if the current token is contextual keyword with text `t`. 62 /// Checks if the current token is contextual keyword with text `t`.
53 pub(crate) fn at_contextual_kw(&self, t: &str) -> bool { 63 pub(crate) fn at_contextual_kw(&self, t: &str) -> bool {
54 self.0.at_kw(t) 64 self.0.at_kw(t)
diff --git a/crates/ra_syntax/src/parser_impl.rs b/crates/ra_syntax/src/parsing/parser_impl.rs
index d99615d72..8cce1ab01 100644
--- a/crates/ra_syntax/src/parser_impl.rs
+++ b/crates/ra_syntax/src/parsing/parser_impl.rs
@@ -4,22 +4,21 @@ mod input;
4use std::cell::Cell; 4use std::cell::Cell;
5 5
6use crate::{ 6use crate::{
7 lexer::Token,
8 parser_api::Parser,
9 parser_impl::{
10 event::{Event, EventProcessor},
11 input::{InputPosition, ParserInput},
12 },
13 SmolStr, 7 SmolStr,
14 syntax_node::syntax_error::{ 8 syntax_error::{ParseError, SyntaxError},
15 ParseError, 9 parsing::{
16 SyntaxError, 10 lexer::Token,
11 parser_api::Parser,
12 parser_impl::{
13 event::{Event, EventProcessor},
14 input::{InputPosition, ParserInput},
15 },
17 }, 16 },
18}; 17};
19 18
20use crate::SyntaxKind::{self, EOF, TOMBSTONE}; 19use crate::SyntaxKind::{self, EOF, TOMBSTONE};
21 20
22pub(crate) trait Sink { 21pub(super) trait Sink {
23 type Tree; 22 type Tree;
24 23
25 /// Adds new leaf to the current branch. 24 /// Adds new leaf to the current branch.
@@ -41,7 +40,7 @@ pub(crate) trait Sink {
41} 40}
42 41
43/// Parse a sequence of tokens into the representative node tree 42/// Parse a sequence of tokens into the representative node tree
44pub(crate) fn parse_with<S: Sink>( 43pub(super) fn parse_with<S: Sink>(
45 sink: S, 44 sink: S,
46 text: &str, 45 text: &str,
47 tokens: &[Token], 46 tokens: &[Token],
@@ -60,7 +59,7 @@ pub(crate) fn parse_with<S: Sink>(
60/// Implementation details of `Parser`, extracted 59/// Implementation details of `Parser`, extracted
61/// to a separate struct in order not to pollute 60/// to a separate struct in order not to pollute
62/// the public API of the `Parser`. 61/// the public API of the `Parser`.
63pub(crate) struct ParserImpl<'t> { 62pub(super) struct ParserImpl<'t> {
64 parser_input: &'t ParserInput<'t>, 63 parser_input: &'t ParserInput<'t>,
65 pos: InputPosition, 64 pos: InputPosition,
66 events: Vec<Event>, 65 events: Vec<Event>,
@@ -68,7 +67,7 @@ pub(crate) struct ParserImpl<'t> {
68} 67}
69 68
70impl<'t> ParserImpl<'t> { 69impl<'t> ParserImpl<'t> {
71 pub(crate) fn new(inp: &'t ParserInput<'t>) -> ParserImpl<'t> { 70 fn new(inp: &'t ParserInput<'t>) -> ParserImpl<'t> {
72 ParserImpl { 71 ParserImpl {
73 parser_input: inp, 72 parser_input: inp,
74 pos: InputPosition::new(), 73 pos: InputPosition::new(),
@@ -77,12 +76,12 @@ impl<'t> ParserImpl<'t> {
77 } 76 }
78 } 77 }
79 78
80 pub(crate) fn into_events(self) -> Vec<Event> { 79 fn into_events(self) -> Vec<Event> {
81 assert_eq!(self.nth(0), EOF); 80 assert_eq!(self.nth(0), EOF);
82 self.events 81 self.events
83 } 82 }
84 83
85 pub(super) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> { 84 pub(super) fn current2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
86 let c1 = self.parser_input.kind(self.pos); 85 let c1 = self.parser_input.kind(self.pos);
87 let c2 = self.parser_input.kind(self.pos + 1); 86 let c2 = self.parser_input.kind(self.pos + 1);
88 if self.parser_input.token_start_at(self.pos + 1) 87 if self.parser_input.token_start_at(self.pos + 1)
@@ -94,7 +93,7 @@ impl<'t> ParserImpl<'t> {
94 } 93 }
95 } 94 }
96 95
97 pub(super) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> { 96 pub(super) fn current3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
98 let c1 = self.parser_input.kind(self.pos); 97 let c1 = self.parser_input.kind(self.pos);
99 let c2 = self.parser_input.kind(self.pos + 1); 98 let c2 = self.parser_input.kind(self.pos + 1);
100 let c3 = self.parser_input.kind(self.pos + 2); 99 let c3 = self.parser_input.kind(self.pos + 2);
diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parsing/parser_impl/event.rs
index b45830c61..2ddbdd34d 100644
--- a/crates/ra_syntax/src/parser_impl/event.rs
+++ b/crates/ra_syntax/src/parsing/parser_impl/event.rs
@@ -7,19 +7,22 @@
7//! tree builder: the parser produces a stream of events like 7//! tree builder: the parser produces a stream of events like
8//! `start node`, `finish node`, and `FileBuilder` converts 8//! `start node`, `finish node`, and `FileBuilder` converts
9//! this stream to a real tree. 9//! this stream to a real tree.
10use std::mem;
11
10use crate::{ 12use crate::{
11 lexer::Token,
12 parser_impl::Sink,
13 SmolStr, 13 SmolStr,
14 SyntaxKind::{self, *}, 14 SyntaxKind::{self, *},
15 TextRange, TextUnit, 15 TextRange, TextUnit,
16 syntax_node::syntax_error::{ 16 syntax_error::{
17 ParseError, 17 ParseError,
18 SyntaxError, 18 SyntaxError,
19 SyntaxErrorKind, 19 SyntaxErrorKind,
20 }, 20 },
21 parsing::{
22 lexer::Token,
23 parser_impl::Sink,
24 },
21}; 25};
22use std::mem;
23 26
24/// `Parser` produces a flat list of `Event`s. 27/// `Parser` produces a flat list of `Event`s.
25/// They are converted to a tree-structure in 28/// They are converted to a tree-structure in
diff --git a/crates/ra_syntax/src/parser_impl/input.rs b/crates/ra_syntax/src/parsing/parser_impl/input.rs
index 616a26fdc..275d94918 100644
--- a/crates/ra_syntax/src/parser_impl/input.rs
+++ b/crates/ra_syntax/src/parsing/parser_impl/input.rs
@@ -1,4 +1,7 @@
1use crate::{lexer::Token, SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit}; 1use crate::{
2 SyntaxKind, SyntaxKind::EOF, TextRange, TextUnit,
3 parsing::lexer::Token,
4};
2 5
3use std::ops::{Add, AddAssign}; 6use std::ops::{Add, AddAssign};
4 7
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index dd751465c..edf3fa291 100644
--- a/crates/ra_syntax/src/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -1,10 +1,17 @@
1use crate::algo; 1use crate::{
2use crate::grammar; 2 SyntaxKind::*, TextRange, TextUnit,
3use crate::lexer::{tokenize, Token}; 3 algo,
4use crate::parser_api::Parser; 4 syntax_node::{GreenNode, SyntaxNode},
5use crate::parser_impl; 5 syntax_error::SyntaxError,
6use crate::syntax_node::{self, GreenNode, SyntaxError, SyntaxNode}; 6 parsing::{
7use crate::{SyntaxKind::*, TextRange, TextUnit}; 7 grammar,
8 parser_impl,
9 builder::GreenBuilder,
10 parser_api::Parser,
11 lexer::{tokenize, Token},
12 }
13};
14
8use ra_text_edit::AtomTextEdit; 15use ra_text_edit::AtomTextEdit;
9 16
10pub(crate) fn incremental_reparse( 17pub(crate) fn incremental_reparse(
@@ -56,7 +63,7 @@ fn reparse_block<'node>(
56 return None; 63 return None;
57 } 64 }
58 let (green, new_errors) = 65 let (green, new_errors) =
59 parser_impl::parse_with(syntax_node::GreenBuilder::new(), &text, &tokens, reparser); 66 parser_impl::parse_with(GreenBuilder::new(), &text, &tokens, reparser);
60 Some((node, green, new_errors)) 67 Some((node, green, new_errors))
61} 68}
62 69
@@ -72,34 +79,12 @@ fn is_contextual_kw(text: &str) -> bool {
72 } 79 }
73} 80}
74 81
75type ParseFn = fn(&mut Parser); 82fn find_reparsable_node(
76fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> { 83 node: &SyntaxNode,
84 range: TextRange,
85) -> Option<(&SyntaxNode, fn(&mut Parser))> {
77 let node = algo::find_covering_node(node, range); 86 let node = algo::find_covering_node(node, range);
78 return node.ancestors().filter_map(|node| reparser(node).map(|r| (node, r))).next(); 87 node.ancestors().find_map(|node| grammar::reparser(node).map(|r| (node, r)))
79
80 fn reparser(node: &SyntaxNode) -> Option<ParseFn> {
81 let res = match node.kind() {
82 BLOCK => grammar::block,
83 NAMED_FIELD_DEF_LIST => grammar::named_field_def_list,
84 NAMED_FIELD_LIST => grammar::named_field_list,
85 ENUM_VARIANT_LIST => grammar::enum_variant_list,
86 MATCH_ARM_LIST => grammar::match_arm_list,
87 USE_TREE_LIST => grammar::use_tree_list,
88 EXTERN_ITEM_LIST => grammar::extern_item_list,
89 TOKEN_TREE if node.first_child().unwrap().kind() == L_CURLY => grammar::token_tree,
90 ITEM_LIST => {
91 let parent = node.parent().unwrap();
92 match parent.kind() {
93 IMPL_BLOCK => grammar::impl_item_list,
94 TRAIT_DEF => grammar::trait_item_list,
95 MODULE => grammar::mod_item_list,
96 _ => return None,
97 }
98 }
99 _ => return None,
100 };
101 Some(res)
102 }
103} 88}
104 89
105fn is_balanced(tokens: &[Token]) -> bool { 90fn is_balanced(tokens: &[Token]) -> bool {
diff --git a/crates/ra_syntax/src/token_set.rs b/crates/ra_syntax/src/parsing/token_set.rs
index b3fe633e0..5719fe5a2 100644
--- a/crates/ra_syntax/src/token_set.rs
+++ b/crates/ra_syntax/src/parsing/token_set.rs
@@ -4,19 +4,19 @@ use crate::SyntaxKind;
4pub(crate) struct TokenSet(u128); 4pub(crate) struct TokenSet(u128);
5 5
6impl TokenSet { 6impl TokenSet {
7 pub const fn empty() -> TokenSet { 7 pub(crate) const fn empty() -> TokenSet {
8 TokenSet(0) 8 TokenSet(0)
9 } 9 }
10 10
11 pub const fn singleton(kind: SyntaxKind) -> TokenSet { 11 pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet {
12 TokenSet(mask(kind)) 12 TokenSet(mask(kind))
13 } 13 }
14 14
15 pub const fn union(self, other: TokenSet) -> TokenSet { 15 pub(crate) const fn union(self, other: TokenSet) -> TokenSet {
16 TokenSet(self.0 | other.0) 16 TokenSet(self.0 | other.0)
17 } 17 }
18 18
19 pub fn contains(&self, kind: SyntaxKind) -> bool { 19 pub(crate) fn contains(&self, kind: SyntaxKind) -> bool {
20 self.0 & mask(kind) != 0 20 self.0 & mask(kind) != 0
21 } 21 }
22} 22}
diff --git a/crates/ra_syntax/src/syntax_node/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs
index 4ff998090..4ff998090 100644
--- a/crates/ra_syntax/src/syntax_node/syntax_error.rs
+++ b/crates/ra_syntax/src/syntax_error.rs
diff --git a/crates/ra_syntax/src/syntax_kinds.rs b/crates/ra_syntax/src/syntax_kinds.rs
index d53886676..c1118c5ab 100644
--- a/crates/ra_syntax/src/syntax_kinds.rs
+++ b/crates/ra_syntax/src/syntax_kinds.rs
@@ -1,8 +1,9 @@
1mod generated; 1mod generated;
2 2
3use crate::SyntaxKind::*;
4use std::fmt; 3use std::fmt;
5 4
5use crate::SyntaxKind::*;
6
6pub use self::generated::SyntaxKind; 7pub use self::generated::SyntaxKind;
7 8
8impl fmt::Debug for SyntaxKind { 9impl fmt::Debug for SyntaxKind {
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs
index ed48739f8..aa627398d 100644
--- a/crates/ra_syntax/src/syntax_node.rs
+++ b/crates/ra_syntax/src/syntax_node.rs
@@ -1,15 +1,12 @@
1mod builder;
2pub mod syntax_error;
3mod syntax_text;
4
5use std::{fmt, borrow::Borrow}; 1use std::{fmt, borrow::Borrow};
6 2
7use self::syntax_text::SyntaxText;
8use crate::{SmolStr, SyntaxKind, TextRange};
9use rowan::{Types, TransparentNewType}; 3use rowan::{Types, TransparentNewType};
10 4
11pub(crate) use self::builder::GreenBuilder; 5use crate::{
12pub use self::syntax_error::{SyntaxError, SyntaxErrorKind, Location}; 6 SmolStr, SyntaxKind, TextRange, SyntaxText,
7 syntax_error::SyntaxError,
8};
9
13pub use rowan::WalkEvent; 10pub use rowan::WalkEvent;
14 11
15#[derive(Debug, Clone, Copy)] 12#[derive(Debug, Clone, Copy)]
diff --git a/crates/ra_syntax/src/syntax_node/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs
index 84e5b231a..84e5b231a 100644
--- a/crates/ra_syntax/src/syntax_node/syntax_text.rs
+++ b/crates/ra_syntax/src/syntax_text.rs
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index 10672d6bf..69958f0d7 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -5,7 +5,7 @@ mod string;
5mod block; 5mod block;
6 6
7use crate::{ 7use crate::{
8 SourceFile, syntax_node::SyntaxError, AstNode, 8 SourceFile, SyntaxError, AstNode,
9 ast, 9 ast,
10 algo::visit::{visitor_ctx, VisitorCtx}, 10 algo::visit::{visitor_ctx, VisitorCtx},
11}; 11};
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs
index de949d967..f2cf3cbbd 100644
--- a/crates/ra_syntax/src/validation/block.rs
+++ b/crates/ra_syntax/src/validation/block.rs
@@ -1,9 +1,7 @@
1use crate::{SyntaxKind::*, 1use crate::{SyntaxKind::*,
2 ast::{self, AttrsOwner, AstNode}, 2 ast::{self, AttrsOwner, AstNode},
3 syntax_node::{ 3 SyntaxError,
4 SyntaxError, 4 SyntaxErrorKind::*,
5 SyntaxErrorKind::*,
6 },
7}; 5};
8 6
9pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec<SyntaxError>) { 7pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec<SyntaxError>) {
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs
index acdc12552..838e7a65f 100644
--- a/crates/ra_syntax/src/validation/byte.rs
+++ b/crates/ra_syntax/src/validation/byte.rs
@@ -5,10 +5,8 @@ use crate::{
5 string_lexing::{self, StringComponentKind}, 5 string_lexing::{self, StringComponentKind},
6 TextRange, 6 TextRange,
7 validation::char, 7 validation::char,
8 syntax_node::{ 8 SyntaxError,
9 SyntaxError, 9 SyntaxErrorKind::*,
10 SyntaxErrorKind::*,
11 },
12}; 10};
13 11
14pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError>) { 12pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec<SyntaxError>) {
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs
index 69a98b640..64c7054a1 100644
--- a/crates/ra_syntax/src/validation/byte_string.rs
+++ b/crates/ra_syntax/src/validation/byte_string.rs
@@ -1,10 +1,8 @@
1use crate::{ 1use crate::{
2 ast::{self, AstNode, AstToken}, 2 ast::{self, AstNode, AstToken},
3 string_lexing::{self, StringComponentKind}, 3 string_lexing::{self, StringComponentKind},
4 syntax_node::{ 4 SyntaxError,
5 SyntaxError, 5 SyntaxErrorKind::*,
6 SyntaxErrorKind::*,
7 },
8}; 6};
9 7
10use super::byte; 8use super::byte;
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs
index 26c15e36d..3169ed590 100644
--- a/crates/ra_syntax/src/validation/char.rs
+++ b/crates/ra_syntax/src/validation/char.rs
@@ -8,10 +8,8 @@ use crate::{
8 ast::{self, AstNode, AstToken}, 8 ast::{self, AstNode, AstToken},
9 string_lexing::{self, StringComponentKind}, 9 string_lexing::{self, StringComponentKind},
10 TextRange, 10 TextRange,
11 syntax_node::{ 11 SyntaxError,
12 SyntaxError, 12 SyntaxErrorKind::*,
13 SyntaxErrorKind::*,
14 },
15}; 13};
16 14
17pub(super) fn validate_char_node(node: &ast::Char, errors: &mut Vec<SyntaxError>) { 15pub(super) fn validate_char_node(node: &ast::Char, errors: &mut Vec<SyntaxError>) {
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs
index 2f7f9c7c4..d857d088c 100644
--- a/crates/ra_syntax/src/validation/string.rs
+++ b/crates/ra_syntax/src/validation/string.rs
@@ -1,10 +1,8 @@
1use crate::{ 1use crate::{
2 ast::{self, AstNode, AstToken}, 2 ast::{self, AstNode, AstToken},
3 string_lexing, 3 string_lexing,
4 syntax_node::{ 4 SyntaxError,
5 SyntaxError, 5 SyntaxErrorKind::*,
6 SyntaxErrorKind::*,
7 },
8}; 6};
9 7
10use super::char; 8use super::char;
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index ef9c613a7..0a10d2737 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -14,7 +14,7 @@ pub use teraron::{Mode, Overwrite, Verify};
14pub type Result<T> = std::result::Result<T, failure::Error>; 14pub type Result<T> = std::result::Result<T, failure::Error>;
15 15
16pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron"; 16pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
17const GRAMMAR_DIR: &str = "crates/ra_syntax/src/grammar"; 17const GRAMMAR_DIR: &str = "crates/ra_syntax/src/parsing/grammar";
18const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/ok"; 18const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/ok";
19const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/err"; 19const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/err";
20 20