tinyscript 0.6.1

Tiny, C-like scripting language.
Documentation
// Copyright © 2025 Stephan Kunz
//! Compilation errors, only internaly used.

use thiserror::Error;

use crate::ConstString;

/// Things that may go wrong during compilation of a script.
#[derive(Error, Debug)]
pub enum CompilationError {
	/// Stack of values exceeded.
	#[error("to many constant values defined: storage overflow")]
	ConstantStorageOverflow,
	/// Enum value is not defined.
	#[error("the ScriptEnum value {value} at line {pos} is not defined")]
	EnumValNotFound {
		/// Name of the enum value.
		value: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// Whatever it is: It is not an expression.
	#[error("expression expected at line {pos}, got {token}")]
	ExpressionExpected {
		/// The faulty token.
		token: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// Not a hex number.
	#[error("could not parse {token} at line {pos} as Hex value")]
	ParseHex {
		/// The faulty token.
		token: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// Not an int number.
	#[error("could not parse {token} at line {pos} as Integer value")]
	ParseInt {
		/// The faulty token.
		token: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// Not a float number.
	#[error("could not parse {token} at line {pos} as Double value")]
	ParseNumber {
		/// The faulty token.
		token: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// Did not get the expected `Token`.
	#[error("expected token {expected}, found Token {found} at line {pos}")]
	TokenExpected {
		/// The expected token.
		expected: ConstString,
		/// The found token.
		found: ConstString,
		/// Position(line) in code.
		pos: usize,
	},
	/// This char should not be here.
	#[error("unexpected character {c} at line {pos}")]
	UnexpectedChar {
		/// The faulty character.
		c: char,
		/// Position(line) in code.
		pos: usize,
	},
	/// Missing string termination.
	#[error("unterminated string {str} at line {pos}")]
	UnterminatedString {
		/// The unterminated sequence.
		str: ConstString,
		/// Position(line) in code.
		pos: usize,
	},

	/// This code line never should have been reached.
	#[error("{file} at line {line} should be unreachable")]
	Unreachable {
		/// The faulty file.
		file: ConstString,
		/// The faulty line.
		line: u32,
	},
}

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

	// check, that the auto traits are available
	const fn is_normal<T: Sized + Send + Sync>() {}

	#[test]
	const fn normal_types() {
		is_normal::<&CompilationError>();
		is_normal::<CompilationError>();
	}
}