From 86a7ac2d31e97c42a9da8d8fd539b5a0de0fa795 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Oct 2018 15:44:00 +0300 Subject: Simplify event processing --- crates/ra_syntax/src/yellow/builder.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'crates/ra_syntax/src/yellow') diff --git a/crates/ra_syntax/src/yellow/builder.rs b/crates/ra_syntax/src/yellow/builder.rs index 35dbaec05..c307b2bd0 100644 --- a/crates/ra_syntax/src/yellow/builder.rs +++ b/crates/ra_syntax/src/yellow/builder.rs @@ -1,33 +1,29 @@ use rowan::GreenNodeBuilder; use { + TextUnit, SmolStr, parser_impl::Sink, yellow::{GreenNode, SyntaxError, RaTypes}, - SyntaxKind, TextRange, TextUnit, + SyntaxKind, }; -pub(crate) struct GreenBuilder<'a> { - text: &'a str, - pos: TextUnit, +pub(crate) struct GreenBuilder { errors: Vec, inner: GreenNodeBuilder, } -impl<'a> Sink<'a> for GreenBuilder<'a> { - type Tree = (GreenNode, Vec); - - fn new(text: &'a str) -> Self { +impl GreenBuilder { + pub(crate) fn new() -> GreenBuilder { GreenBuilder { - text, - pos: 0.into(), errors: Vec::new(), inner: GreenNodeBuilder::new(), } } +} + +impl Sink for GreenBuilder { + type Tree = (GreenNode, Vec); - fn leaf(&mut self, kind: SyntaxKind, len: TextUnit) { - let range = TextRange::offset_len(self.pos, len); - self.pos += len; - let text = self.text[range].into(); + fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { self.inner.leaf(kind, text); } @@ -39,11 +35,9 @@ impl<'a> Sink<'a> for GreenBuilder<'a> { self.inner.finish_internal(); } - fn error(&mut self, message: String) { - self.errors.push(SyntaxError { - msg: message, - offset: self.pos, - }) + fn error(&mut self, message: String, offset: TextUnit) { + let error = SyntaxError { msg: message, offset }; + self.errors.push(error) } fn finish(self) -> (GreenNode, Vec) { -- cgit v1.2.3