aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/lib.rs28
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)]
32pub mod fuzz; 32pub mod fuzz;
33 33
34use std::sync::Arc;
35
36use ra_text_edit::AtomTextEdit;
37
38use crate::syntax_node::GreenNode;
39
34pub use rowan::{SmolStr, TextRange, TextUnit}; 40pub use rowan::{SmolStr, TextRange, TextUnit};
35pub use ra_parser::SyntaxKind; 41pub use ra_parser::SyntaxKind;
36pub use ra_parser::T; 42pub 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
46use ra_text_edit::AtomTextEdit; 52/// `Parse` is the result of the parsing: a syntax tree and a collection of
47use 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)]
58pub struct Parse {
59 pub tree: TreeArc<SourceFile>,
60 pub errors: Arc<Vec<SyntaxError>>,
61}
62
63impl 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.
50pub use crate::ast::SourceFile; 74pub use crate::ast::SourceFile;