From 08b91a265fcda74f5463473938ec33873b49a7f7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 16 Jan 2020 17:51:04 +0100 Subject: =?UTF-8?q?Powerful=20parser=20testing=20=F0=9F=90=B1=E2=80=8D?= =?UTF-8?q?=F0=9F=91=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/span.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/syntax/span.rs') 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 Spanned { } } -impl Display for Spanned where T: std::fmt::Debug { +impl Display for Spanned 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 Debug for Spanned 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) } } -- cgit v1.2.3