mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
move all parsing related bits to a separate module
This commit is contained in:
parent
9d0cda4bc8
commit
5222b8aba3
31 changed files with 78 additions and 47 deletions
41
crates/ra_syntax/src/parsing/builder.rs
Normal file
41
crates/ra_syntax/src/parsing/builder.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use crate::{
|
||||
parsing::parser_impl::Sink,
|
||||
syntax_node::{GreenNode, RaTypes, SyntaxError},
|
||||
SmolStr, SyntaxKind,
|
||||
};
|
||||
use rowan::GreenNodeBuilder;
|
||||
|
||||
pub(crate) struct GreenBuilder {
|
||||
errors: Vec<SyntaxError>,
|
||||
inner: GreenNodeBuilder<RaTypes>,
|
||||
}
|
||||
|
||||
impl GreenBuilder {
|
||||
pub(crate) fn new() -> GreenBuilder {
|
||||
GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Sink for GreenBuilder {
|
||||
type Tree = (GreenNode, Vec<SyntaxError>);
|
||||
|
||||
fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) {
|
||||
self.inner.leaf(kind, text);
|
||||
}
|
||||
|
||||
fn start_branch(&mut self, kind: SyntaxKind) {
|
||||
self.inner.start_internal(kind)
|
||||
}
|
||||
|
||||
fn finish_branch(&mut self) {
|
||||
self.inner.finish_internal();
|
||||
}
|
||||
|
||||
fn error(&mut self, error: SyntaxError) {
|
||||
self.errors.push(error)
|
||||
}
|
||||
|
||||
fn finish(self) -> (GreenNode, Vec<SyntaxError>) {
|
||||
(self.inner.finish(), self.errors)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue