diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-08-12 18:26:51 +0200 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-08-12 18:30:53 +0200 |
| commit | a1c187eef3ba08076aedb5154929f7eda8d1b424 (patch) | |
| tree | 9d898eb9600b0c36a74e4f95238f679c683fa566 /crates/syntax/src/syntax_error.rs | |
| parent | 3d6889cba72a9d02199f7adaa2ecc69bc30af834 (diff) | |
| download | rust-a1c187eef3ba08076aedb5154929f7eda8d1b424.tar.gz rust-a1c187eef3ba08076aedb5154929f7eda8d1b424.zip | |
Rename ra_syntax -> syntax
Diffstat (limited to 'crates/syntax/src/syntax_error.rs')
| -rw-r--r-- | crates/syntax/src/syntax_error.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/syntax/src/syntax_error.rs b/crates/syntax/src/syntax_error.rs new file mode 100644 index 00000000000..7c4511fece0 --- /dev/null +++ b/crates/syntax/src/syntax_error.rs @@ -0,0 +1,44 @@ +//! See docs for `SyntaxError`. + +use std::fmt; + +use crate::{TextRange, TextSize}; + +/// Represents the result of unsuccessful tokenization, parsing +/// or tree validation. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SyntaxError(String, TextRange); + +// FIXME: there was an unused SyntaxErrorKind previously (before this enum was removed) +// It was introduced in this PR: https://github.com/rust-analyzer/rust-analyzer/pull/846/files#diff-827da9b03b8f9faa1bade5cdd44d5dafR95 +// but it was not removed by a mistake. +// +// So, we need to find a place where to stick validation for attributes in match clauses. +// Code before refactor: +// InvalidMatchInnerAttr => { +// write!(f, "Inner attributes are only allowed directly after the opening brace of the match expression") +// } + +impl SyntaxError { + pub fn new(message: impl Into<String>, range: TextRange) -> Self { + Self(message.into(), range) + } + pub fn new_at_offset(message: impl Into<String>, offset: TextSize) -> Self { + Self(message.into(), TextRange::empty(offset)) + } + + pub fn range(&self) -> TextRange { + self.1 + } + + pub fn with_range(mut self, range: TextRange) -> Self { + self.1 = range; + self + } +} + +impl fmt::Display for SyntaxError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} |
