1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![warn(missing_docs)]

//! This library is used for parsing MCVM package scripts
//!
//! # Features:
//!
//! - `schema`: Enable generation of JSON schemas using the `schemars` crate

/// Parsing for conditions, used in if instructions
pub mod conditions;
/// Parsing for most instructions, with the exception of a few complex ones
pub mod instruction;
/// Token generation from a string, which is passed into the parser
pub mod lex;
/// General parsing
pub mod parse;
/// Things related to package script routines
pub mod routine;
/// Things related to script variables
pub mod vars;

use std::fmt::Display;

/// Reason why the package reported a failure
#[derive(Debug, Clone)]
pub enum FailReason {
	/// No fail reason is provided
	None,
	/// The Minecraft version is unsupported
	UnsupportedVersion,
	/// The modloader is unsupported
	UnsupportedModloader,
	/// The plugin loader is unsupported
	UnsupportedPluginLoader,
	/// The configured set of features is unsupported
	UnsupportedFeatures,
	/// The operating system is unsupported
	UnsupportedOperatingSystem,
	/// The architecture is unsupported
	UnsupportedArchitecture,
}

impl FailReason {
	/// Parse a FailReason from a string
	pub fn from_string(string: &str) -> Option<Self> {
		match string {
			"unsupported_version" => Some(Self::UnsupportedVersion),
			"unsupported_modloader" => Some(Self::UnsupportedModloader),
			"unsupported_plugin_loader" => Some(Self::UnsupportedPluginLoader),
			"unsupported_features" => Some(Self::UnsupportedFeatures),
			"unsupported_operating_system" => Some(Self::UnsupportedFeatures),
			"unsupported_architecture" => Some(Self::UnsupportedArchitecture),
			_ => None,
		}
	}
}

impl Display for FailReason {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		write!(
			f,
			"{}",
			match self {
				Self::None => "",
				Self::UnsupportedVersion => "Unsupported Minecraft version",
				Self::UnsupportedModloader => "Unsupported modloader",
				Self::UnsupportedPluginLoader => "Unsupported plugin loader",
				Self::UnsupportedFeatures => "Unsupported feature set",
				Self::UnsupportedOperatingSystem => "Unsupported operating system",
				Self::UnsupportedArchitecture => "Unsupported system architecture",
			}
		)
	}
}