diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 0ceabc203..a950870bd 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -31,6 +31,12 @@ pub mod ast; | |||
31 | #[doc(hidden)] | 31 | #[doc(hidden)] |
32 | pub mod fuzz; | 32 | pub mod fuzz; |
33 | 33 | ||
34 | use std::sync::Arc; | ||
35 | |||
36 | use ra_text_edit::AtomTextEdit; | ||
37 | |||
38 | use crate::syntax_node::GreenNode; | ||
39 | |||
34 | pub use rowan::{SmolStr, TextRange, TextUnit}; | 40 | pub use rowan::{SmolStr, TextRange, TextUnit}; |
35 | pub use ra_parser::SyntaxKind; | 41 | pub use ra_parser::SyntaxKind; |
36 | pub use ra_parser::T; | 42 | pub use ra_parser::T; |
@@ -43,8 +49,26 @@ pub use crate::{ | |||
43 | parsing::{tokenize, classify_literal, Token}, | 49 | parsing::{tokenize, classify_literal, Token}, |
44 | }; | 50 | }; |
45 | 51 | ||
46 | use ra_text_edit::AtomTextEdit; | 52 | /// `Parse` is the result of the parsing: a syntax tree and a collection of |
47 | use crate::syntax_node::GreenNode; | 53 | /// errors. |
54 | /// | ||
55 | /// Note that we always produce a syntax tree, even for completely invalid | ||
56 | /// files. | ||
57 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
58 | pub struct Parse { | ||
59 | pub tree: TreeArc<SourceFile>, | ||
60 | pub errors: Arc<Vec<SyntaxError>>, | ||
61 | } | ||
62 | |||
63 | impl Parse { | ||
64 | pub fn ok(self) -> Result<TreeArc<SourceFile>, Arc<Vec<SyntaxError>>> { | ||
65 | if self.errors.is_empty() { | ||
66 | Ok(self.tree) | ||
67 | } else { | ||
68 | Err(self.errors) | ||
69 | } | ||
70 | } | ||
71 | } | ||
48 | 72 | ||
49 | /// `SourceFile` represents a parse tree for a single Rust file. | 73 | /// `SourceFile` represents a parse tree for a single Rust file. |
50 | pub use crate::ast::SourceFile; | 74 | pub use crate::ast::SourceFile; |