aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
commit1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_syntax/src/lib.rs
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
parent61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff)
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up. I made sure that `cargo test` still passes. Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/lib.rs')
-rw-r--r--crates/ra_syntax/src/lib.rs34
1 files changed, 16 insertions, 18 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 7eba5ee61..7a9718aad 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -20,11 +20,11 @@
20#![allow(missing_docs)] 20#![allow(missing_docs)]
21//#![warn(unreachable_pub)] // rust-lang/rust#47816 21//#![warn(unreachable_pub)] // rust-lang/rust#47816
22 22
23extern crate itertools;
24extern crate unicode_xid;
25extern crate drop_bomb; 23extern crate drop_bomb;
24extern crate itertools;
26extern crate parking_lot; 25extern crate parking_lot;
27extern crate rowan; 26extern crate rowan;
27extern crate unicode_xid;
28 28
29#[cfg(test)] 29#[cfg(test)]
30#[macro_use] 30#[macro_use]
@@ -35,33 +35,31 @@ pub mod ast;
35mod lexer; 35mod lexer;
36#[macro_use] 36#[macro_use]
37mod token_set; 37mod token_set;
38mod parser_api;
39mod grammar; 38mod grammar;
39mod parser_api;
40mod parser_impl; 40mod parser_impl;
41mod reparsing; 41mod reparsing;
42 42
43mod syntax_kinds; 43mod syntax_kinds;
44mod yellow; 44pub mod text_utils;
45/// Utilities for simple uses of the parser. 45/// Utilities for simple uses of the parser.
46pub mod utils; 46pub mod utils;
47pub mod text_utils; 47mod yellow;
48 48
49pub use crate::{ 49pub use crate::{
50 rowan::{SmolStr, TextRange, TextUnit},
51 ast::AstNode, 50 ast::AstNode,
52 lexer::{tokenize, Token}, 51 lexer::{tokenize, Token},
53 syntax_kinds::SyntaxKind,
54 yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError, Direction},
55 reparsing::AtomEdit, 52 reparsing::AtomEdit,
53 rowan::{SmolStr, TextRange, TextUnit},
54 syntax_kinds::SyntaxKind,
55 yellow::{Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot},
56}; 56};
57 57
58use crate::{ 58use crate::yellow::GreenNode;
59 yellow::{GreenNode},
60};
61 59
62#[derive(Clone, Debug, Hash, PartialEq, Eq)] 60#[derive(Clone, Debug, Hash, PartialEq, Eq)]
63pub struct File { 61pub struct File {
64 root: SyntaxNode 62 root: SyntaxNode,
65} 63}
66 64
67impl File { 65impl File {
@@ -74,21 +72,21 @@ impl File {
74 } 72 }
75 pub fn parse(text: &str) -> File { 73 pub fn parse(text: &str) -> File {
76 let tokens = tokenize(&text); 74 let tokens = tokenize(&text);
77 let (green, errors) = parser_impl::parse_with( 75 let (green, errors) =
78 yellow::GreenBuilder::new(), 76 parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root);
79 text, &tokens, grammar::root,
80 );
81 File::new(green, errors) 77 File::new(green, errors)
82 } 78 }
83 pub fn reparse(&self, edit: &AtomEdit) -> File { 79 pub fn reparse(&self, edit: &AtomEdit) -> File {
84 self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) 80 self.incremental_reparse(edit)
81 .unwrap_or_else(|| self.full_reparse(edit))
85 } 82 }
86 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> { 83 pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> {
87 reparsing::incremental_reparse(self.syntax(), edit, self.errors()) 84 reparsing::incremental_reparse(self.syntax(), edit, self.errors())
88 .map(|(green_node, errors)| File::new(green_node, errors)) 85 .map(|(green_node, errors)| File::new(green_node, errors))
89 } 86 }
90 fn full_reparse(&self, edit: &AtomEdit) -> File { 87 fn full_reparse(&self, edit: &AtomEdit) -> File {
91 let text = text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); 88 let text =
89 text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert);
92 File::parse(&text) 90 File::parse(&text)
93 } 91 }
94 pub fn ast(&self) -> ast::Root { 92 pub fn ast(&self) -> ast::Root {