diff options
Diffstat (limited to 'crates/libsyntax2/src/lib.rs')
-rw-r--r-- | crates/libsyntax2/src/lib.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index ab4a40435..01e155855 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs | |||
@@ -50,16 +50,25 @@ pub use { | |||
50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, | 50 | yellow::{SyntaxNode, SyntaxNodeRef, OwnedRoot, RefRoot, TreeRoot, SyntaxError}, |
51 | }; | 51 | }; |
52 | 52 | ||
53 | use yellow::{GreenNode, SyntaxRoot}; | ||
54 | |||
53 | #[derive(Clone, Debug)] | 55 | #[derive(Clone, Debug)] |
54 | pub struct File { | 56 | pub struct File { |
55 | root: SyntaxNode | 57 | root: SyntaxNode |
56 | } | 58 | } |
57 | 59 | ||
58 | impl File { | 60 | impl File { |
59 | pub fn parse(text: &str) -> Self { | 61 | fn new(root: GreenNode, errors: Vec<SyntaxError>) -> File { |
60 | let root = ::parse(text); | 62 | let root = SyntaxRoot::new(root, errors); |
63 | let root = SyntaxNode::new_owned(root); | ||
64 | validate_block_structure(root.borrowed()); | ||
61 | File { root } | 65 | File { root } |
62 | } | 66 | } |
67 | pub fn parse(text: &str) -> Self { | ||
68 | let tokens = tokenize(&text); | ||
69 | let (root, errors) = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens); | ||
70 | File::new(root, errors) | ||
71 | } | ||
63 | pub fn ast(&self) -> ast::Root { | 72 | pub fn ast(&self) -> ast::Root { |
64 | ast::Root::cast(self.syntax()).unwrap() | 73 | ast::Root::cast(self.syntax()).unwrap() |
65 | } | 74 | } |
@@ -69,14 +78,6 @@ impl File { | |||
69 | pub fn errors(&self) -> Vec<SyntaxError> { | 78 | pub fn errors(&self) -> Vec<SyntaxError> { |
70 | self.syntax().root.syntax_root().errors.clone() | 79 | self.syntax().root.syntax_root().errors.clone() |
71 | } | 80 | } |
72 | |||
73 | } | ||
74 | |||
75 | pub fn parse(text: &str) -> SyntaxNode { | ||
76 | let tokens = tokenize(&text); | ||
77 | let res = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens); | ||
78 | validate_block_structure(res.borrowed()); | ||
79 | res | ||
80 | } | 81 | } |
81 | 82 | ||
82 | #[cfg(not(debug_assertions))] | 83 | #[cfg(not(debug_assertions))] |