From ad24976da38482948c586bdbc16004273662ff7e Mon Sep 17 00:00:00 2001 From: Veetaha Date: Fri, 24 Jan 2020 03:39:23 +0200 Subject: ra_syntax: changed added diagnostics information returned from tokenize() (implemented with iterators) --- crates/ra_syntax/src/syntax_error.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/syntax_error.rs') diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index 6c171df8d..9122dda29 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -4,7 +4,7 @@ use std::fmt; use ra_parser::ParseError; -use crate::{validation::EscapeError, TextRange, TextUnit}; +use crate::{validation::EscapeError, TextRange, TextUnit, TokenizeError}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SyntaxError { @@ -12,6 +12,10 @@ pub struct SyntaxError { location: Location, } +// FIXME: Location should be just `Location(TextRange)` +// TextUnit enum member just unnecessarily compicates things, +// we should'n treat it specially, it just as a `TextRange { start: x, end: x + 1 }` +// see `location_to_range()` in ra_ide/src/diagnostics #[derive(Clone, PartialEq, Eq, Hash)] pub enum Location { Offset(TextUnit), @@ -79,6 +83,7 @@ impl fmt::Display for SyntaxError { pub enum SyntaxErrorKind { ParseError(ParseError), EscapeError(EscapeError), + TokenizeError(TokenizeError), InvalidBlockAttr, InvalidMatchInnerAttr, InvalidTupleIndexFormat, -- cgit v1.2.3 From ac37a11f04b31f792068a1cb50dbbf5ccd4d982d Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 26 Jan 2020 20:44:49 +0200 Subject: Reimplemented lexer with vectors instead of iterators --- crates/ra_syntax/src/syntax_error.rs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'crates/ra_syntax/src/syntax_error.rs') diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index 9122dda29..af18a30f2 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -84,6 +84,9 @@ pub enum SyntaxErrorKind { ParseError(ParseError), EscapeError(EscapeError), TokenizeError(TokenizeError), + // FIXME: the obvious pattern of this enum dictates that the following enum variants + // should be wrapped into something like `SemmanticError(SemmanticError)` + // or `ValidateError(ValidateError)` or `SemmanticValidateError(...)` InvalidBlockAttr, InvalidMatchInnerAttr, InvalidTupleIndexFormat, @@ -106,6 +109,7 @@ impl fmt::Display for SyntaxErrorKind { } ParseError(msg) => write!(f, "{}", msg.0), EscapeError(err) => write!(f, "{}", err), + TokenizeError(err) => write!(f, "{}", err), VisibilityNotAllowed => { write!(f, "unnecessary visibility qualifier") } @@ -116,6 +120,44 @@ impl fmt::Display for SyntaxErrorKind { } } +impl fmt::Display for TokenizeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let msg = match self { + TokenizeError::EmptyInt => "Missing digits after integer base prefix", + TokenizeError::EmptyExponent => "Missing digits after the exponent symbol", + TokenizeError::UnterminatedBlockComment => { + "Missing trailing `*/` symbols to terminate the block comment" + } + TokenizeError::UnterminatedChar => { + "Missing trailing `'` symbol to terminate the character literal" + } + TokenizeError::UnterminatedByte => { + "Missing trailing `'` symbol to terminate the byte literal" + } + TokenizeError::UnterminatedString => { + "Missing trailing `\"` symbol to terminate the string literal" + } + TokenizeError::UnterminatedByteString => { + "Missing trailing `\"` symbol to terminate the byte string literal" + } + TokenizeError::UnterminatedRawString => { + "Missing trailing `\"` with `#` symbols to terminate the raw string literal" + } + TokenizeError::UnterminatedRawByteString => { + "Missing trailing `\"` with `#` symbols to terminate the raw byte string literal" + } + TokenizeError::UnstartedRawString => { + "Missing `\"` symbol after `#` symbols to begin the raw string literal" + } + TokenizeError::UnstartedRawByteString => { + "Missing `\"` symbol after `#` symbols to begin the raw byte string literal" + } + TokenizeError::LifetimeStartsWithNumber => "Lifetime name cannot start with a number", + }; + write!(f, "{}", msg) + } +} + impl fmt::Display for EscapeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let msg = match self { -- cgit v1.2.3 From bf60661aa3e2a77fedb3e1627675842d05538860 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 27 Jan 2020 01:41:48 +0200 Subject: ra_syntax: remove backticks from TokenizeError message since that is not Markdown ;( --- crates/ra_syntax/src/syntax_error.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_syntax/src/syntax_error.rs') diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index af18a30f2..45e11f404 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -126,31 +126,31 @@ impl fmt::Display for TokenizeError { TokenizeError::EmptyInt => "Missing digits after integer base prefix", TokenizeError::EmptyExponent => "Missing digits after the exponent symbol", TokenizeError::UnterminatedBlockComment => { - "Missing trailing `*/` symbols to terminate the block comment" + "Missing trailing */ symbols to terminate the block comment" } TokenizeError::UnterminatedChar => { - "Missing trailing `'` symbol to terminate the character literal" + "Missing trailing ' symbol to terminate the character literal" } TokenizeError::UnterminatedByte => { - "Missing trailing `'` symbol to terminate the byte literal" + "Missing trailing ' symbol to terminate the byte literal" } TokenizeError::UnterminatedString => { - "Missing trailing `\"` symbol to terminate the string literal" + "Missing trailing \" symbol to terminate the string literal" } TokenizeError::UnterminatedByteString => { - "Missing trailing `\"` symbol to terminate the byte string literal" + "Missing trailing \" symbol to terminate the byte string literal" } TokenizeError::UnterminatedRawString => { - "Missing trailing `\"` with `#` symbols to terminate the raw string literal" + "Missing trailing \" with # symbols to terminate the raw string literal" } TokenizeError::UnterminatedRawByteString => { - "Missing trailing `\"` with `#` symbols to terminate the raw byte string literal" + "Missing trailing \" with # symbols to terminate the raw byte string literal" } TokenizeError::UnstartedRawString => { - "Missing `\"` symbol after `#` symbols to begin the raw string literal" + "Missing \" symbol after # symbols to begin the raw string literal" } TokenizeError::UnstartedRawByteString => { - "Missing `\"` symbol after `#` symbols to begin the raw byte string literal" + "Missing \" symbol after # symbols to begin the raw byte string literal" } TokenizeError::LifetimeStartsWithNumber => "Lifetime name cannot start with a number", }; -- cgit v1.2.3 From 9367b9a2920073a3f79fdff80dcc97d727f6ce17 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Thu, 30 Jan 2020 00:18:21 +0200 Subject: ra_syntax: add backticks around tokens specimen --- crates/ra_syntax/src/syntax_error.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'crates/ra_syntax/src/syntax_error.rs') diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index 45e11f404..7f9d36618 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -71,6 +71,10 @@ impl SyntaxError { self } + + pub fn debug_dump(&self, acc: &mut impl fmt::Write) { + writeln!(acc, "error {:?}: {}", self.location(), self.kind()).unwrap(); + } } impl fmt::Display for SyntaxError { @@ -122,37 +126,44 @@ impl fmt::Display for SyntaxErrorKind { impl fmt::Display for TokenizeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + #[rustfmt::skip] let msg = match self { - TokenizeError::EmptyInt => "Missing digits after integer base prefix", - TokenizeError::EmptyExponent => "Missing digits after the exponent symbol", + TokenizeError::EmptyInt => { + "Missing digits after the integer base prefix" + } + TokenizeError::EmptyExponent => { + "Missing digits after the exponent symbol" + } TokenizeError::UnterminatedBlockComment => { - "Missing trailing */ symbols to terminate the block comment" + "Missing trailing `*/` symbols to terminate the block comment" } TokenizeError::UnterminatedChar => { - "Missing trailing ' symbol to terminate the character literal" + "Missing trailing `'` symbol to terminate the character literal" } TokenizeError::UnterminatedByte => { - "Missing trailing ' symbol to terminate the byte literal" + "Missing trailing `'` symbol to terminate the byte literal" } TokenizeError::UnterminatedString => { - "Missing trailing \" symbol to terminate the string literal" + "Missing trailing `\"` symbol to terminate the string literal" } TokenizeError::UnterminatedByteString => { - "Missing trailing \" symbol to terminate the byte string literal" + "Missing trailing `\"` symbol to terminate the byte string literal" } TokenizeError::UnterminatedRawString => { - "Missing trailing \" with # symbols to terminate the raw string literal" + "Missing trailing `\"` with `#` symbols to terminate the raw string literal" } TokenizeError::UnterminatedRawByteString => { - "Missing trailing \" with # symbols to terminate the raw byte string literal" + "Missing trailing `\"` with `#` symbols to terminate the raw byte string literal" } TokenizeError::UnstartedRawString => { - "Missing \" symbol after # symbols to begin the raw string literal" + "Missing `\"` symbol after `#` symbols to begin the raw string literal" } TokenizeError::UnstartedRawByteString => { - "Missing \" symbol after # symbols to begin the raw byte string literal" + "Missing `\"` symbol after `#` symbols to begin the raw byte string literal" + } + TokenizeError::LifetimeStartsWithNumber => { + "Lifetime name cannot start with a number" } - TokenizeError::LifetimeStartsWithNumber => "Lifetime name cannot start with a number", }; write!(f, "{}", msg) } -- cgit v1.2.3