s2s2lua 0.1.1

Transpile Stranded II .s2s scripts to Lua for OpenStranded
Documentation
// s2s2lua – transpile Stranded II .s2s scripts to Lua for OpenStranded
// Copyright (C) 2025  s2s2lua 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/>.

//! Error types for the s2s transpiler.

use std::fmt;

/// Errors that can occur during s2s transpilation.
#[derive(Debug, Clone)]
pub enum S2sError {
    /// Lexer error at byte offset
    Lex { offset: usize, message: String },
    /// Parser error at given token position
    Parse { line: usize, column: usize, message: String },
    /// Unsupported s2s construct (should not happen for standard scripts)
    Unsupported(String),
}

impl fmt::Display for S2sError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Lex { offset, message } => {
                write!(f, "Lexer error at offset {offset}: {message}")
            }
            Self::Parse { line, column, message } => {
                write!(f, "Parse error at {line}:{column}: {message}")
            }
            Self::Unsupported(s) => write!(f, "Unsupported s2s construct: {s}"),
        }
    }
}

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

pub type S2sResult<T> = Result<T, S2sError>;