fluid-parser 0.1.16

A fluid (fltk ui designer) file parser
Documentation
use std::fmt;

#[derive(Debug, Clone, PartialEq, Eq, Copy, Default)]
pub struct Location {
    pub line: usize,
    pub col: usize,
}

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

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FluidError {
    UnexpectedToken(Location),
    UnexpectedEof(Location),
    Parse(String, Location),
}

impl fmt::Display for FluidError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            FluidError::UnexpectedToken(loc) => write!(f, "{}: Unexpected token", loc),
            FluidError::UnexpectedEof(loc) => write!(f, "{}: Unexpected eof", loc),
            FluidError::Parse(s, loc) => write!(f, "{}: Failed to parse `{}`", loc, s),
        }
    }
}

impl std::error::Error for FluidError {}