diff options
author | Greg Brown <gmb60@cam.ac.uk> | 2021-01-08 18:00:34 +0000 |
---|---|---|
committer | Greg Brown <gmb60@cam.ac.uk> | 2021-01-08 18:00:34 +0000 |
commit | 0a837400e0ffa7fca1a1902b34f375d0dc5b5f6b (patch) | |
tree | f6a71331efcd8e2fbdb3427d7fa0ae5289174f7b /chewed/src/position.rs | |
parent | e1452227b8bd9ad3805480f8a5a66a75fb8370dd (diff) |
Add positions to chewed errors.
Diffstat (limited to 'chewed/src/position.rs')
-rw-r--r-- | chewed/src/position.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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) + } +} |