From a74cd0b8ac2eaad707c7eca3168d0aae3788f19b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 12 Mar 2024 19:32:11 -0500 Subject: [PATCH] cl-structures: break `span` into its own file. --- cl-structures/src/lib.rs | 41 +-------------------------------------- cl-structures/src/span.rs | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 cl-structures/src/span.rs diff --git a/cl-structures/src/lib.rs b/cl-structures/src/lib.rs index 281d1bf..69deef0 100644 --- a/cl-structures/src/lib.rs +++ b/cl-structures/src/lib.rs @@ -2,44 +2,5 @@ //! - [Span](struct@span::Span): Stores a start and end [Loc](struct@span::Loc) //! - [Loc](struct@span::Loc): Stores the index in a stream #![warn(clippy::all)] +pub mod span; -pub mod span { - //! - [struct@Span]: Stores the start and end [struct@Loc] of a notable AST node - //! - [struct@Loc]: Stores the line/column of a notable AST node - #![allow(non_snake_case)] - - /// Stores the start and end [locations](struct@Loc) within the token stream - #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] - pub struct Span { - pub head: Loc, - pub tail: Loc, - } - pub fn Span(head: Loc, tail: Loc) -> Span { - Span { head, tail } - } - - /// Stores a read-only (line, column) location in a token stream - #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] - pub struct Loc { - line: u32, - col: u32, - } - pub fn Loc(line: u32, col: u32) -> Loc { - Loc { line, col } - } - impl Loc { - pub fn line(self) -> u32 { - self.line - } - pub fn col(self) -> u32 { - self.col - } - } - - impl std::fmt::Display for Loc { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let Loc { line, col } = self; - write!(f, "{line}:{col}:") - } - } -} diff --git a/cl-structures/src/span.rs b/cl-structures/src/span.rs new file mode 100644 index 0000000..8f03b38 --- /dev/null +++ b/cl-structures/src/span.rs @@ -0,0 +1,38 @@ +//! - [struct@Span]: Stores the start and end [struct@Loc] of a notable AST node +//! - [struct@Loc]: Stores the line/column of a notable AST node +#![allow(non_snake_case)] + +/// Stores the start and end [locations](struct@Loc) within the token stream +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Span { + pub head: Loc, + pub tail: Loc, +} +pub fn Span(head: Loc, tail: Loc) -> Span { + Span { head, tail } +} + +/// Stores a read-only (line, column) location in a token stream +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Loc { + line: u32, + col: u32, +} +pub fn Loc(line: u32, col: u32) -> Loc { + Loc { line, col } +} +impl Loc { + pub fn line(self) -> u32 { + self.line + } + pub fn col(self) -> u32 { + self.col + } +} + +impl std::fmt::Display for Loc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Loc { line, col } = self; + write!(f, "{line}:{col}:") + } +}