From f52eda675e271675c99bb27ed8622690cebb5678 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 May 2019 11:31:27 +0300 Subject: add Parse --- crates/ra_syntax/src/lib.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/lib.rs') 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; #[doc(hidden)] pub mod fuzz; +use std::sync::Arc; + +use ra_text_edit::AtomTextEdit; + +use crate::syntax_node::GreenNode; + pub use rowan::{SmolStr, TextRange, TextUnit}; pub use ra_parser::SyntaxKind; pub use ra_parser::T; @@ -43,8 +49,26 @@ pub use crate::{ parsing::{tokenize, classify_literal, Token}, }; -use ra_text_edit::AtomTextEdit; -use crate::syntax_node::GreenNode; +/// `Parse` is the result of the parsing: a syntax tree and a collection of +/// errors. +/// +/// Note that we always produce a syntax tree, even for completely invalid +/// files. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Parse { + pub tree: TreeArc, + pub errors: Arc>, +} + +impl Parse { + pub fn ok(self) -> Result, Arc>> { + if self.errors.is_empty() { + Ok(self.tree) + } else { + Err(self.errors) + } + } +} /// `SourceFile` represents a parse tree for a single Rust file. pub use crate::ast::SourceFile; -- cgit v1.2.3