diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-01-16 17:51:04 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-01-16 17:51:04 +0100 |
| commit | 08b91a265fcda74f5463473938ec33873b49a7f7 (patch) | |
| tree | 747ac6a0b385a14a4aa5adbc3f21ef7b9653bd78 /src/syntax/span.rs | |
| parent | 15ad30555bdad8e7b192fdcf7d4543c0d3fb18ce (diff) | |
Powerful parser testing 🐱👤
Diffstat (limited to 'src/syntax/span.rs')
| -rw-r--r-- | src/syntax/span.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs index e5c6912b..546b3ad6 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -1,6 +1,6 @@ //! Spans map elements to the part of source code they originate from. -use std::fmt::{self, Display, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; /// Annotates a value with the part of the source code it corresponds to. @@ -28,13 +28,21 @@ impl<T> Spanned<T> { } } -impl<T> Display for Spanned<T> where T: std::fmt::Debug { +impl<T> Display for Spanned<T> where T: std::fmt::Display { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "({:?}:{})", self.v, self.span) + write!(f, "({}, {}, ", self.span.start, self.span.end)?; + self.v.fmt(f)?; + write!(f, ")") } } -debug_display!(Spanned; T where T: std::fmt::Debug); +impl<T> Debug for Spanned<T> where T: std::fmt::Debug { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "({}, {}, ", self.span.start, self.span.end)?; + self.v.fmt(f)?; + write!(f, ")") + } +} /// Describes a slice of source code. #[derive(Copy, Clone, Eq, PartialEq, Hash)] @@ -68,7 +76,7 @@ impl Span { impl Display for Span { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "[{}, {}]", self.start, self.end) + write!(f, "({}, {})", self.start, self.end) } } |
