From 0a837400e0ffa7fca1a1902b34f375d0dc5b5f6b Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Fri, 8 Jan 2021 18:00:34 +0000 Subject: Add positions to chewed errors. --- chewed/src/position.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 chewed/src/position.rs (limited to 'chewed/src/position.rs') diff --git a/chewed/src/position.rs b/chewed/src/position.rs new file mode 100644 index 0000000..62d9b5a --- /dev/null +++ b/chewed/src/position.rs @@ -0,0 +1,21 @@ +use std::fmt; + +#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)] +pub struct LineCol { + /// One-indexed line. + pub line: usize, + /// Zero-indexed column. + pub col: usize, +} + +impl Default for LineCol { + fn default() -> Self { + Self { line: 1, col: 0 } + } +} + +impl fmt::Display for LineCol { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}:{}", self.line, self.col) + } +} -- cgit v1.2.3