ripex 0.3.0

Multi-language structural parsing and fact extraction.
Documentation
use std::fmt;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Pos {
    pub offset: usize,
    pub line: usize,
    pub column: usize,
}

impl Pos {
    pub const fn new(offset: usize, line: usize, column: usize) -> Self {
        Pos {
            offset,
            line,
            column,
        }
    }

    pub const ZERO: Pos = Pos::new(0, 1, 0);
}

impl fmt::Display for Pos {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}:{}", self.line, self.column)
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Span {
    pub start: Pos,
    pub end: Pos,
}

impl Span {
    pub const fn new(start: Pos, end: Pos) -> Self {
        Span { start, end }
    }

    pub const ZERO: Span = Span::new(Pos::ZERO, Pos::ZERO);

    pub fn merge(self, other: Span) -> Span {
        Span {
            start: self.start,
            end: other.end,
        }
    }
}

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