aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-07 15:32:33 +0000
committerAleksey Kladov <[email protected]>2018-11-07 15:42:36 +0000
commitf8b36bbc3b968754b71844d942286e81415627b8 (patch)
tree72be8cc4bac951b00746291e4b357b86def7d4c7 /crates/ra_syntax
parent2119fe214303325e86174b139d7ad8193b2ce251 (diff)
Rename File -> SourceFileNode
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/lib.rs22
-rw-r--r--crates/ra_syntax/src/reparsing.rs8
-rw-r--r--crates/ra_syntax/src/utils.rs4
-rw-r--r--crates/ra_syntax/src/validation.rs10
-rw-r--r--crates/ra_syntax/tests/test.rs4
5 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 54012b7b6..9f8066c70 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -61,12 +61,12 @@ pub use crate::{
61 61
62use crate::yellow::GreenNode; 62use crate::yellow::GreenNode;
63 63
64// TODO: pick a single name for everything. SourceFile maybe? 64// TODO: pick a single name for everything. SourceFileNode maybe?
65/// File represents a parse tree for a single Rust file. 65/// File represents a parse tree for a single Rust file.
66pub type File = ast::RootNode; 66pub type SourceFileNode = ast::RootNode;
67 67
68impl File { 68impl SourceFileNode {
69 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File { 69 fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode {
70 let root = SyntaxNode::new(green, errors); 70 let root = SyntaxNode::new(green, errors);
71 if cfg!(debug_assertions) { 71 if cfg!(debug_assertions) {
72 utils::validate_block_structure(root.borrowed()); 72 utils::validate_block_structure(root.borrowed());
@@ -74,24 +74,24 @@ impl File {
74 assert_eq!(root.kind(), SyntaxKind::ROOT); 74 assert_eq!(root.kind(), SyntaxKind::ROOT);
75 ast::RootNode { syntax: root } 75 ast::RootNode { syntax: root }
76 } 76 }
77 pub fn parse(text: &str) -> File { 77 pub fn parse(text: &str) -> SourceFileNode {
78 let tokens = tokenize(&text); 78 let tokens = tokenize(&text);
79 let (green, errors) = 79 let (green, errors) =
80 parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); 80 parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root);
81 File::new(green, errors) 81 SourceFileNode::new(green, errors)
82 } 82 }
83 pub fn reparse(&self, edit: &AtomEdit) -> File { 83 pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode {
84 self.incremental_reparse(edit) 84 self.incremental_reparse(edit)
85 .unwrap_or_else(|| self.full_reparse(edit)) 85 .unwrap_or_else(|| self.full_reparse(edit))
86 } 86 }
87 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> { 87 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<SourceFileNode> {
88 reparsing::incremental_reparse(self.syntax(), edit, self.errors()) 88 reparsing::incremental_reparse(self.syntax(), edit, self.errors())
89 .map(|(green_node, errors)| File::new(green_node, errors)) 89 .map(|(green_node, errors)| SourceFileNode::new(green_node, errors))
90 } 90 }
91 fn full_reparse(&self, edit: &AtomEdit) -> File { 91 fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode {
92 let text = 92 let text =
93 text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); 93 text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert);
94 File::parse(&text) 94 SourceFileNode::parse(&text)
95 } 95 }
96 /// Typed AST representation of the parse tree. 96 /// Typed AST representation of the parse tree.
97 pub fn ast(&self) -> ast::Root { 97 pub fn ast(&self) -> ast::Root {
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs
index 3c4ea5c22..d48133166 100644
--- a/crates/ra_syntax/src/reparsing.rs
+++ b/crates/ra_syntax/src/reparsing.rs
@@ -180,7 +180,7 @@ fn merge_errors(
180#[cfg(test)] 180#[cfg(test)]
181mod tests { 181mod tests {
182 use super::{ 182 use super::{
183 super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, File}, 183 super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode},
184 reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, 184 reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef,
185}; 185};
186 186
@@ -192,9 +192,9 @@ mod tests {
192 let (range, before) = extract_range(before); 192 let (range, before) = extract_range(before);
193 let after = replace_range(before.clone(), range, replace_with); 193 let after = replace_range(before.clone(), range, replace_with);
194 194
195 let fully_reparsed = File::parse(&after); 195 let fully_reparsed = SourceFileNode::parse(&after);
196 let incrementally_reparsed = { 196 let incrementally_reparsed = {
197 let f = File::parse(&before); 197 let f = SourceFileNode::parse(&before);
198 let edit = AtomEdit { 198 let edit = AtomEdit {
199 delete: range, 199 delete: range,
200 insert: replace_with.to_string(), 200 insert: replace_with.to_string(),
@@ -203,7 +203,7 @@ mod tests {
203 reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); 203 reparser(f.syntax(), &edit).expect("cannot incrementally reparse");
204 let green_root = node.replace_with(green); 204 let green_root = node.replace_with(green);
205 let errors = super::merge_errors(f.errors(), new_errors, node, &edit); 205 let errors = super::merge_errors(f.errors(), new_errors, node, &edit);
206 File::new(green_root, errors) 206 SourceFileNode::new(green_root, errors)
207 }; 207 };
208 208
209 assert_eq_text!( 209 assert_eq_text!(
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs
index cad9544be..5bbdf80bb 100644
--- a/crates/ra_syntax/src/utils.rs
+++ b/crates/ra_syntax/src/utils.rs
@@ -1,4 +1,4 @@
1use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; 1use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent};
2use std::fmt::Write; 2use std::fmt::Write;
3use std::str; 3use std::str;
4 4
@@ -45,7 +45,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
45} 45}
46 46
47pub fn check_fuzz_invariants(text: &str) { 47pub fn check_fuzz_invariants(text: &str) {
48 let file = File::parse(text); 48 let file = SourceFileNode::parse(text);
49 let root = file.syntax(); 49 let root = file.syntax();
50 validate_block_structure(root); 50 validate_block_structure(root);
51 let _ = file.ast(); 51 let _ = file.ast();
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs
index f345dbd6e..a10b297c0 100644
--- a/crates/ra_syntax/src/validation.rs
+++ b/crates/ra_syntax/src/validation.rs
@@ -5,7 +5,7 @@ use arrayvec::ArrayString;
5use crate::{ 5use crate::{
6 algo::visit::{visitor_ctx, VisitorCtx}, 6 algo::visit::{visitor_ctx, VisitorCtx},
7 ast::{self, AstNode}, 7 ast::{self, AstNode},
8 File, 8 SourceFileNode,
9 string_lexing::{self, CharComponentKind}, 9 string_lexing::{self, CharComponentKind},
10 yellow::{ 10 yellow::{
11 SyntaxError, 11 SyntaxError,
@@ -13,7 +13,7 @@ use crate::{
13 }, 13 },
14}; 14};
15 15
16pub(crate) fn validate(file: &File) -> Vec<SyntaxError> { 16pub(crate) fn validate(file: &SourceFileNode) -> Vec<SyntaxError> {
17 let mut errors = Vec::new(); 17 let mut errors = Vec::new();
18 for node in file.syntax().descendants() { 18 for node in file.syntax().descendants() {
19 let _ = visitor_ctx(&mut errors) 19 let _ = visitor_ctx(&mut errors)
@@ -155,11 +155,11 @@ fn is_ascii_escape(code: char) -> bool {
155 155
156#[cfg(test)] 156#[cfg(test)]
157mod test { 157mod test {
158 use crate::File; 158 use crate::SourceFileNode;
159 159
160 fn build_file(literal: &str) -> File { 160 fn build_file(literal: &str) -> SourceFileNode {
161 let src = format!("const C: char = '{}';", literal); 161 let src = format!("const C: char = '{}';", literal);
162 File::parse(&src) 162 SourceFileNode::parse(&src)
163 } 163 }
164 164
165 fn assert_valid_char(literal: &str) { 165 fn assert_valid_char(literal: &str) {
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
index 9d1ded093..67acc9020 100644
--- a/crates/ra_syntax/tests/test.rs
+++ b/crates/ra_syntax/tests/test.rs
@@ -11,7 +11,7 @@ use std::{
11 11
12use ra_syntax::{ 12use ra_syntax::{
13 utils::{check_fuzz_invariants, dump_tree}, 13 utils::{check_fuzz_invariants, dump_tree},
14 File, 14 SourceFileNode,
15}; 15};
16 16
17#[test] 17#[test]
@@ -25,7 +25,7 @@ fn lexer_tests() {
25#[test] 25#[test]
26fn parser_tests() { 26fn parser_tests() {
27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
28 let file = File::parse(text); 28 let file = SourceFileNode::parse(text);
29 dump_tree(file.syntax()) 29 dump_tree(file.syntax())
30 }) 30 })
31} 31}