inf2ron 0.2.0

Parse Stranded II .inf definition files (items, objects, units, buildings, combinations) and output RON format
Documentation
// inf2ron – parse Stranded II .inf definition files to RON
// Copyright (C) 2025  inf2ron contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

//! .inf parsing errors.

use std::fmt;

#[derive(Debug)]
pub enum InfError {
    /// I/O error
    Io(std::io::Error),
    /// Syntax error at line N
    Parse {
        line: usize,
        message: String,
    },
    /// script=start without matching script=end (or vice versa)
    UnmatchedBlock {
        line: usize,
        block_type: String,
    },
}

impl fmt::Display for InfError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Io(e) => write!(f, "IO error: {e}"),
            Self::Parse { line, message } => {
                write!(f, "Parse error at line {line}: {message}")
            }
            Self::UnmatchedBlock { line, block_type } => {
                write!(
                    f,
                    "Unmatched {block_type}=start/end block starting at line {line}"
                )
            }
        }
    }
}

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

impl From<std::io::Error> for InfError {
    fn from(e: std::io::Error) -> Self {
        Self::Io(e)
    }
}

pub type InfResult<T> = Result<T, InfError>;