haz-query-lang 0.2.0

Parser and AST for the haz task query language.
Documentation
//! Byte-offset spans into the parsed filter-expression input.

use std::fmt;

/// A half-open `[start, end)` byte-offset range identifying a
/// substring of the original input string.
///
/// Spans are produced by the parser to mark the location of each
/// atom token. Downstream atom-validation diagnostics use them to
/// point back at the user's source.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Span {
    /// Inclusive start byte offset.
    pub start: usize,
    /// Exclusive end byte offset.
    pub end: usize,
}

impl fmt::Display for Span {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "bytes {}..{}", self.start, self.end)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn span_carries_start_and_end_byte_offsets() {
        let span = Span { start: 3, end: 7 };
        assert_eq!(span.start, 3);
        assert_eq!(span.end, 7);
    }

    #[test]
    fn span_is_copy_and_equality_is_structural() {
        let a = Span { start: 0, end: 4 };
        let b = a;
        assert_eq!(a, b);
        assert_ne!(a, Span { start: 0, end: 5 });
    }

    #[test]
    fn span_displays_as_byte_range() {
        let span = Span { start: 3, end: 7 };
        assert_eq!(span.to_string(), "bytes 3..7");
    }
}