From 3517c175ac537b47dd3e36cc7fb1edd60b02c039 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 21:08:59 +0300 Subject: rename Sink -> TreeSink --- crates/ra_syntax/src/parsing/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/parsing/builder.rs') diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index 9090c60c2..118f43b2c 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs @@ -1,5 +1,5 @@ use crate::{ - parsing::parser_impl::Sink, + parsing::parser_impl::TreeSink, syntax_node::{GreenNode, RaTypes}, SmolStr, SyntaxKind, SyntaxError, }; @@ -17,7 +17,7 @@ impl GreenBuilder { } } -impl Sink for GreenBuilder { +impl TreeSink for GreenBuilder { type Tree = (GreenNode, Vec); fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { -- cgit v1.2.3 From 2b5e336ce7172914686b33c8ac1522911366fcf0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 22:19:12 +0300 Subject: move abstract traits to top --- crates/ra_syntax/src/parsing/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/parsing/builder.rs') diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index 118f43b2c..a05e7f84b 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs @@ -1,5 +1,5 @@ use crate::{ - parsing::parser_impl::TreeSink, + parsing::TreeSink, syntax_node::{GreenNode, RaTypes}, SmolStr, SyntaxKind, SyntaxError, }; -- cgit v1.2.3 From 882c47f1870f15cb2aaad8871ccbad1c51520f49 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 23:17:07 +0300 Subject: move syntax error to parser --- crates/ra_syntax/src/parsing/builder.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/src/parsing/builder.rs') diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index a05e7f84b..ee0e2cce7 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs @@ -1,19 +1,24 @@ use crate::{ - parsing::TreeSink, + SmolStr, SyntaxKind, SyntaxError, SyntaxErrorKind, TextUnit, + parsing::{TreeSink, ParseError}, syntax_node::{GreenNode, RaTypes}, - SmolStr, SyntaxKind, SyntaxError, }; use rowan::GreenNodeBuilder; pub(crate) struct GreenBuilder { + text_pos: TextUnit, errors: Vec, inner: GreenNodeBuilder, } -impl GreenBuilder { - pub(crate) fn new() -> GreenBuilder { - GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() } +impl Default for GreenBuilder { + fn default() -> GreenBuilder { + GreenBuilder { + text_pos: TextUnit::default(), + errors: Vec::new(), + inner: GreenNodeBuilder::new(), + } } } @@ -21,6 +26,7 @@ impl TreeSink for GreenBuilder { type Tree = (GreenNode, Vec); fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { + self.text_pos += TextUnit::of_str(text.as_str()); self.inner.leaf(kind, text); } @@ -32,7 +38,8 @@ impl TreeSink for GreenBuilder { self.inner.finish_internal(); } - fn error(&mut self, error: SyntaxError) { + fn error(&mut self, error: ParseError) { + let error = SyntaxError::new(SyntaxErrorKind::ParseError(error), self.text_pos); self.errors.push(error) } -- cgit v1.2.3