aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-05 09:31:27 +0100
committerAleksey Kladov <[email protected]>2019-05-28 14:15:17 +0100
commitf52eda675e271675c99bb27ed8622690cebb5678 (patch)
tree2ee6bfa36bc7fcad612f11a060c871e31e7551aa /crates
parent0545e4781d3aba3083835cfa8afab07b7442a3aa (diff)
add Parse
Diffstat (limited to 'crates')
-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;