diff options
Diffstat (limited to 'crates/ra_syntax/src/lib.rs')
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index f765f621b..37320e1ba 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -31,7 +31,7 @@ pub mod ast; | |||
31 | #[doc(hidden)] | 31 | #[doc(hidden)] |
32 | pub mod fuzz; | 32 | pub mod fuzz; |
33 | 33 | ||
34 | use std::sync::Arc; | 34 | use std::{sync::Arc, fmt::Write}; |
35 | 35 | ||
36 | use ra_text_edit::AtomTextEdit; | 36 | use ra_text_edit::AtomTextEdit; |
37 | 37 | ||
@@ -68,6 +68,14 @@ impl Parse { | |||
68 | Err(self.errors) | 68 | Err(self.errors) |
69 | } | 69 | } |
70 | } | 70 | } |
71 | |||
72 | pub fn debug_dump(&self) -> String { | ||
73 | let mut buf = self.tree.syntax().debug_dump(); | ||
74 | for err in self.errors.iter() { | ||
75 | writeln!(buf, "err: `{}`", err).unwrap(); | ||
76 | } | ||
77 | buf | ||
78 | } | ||
71 | } | 79 | } |
72 | 80 | ||
73 | /// `SourceFile` represents a parse tree for a single Rust file. | 81 | /// `SourceFile` represents a parse tree for a single Rust file. |
@@ -83,6 +91,12 @@ impl SourceFile { | |||
83 | TreeArc::cast(root) | 91 | TreeArc::cast(root) |
84 | } | 92 | } |
85 | 93 | ||
94 | pub fn parse2(text: &str) -> Parse { | ||
95 | let (green, errors) = parsing::parse_text(text); | ||
96 | let tree = SourceFile::new(green); | ||
97 | Parse { tree, errors: Arc::new(errors) } | ||
98 | } | ||
99 | |||
86 | pub fn parse(text: &str) -> TreeArc<SourceFile> { | 100 | pub fn parse(text: &str) -> TreeArc<SourceFile> { |
87 | let (green, _errors) = parsing::parse_text(text); | 101 | let (green, _errors) = parsing::parse_text(text); |
88 | SourceFile::new(green) | 102 | SourceFile::new(green) |