From 3b42ddae601fbd73f672e82028e04c3abdf1252d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 4 Nov 2018 16:45:22 +0100 Subject: Introduce SyntaxErrorKind and TextRange in SyntaxError --- crates/ra_syntax/src/parser_impl/event.rs | 11 +++++++++-- crates/ra_syntax/src/parser_impl/mod.rs | 12 +++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/parser_impl') diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 79fa21389..ced09bcff 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -13,6 +13,10 @@ use crate::{ SmolStr, SyntaxKind::{self, *}, TextRange, TextUnit, + yellow::syntax_error::{ + ParseError, + SyntaxErrorKind, + }, }; use std::mem; @@ -75,7 +79,7 @@ pub(crate) enum Event { }, Error { - msg: String, + msg: ParseError, }, } @@ -157,7 +161,10 @@ impl<'a, S: Sink> EventProcessor<'a, S> { .sum::(); self.leaf(kind, len, n_raw_tokens); } - Event::Error { msg } => self.sink.error(msg, self.text_pos), + Event::Error { msg } => self.sink.error( + SyntaxErrorKind::ParseError(msg), + TextRange::offset_len(self.text_pos, 1.into()), + ), } } self.sink diff --git a/crates/ra_syntax/src/parser_impl/mod.rs b/crates/ra_syntax/src/parser_impl/mod.rs index 2b026d61e..ade25770b 100644 --- a/crates/ra_syntax/src/parser_impl/mod.rs +++ b/crates/ra_syntax/src/parser_impl/mod.rs @@ -10,7 +10,11 @@ use crate::{ event::{Event, EventProcessor}, input::{InputPosition, ParserInput}, }, - SmolStr, TextUnit, + SmolStr, TextRange, + yellow::syntax_error::{ + ParseError, + SyntaxErrorKind, + }, }; use crate::SyntaxKind::{self, EOF, TOMBSTONE}; @@ -21,7 +25,7 @@ pub(crate) trait Sink { fn leaf(&mut self, kind: SyntaxKind, text: SmolStr); fn start_internal(&mut self, kind: SyntaxKind); fn finish_internal(&mut self); - fn error(&mut self, message: String, offset: TextUnit); + fn error(&mut self, kind: SyntaxErrorKind, offset: TextRange); fn finish(self) -> Self::Tree; } @@ -144,7 +148,9 @@ impl<'t> ParserImpl<'t> { } pub(super) fn error(&mut self, msg: String) { - self.event(Event::Error { msg }) + self.event(Event::Error { + msg: ParseError(msg), + }) } pub(super) fn complete(&mut self, pos: u32, kind: SyntaxKind) { -- cgit v1.2.3 From fda8ddc5fe8a764c0dc91fecb92af1bdf3078485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Mon, 5 Nov 2018 18:38:34 +0100 Subject: Introduce Location and make SyntaxError fields private --- crates/ra_syntax/src/parser_impl/event.rs | 4 ++-- crates/ra_syntax/src/parser_impl/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/parser_impl') diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index ced09bcff..1445401bc 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -15,6 +15,7 @@ use crate::{ TextRange, TextUnit, yellow::syntax_error::{ ParseError, + SyntaxError, SyntaxErrorKind, }, }; @@ -162,8 +163,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { self.leaf(kind, len, n_raw_tokens); } Event::Error { msg } => self.sink.error( - SyntaxErrorKind::ParseError(msg), - TextRange::offset_len(self.text_pos, 1.into()), + SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos), ), } } diff --git a/crates/ra_syntax/src/parser_impl/mod.rs b/crates/ra_syntax/src/parser_impl/mod.rs index ade25770b..cb6e370ac 100644 --- a/crates/ra_syntax/src/parser_impl/mod.rs +++ b/crates/ra_syntax/src/parser_impl/mod.rs @@ -10,10 +10,10 @@ use crate::{ event::{Event, EventProcessor}, input::{InputPosition, ParserInput}, }, - SmolStr, TextRange, + SmolStr, yellow::syntax_error::{ ParseError, - SyntaxErrorKind, + SyntaxError, }, }; @@ -25,7 +25,7 @@ pub(crate) trait Sink { fn leaf(&mut self, kind: SyntaxKind, text: SmolStr); fn start_internal(&mut self, kind: SyntaxKind); fn finish_internal(&mut self); - fn error(&mut self, kind: SyntaxErrorKind, offset: TextRange); + fn error(&mut self, error: SyntaxError); fn finish(self) -> Self::Tree; } -- cgit v1.2.3 From 59405bfe4ad0afa0b7ff533c7bfbc3ad4170604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Mon, 5 Nov 2018 22:29:33 +0100 Subject: cargo format --- crates/ra_syntax/src/parser_impl/event.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src/parser_impl') diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 1445401bc..bf9c1cef0 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -162,9 +162,10 @@ impl<'a, S: Sink> EventProcessor<'a, S> { .sum::(); self.leaf(kind, len, n_raw_tokens); } - Event::Error { msg } => self.sink.error( - SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos), - ), + Event::Error { msg } => self.sink.error(SyntaxError::new( + SyntaxErrorKind::ParseError(msg), + self.text_pos, + )), } } self.sink -- cgit v1.2.3