aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs2
-rw-r--r--crates/ra_syntax/src/lib.rs14
-rw-r--r--crates/ra_syntax/src/parsing.rs14
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs2
-rw-r--r--crates/ra_syntax/src/parsing/text_token_source.rs14
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs2
-rw-r--r--crates/ra_syntax/src/syntax_node.rs2
8 files changed, 26 insertions, 26 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
index f2789e6a3..eec4bd845 100644
--- a/crates/ra_syntax/Cargo.toml
+++ b/crates/ra_syntax/Cargo.toml
@@ -21,7 +21,7 @@ once_cell = "1.3.1"
21stdx = { path = "../stdx" } 21stdx = { path = "../stdx" }
22 22
23text_edit = { path = "../text_edit" } 23text_edit = { path = "../text_edit" }
24ra_parser = { path = "../ra_parser" } 24parser = { path = "../parser" }
25 25
26# This crate transitively depends on `smol_str` via `rowan`. 26# This crate transitively depends on `smol_str` via `rowan`.
27# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here 27# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 733e97877..50c1c157d 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -4,7 +4,7 @@
4use std::fmt; 4use std::fmt;
5 5
6use itertools::Itertools; 6use itertools::Itertools;
7use ra_parser::SyntaxKind; 7use parser::SyntaxKind;
8 8
9use crate::{ 9use crate::{
10 ast::{self, support, AstNode, NameOwner, SyntaxNode}, 10 ast::{self, support, AstNode, NameOwner, SyntaxNode},
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 465607f55..7f8da66af 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -11,7 +11,7 @@
11//! 11//!
12//! The most interesting modules here are `syntax_node` (which defines concrete 12//! The most interesting modules here are `syntax_node` (which defines concrete
13//! syntax tree) and `ast` (which defines abstract syntax tree on top of the 13//! syntax tree) and `ast` (which defines abstract syntax tree on top of the
14//! CST). The actual parser live in a separate `ra_parser` crate, though the 14//! CST). The actual parser live in a separate `parser` crate, though the
15//! lexer lives in this crate. 15//! lexer lives in this crate.
16//! 16//!
17//! See `api_walkthrough` test in this file for a quick API tour! 17//! See `api_walkthrough` test in this file for a quick API tour!
@@ -53,7 +53,7 @@ pub use crate::{
53 SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder, 53 SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder,
54 }, 54 },
55}; 55};
56pub use ra_parser::{SyntaxKind, T}; 56pub use parser::{SyntaxKind, T};
57pub use rowan::{SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent}; 57pub use rowan::{SmolStr, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent};
58 58
59/// `Parse` is the result of the parsing: a syntax tree and a collection of 59/// `Parse` is the result of the parsing: a syntax tree and a collection of
@@ -169,35 +169,35 @@ impl SourceFile {
169impl ast::Path { 169impl ast::Path {
170 /// Returns `text`, parsed as a path, but only if it has no errors. 170 /// Returns `text`, parsed as a path, but only if it has no errors.
171 pub fn parse(text: &str) -> Result<Self, ()> { 171 pub fn parse(text: &str) -> Result<Self, ()> {
172 parsing::parse_text_fragment(text, ra_parser::FragmentKind::Path) 172 parsing::parse_text_fragment(text, parser::FragmentKind::Path)
173 } 173 }
174} 174}
175 175
176impl ast::Pat { 176impl ast::Pat {
177 /// Returns `text`, parsed as a pattern, but only if it has no errors. 177 /// Returns `text`, parsed as a pattern, but only if it has no errors.
178 pub fn parse(text: &str) -> Result<Self, ()> { 178 pub fn parse(text: &str) -> Result<Self, ()> {
179 parsing::parse_text_fragment(text, ra_parser::FragmentKind::Pattern) 179 parsing::parse_text_fragment(text, parser::FragmentKind::Pattern)
180 } 180 }
181} 181}
182 182
183impl ast::Expr { 183impl ast::Expr {
184 /// Returns `text`, parsed as an expression, but only if it has no errors. 184 /// Returns `text`, parsed as an expression, but only if it has no errors.
185 pub fn parse(text: &str) -> Result<Self, ()> { 185 pub fn parse(text: &str) -> Result<Self, ()> {
186 parsing::parse_text_fragment(text, ra_parser::FragmentKind::Expr) 186 parsing::parse_text_fragment(text, parser::FragmentKind::Expr)
187 } 187 }
188} 188}
189 189
190impl ast::Item { 190impl ast::Item {
191 /// Returns `text`, parsed as an item, but only if it has no errors. 191 /// Returns `text`, parsed as an item, but only if it has no errors.
192 pub fn parse(text: &str) -> Result<Self, ()> { 192 pub fn parse(text: &str) -> Result<Self, ()> {
193 parsing::parse_text_fragment(text, ra_parser::FragmentKind::Item) 193 parsing::parse_text_fragment(text, parser::FragmentKind::Item)
194 } 194 }
195} 195}
196 196
197impl ast::Type { 197impl ast::Type {
198 /// Returns `text`, parsed as an type reference, but only if it has no errors. 198 /// Returns `text`, parsed as an type reference, but only if it has no errors.
199 pub fn parse(text: &str) -> Result<Self, ()> { 199 pub fn parse(text: &str) -> Result<Self, ()> {
200 parsing::parse_text_fragment(text, ra_parser::FragmentKind::Type) 200 parsing::parse_text_fragment(text, parser::FragmentKind::Type)
201 } 201 }
202} 202}
203 203
diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs
index 0ed3c20ef..68a39eb21 100644
--- a/crates/ra_syntax/src/parsing.rs
+++ b/crates/ra_syntax/src/parsing.rs
@@ -1,4 +1,4 @@
1//! Lexing, bridging to ra_parser (which does the actual parsing) and 1//! Lexing, bridging to parser (which does the actual parsing) and
2//! incremental reparsing. 2//! incremental reparsing.
3 3
4mod lexer; 4mod lexer;
@@ -13,7 +13,7 @@ use text_tree_sink::TextTreeSink;
13pub use lexer::*; 13pub use lexer::*;
14 14
15pub(crate) use self::reparsing::incremental_reparse; 15pub(crate) use self::reparsing::incremental_reparse;
16use ra_parser::SyntaxKind; 16use parser::SyntaxKind;
17 17
18pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) { 18pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
19 let (tokens, lexer_errors) = tokenize(&text); 19 let (tokens, lexer_errors) = tokenize(&text);
@@ -21,7 +21,7 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
21 let mut token_source = TextTokenSource::new(text, &tokens); 21 let mut token_source = TextTokenSource::new(text, &tokens);
22 let mut tree_sink = TextTreeSink::new(text, &tokens); 22 let mut tree_sink = TextTreeSink::new(text, &tokens);
23 23
24 ra_parser::parse(&mut token_source, &mut tree_sink); 24 parser::parse(&mut token_source, &mut tree_sink);
25 25
26 let (tree, mut parser_errors) = tree_sink.finish(); 26 let (tree, mut parser_errors) = tree_sink.finish();
27 parser_errors.extend(lexer_errors); 27 parser_errors.extend(lexer_errors);
@@ -32,7 +32,7 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
32/// Returns `text` parsed as a `T` provided there are no parse errors. 32/// Returns `text` parsed as a `T` provided there are no parse errors.
33pub(crate) fn parse_text_fragment<T: AstNode>( 33pub(crate) fn parse_text_fragment<T: AstNode>(
34 text: &str, 34 text: &str,
35 fragment_kind: ra_parser::FragmentKind, 35 fragment_kind: parser::FragmentKind,
36) -> Result<T, ()> { 36) -> Result<T, ()> {
37 let (tokens, lexer_errors) = tokenize(&text); 37 let (tokens, lexer_errors) = tokenize(&text);
38 if !lexer_errors.is_empty() { 38 if !lexer_errors.is_empty() {
@@ -44,13 +44,13 @@ pub(crate) fn parse_text_fragment<T: AstNode>(
44 44
45 // TextTreeSink assumes that there's at least some root node to which it can attach errors and 45 // TextTreeSink assumes that there's at least some root node to which it can attach errors and
46 // tokens. We arbitrarily give it a SourceFile. 46 // tokens. We arbitrarily give it a SourceFile.
47 use ra_parser::TreeSink; 47 use parser::TreeSink;
48 tree_sink.start_node(SyntaxKind::SOURCE_FILE); 48 tree_sink.start_node(SyntaxKind::SOURCE_FILE);
49 ra_parser::parse_fragment(&mut token_source, &mut tree_sink, fragment_kind); 49 parser::parse_fragment(&mut token_source, &mut tree_sink, fragment_kind);
50 tree_sink.finish_node(); 50 tree_sink.finish_node();
51 51
52 let (tree, parser_errors) = tree_sink.finish(); 52 let (tree, parser_errors) = tree_sink.finish();
53 use ra_parser::TokenSource; 53 use parser::TokenSource;
54 if !parser_errors.is_empty() || token_source.current().kind != SyntaxKind::EOF { 54 if !parser_errors.is_empty() || token_source.current().kind != SyntaxKind::EOF {
55 return Err(()); 55 return Err(());
56 } 56 }
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index 6644ffca4..4149f856a 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -6,7 +6,7 @@
6//! - otherwise, we search for the nearest `{}` block which contains the edit 6//! - otherwise, we search for the nearest `{}` block which contains the edit
7//! and try to parse only this block. 7//! and try to parse only this block.
8 8
9use ra_parser::Reparser; 9use parser::Reparser;
10use text_edit::Indel; 10use text_edit::Indel;
11 11
12use crate::{ 12use crate::{
diff --git a/crates/ra_syntax/src/parsing/text_token_source.rs b/crates/ra_syntax/src/parsing/text_token_source.rs
index 97aa3e795..df866dc2b 100644
--- a/crates/ra_syntax/src/parsing/text_token_source.rs
+++ b/crates/ra_syntax/src/parsing/text_token_source.rs
@@ -1,10 +1,10 @@
1//! See `TextTokenSource` docs. 1//! See `TextTokenSource` docs.
2 2
3use ra_parser::TokenSource; 3use parser::TokenSource;
4 4
5use crate::{parsing::lexer::Token, SyntaxKind::EOF, TextRange, TextSize}; 5use crate::{parsing::lexer::Token, SyntaxKind::EOF, TextRange, TextSize};
6 6
7/// Implementation of `ra_parser::TokenSource` that takes tokens from source code text. 7/// Implementation of `parser::TokenSource` that takes tokens from source code text.
8pub(crate) struct TextTokenSource<'t> { 8pub(crate) struct TextTokenSource<'t> {
9 text: &'t str, 9 text: &'t str,
10 /// token and its start position (non-whitespace/comment tokens) 10 /// token and its start position (non-whitespace/comment tokens)
@@ -20,15 +20,15 @@ pub(crate) struct TextTokenSource<'t> {
20 token_offset_pairs: Vec<(Token, TextSize)>, 20 token_offset_pairs: Vec<(Token, TextSize)>,
21 21
22 /// Current token and position 22 /// Current token and position
23 curr: (ra_parser::Token, usize), 23 curr: (parser::Token, usize),
24} 24}
25 25
26impl<'t> TokenSource for TextTokenSource<'t> { 26impl<'t> TokenSource for TextTokenSource<'t> {
27 fn current(&self) -> ra_parser::Token { 27 fn current(&self) -> parser::Token {
28 self.curr.0 28 self.curr.0
29 } 29 }
30 30
31 fn lookahead_nth(&self, n: usize) -> ra_parser::Token { 31 fn lookahead_nth(&self, n: usize) -> parser::Token {
32 mk_token(self.curr.1 + n, &self.token_offset_pairs) 32 mk_token(self.curr.1 + n, &self.token_offset_pairs)
33 } 33 }
34 34
@@ -49,7 +49,7 @@ impl<'t> TokenSource for TextTokenSource<'t> {
49 } 49 }
50} 50}
51 51
52fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> ra_parser::Token { 52fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> parser::Token {
53 let (kind, is_jointed_to_next) = match token_offset_pairs.get(pos) { 53 let (kind, is_jointed_to_next) = match token_offset_pairs.get(pos) {
54 Some((token, offset)) => ( 54 Some((token, offset)) => (
55 token.kind, 55 token.kind,
@@ -60,7 +60,7 @@ fn mk_token(pos: usize, token_offset_pairs: &[(Token, TextSize)]) -> ra_parser::
60 ), 60 ),
61 None => (EOF, false), 61 None => (EOF, false),
62 }; 62 };
63 ra_parser::Token { kind, is_jointed_to_next } 63 parser::Token { kind, is_jointed_to_next }
64} 64}
65 65
66impl<'t> TextTokenSource<'t> { 66impl<'t> TextTokenSource<'t> {
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs
index 6d1828d20..c1b5f246d 100644
--- a/crates/ra_syntax/src/parsing/text_tree_sink.rs
+++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs
@@ -2,7 +2,7 @@
2 2
3use std::mem; 3use std::mem;
4 4
5use ra_parser::{ParseError, TreeSink}; 5use parser::{ParseError, TreeSink};
6 6
7use crate::{ 7use crate::{
8 parsing::Token, 8 parsing::Token,
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs
index a7dbdba7b..b2abcbfbb 100644
--- a/crates/ra_syntax/src/syntax_node.rs
+++ b/crates/ra_syntax/src/syntax_node.rs
@@ -71,7 +71,7 @@ impl SyntaxTreeBuilder {
71 self.inner.finish_node() 71 self.inner.finish_node()
72 } 72 }
73 73
74 pub fn error(&mut self, error: ra_parser::ParseError, text_pos: TextSize) { 74 pub fn error(&mut self, error: parser::ParseError, text_pos: TextSize) {
75 self.errors.push(SyntaxError::new_at_offset(*error.0, text_pos)) 75 self.errors.push(SyntaxError::new_at_offset(*error.0, text_pos))
76 } 76 }
77} 77}