mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 23:43:16 +02:00
Centralize exit messages in ExitMessages class
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
namespace YesNt.Interpreter.Runtime;
|
||||
|
||||
internal static class ExitMessages
|
||||
{
|
||||
internal const string InvalidSyntax = "Invalid syntax";
|
||||
internal const string InvalidSyntaxColonRequired = "Invalid syntax. Statement must end with ':'";
|
||||
internal const string InvalidOperation = "Invalid operation";
|
||||
internal const string InvalidStatement = "Invalid statement";
|
||||
internal const string InvalidStringLiteral = "Invalid string literal";
|
||||
internal const string EndOfFile = "End of file";
|
||||
internal const string TerminatedByExternalProcess = "Terminated by external process";
|
||||
internal const string TerminatedByChildTask = "Terminated by child task";
|
||||
internal const string TerminatedByParentTask = "Terminated by parent task";
|
||||
internal const string PlannedTermination = "Planned termination by code";
|
||||
internal const string PlannedTerminationCancelingTasks = "Planned termination by code. Canceling all tasks";
|
||||
internal const string NoMatchingEndIf = "No matching end_if found";
|
||||
internal const string NoMatchingEndWhile = "No matching end_while found";
|
||||
internal const string NoMatchingWhile = "No matching while found";
|
||||
internal const string NestedFunctionsNotAllowed = "Nested functions are not allowed";
|
||||
internal const string NoOutArgumentInStack = "No out argument in stack";
|
||||
internal const string StatementNotAllowedOutsideFunction = "Statement not allowed outside of function";
|
||||
internal const string NoInArgumentInStack = "No in argument in stack";
|
||||
internal const string NoFunctionInStack = "No function in stack";
|
||||
|
||||
internal static string LabelNotFound(string label) => $"Label \"{label}\" not found";
|
||||
internal static string FunctionNotFound(string function) => $"Function \"{function}\" not found";
|
||||
internal static string VariableNotFound(string variable) => $"Variable \"{variable}\" not found";
|
||||
internal static string ListNotFound(string list) => $"List \"{list}\" not found";
|
||||
internal static string InvalidIndex(string rawIndex) => $"\"{rawIndex}\" is not a valid index";
|
||||
internal static string IndexOutOfRange(int index) => $"Index {index} out of range";
|
||||
internal static string InvalidTimeoutValue(string value) => $"\"{value}\" is not a valid time-out value";
|
||||
internal static string CouldNotLoadFile(string path) => $"Could not load file \"{path}\"";
|
||||
internal static string CouldNotFindFile(string path) => $"Could not find file \"{path}\"";
|
||||
internal static string CannotFindFile(string path) => $"Cannot find file \"{path}\".";
|
||||
internal static string FailedToStart(string program, string message) => $"Failed to start \"{program}\". {message}";
|
||||
}
|
||||
@@ -131,7 +131,7 @@ internal sealed class RuntimeInformation
|
||||
{
|
||||
StopAllTasks = true;
|
||||
OnExit?.Invoke(message, StopAllTasks);
|
||||
parentRuntimeInformation?.Exit("Terminated by child task", true);
|
||||
parentRuntimeInformation?.Exit(ExitMessages.TerminatedByChildTask, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,6 @@ internal sealed class RuntimeInformation
|
||||
|
||||
private void ParentRuntimeInformation_OnExit(string exitMessage, bool stopAllTasks)
|
||||
{
|
||||
Exit($"Terminated by parent task", stopAllTasks);
|
||||
Exit(ExitMessages.TerminatedByParentTask, stopAllTasks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class YesNtInterpreter
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
runtimeInfo.Exit("Terminated by external process", true);
|
||||
runtimeInfo.Exit(ExitMessages.TerminatedByExternalProcess, true);
|
||||
}
|
||||
|
||||
public void Execute(string path, bool isDebugMode = false)
|
||||
@@ -106,7 +106,7 @@ public class YesNtInterpreter
|
||||
runtimeInfo.GlobalVariables = globalVariables;
|
||||
if (parentRuntimeInformation.StopAllTasks)
|
||||
{
|
||||
runtimeInfo.Exit($"Parent task was terminated!", parentRuntimeInformation.StopAllTasks);
|
||||
runtimeInfo.Exit(ExitMessages.TerminatedByParentTask, parentRuntimeInformation.StopAllTasks);
|
||||
return;
|
||||
}
|
||||
Execute();
|
||||
@@ -203,7 +203,7 @@ public class YesNtInterpreter
|
||||
|
||||
if (!statementFound)
|
||||
{
|
||||
runtimeInfo.Exit("Invalid statement", true);
|
||||
runtimeInfo.Exit(ExitMessages.InvalidStatement, true);
|
||||
}
|
||||
if (runtimeInfo.IsDebugMode && notSearchingLabel)
|
||||
{
|
||||
@@ -216,15 +216,15 @@ public class YesNtInterpreter
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(runtimeInfo.SearchLabel))
|
||||
{
|
||||
runtimeInfo.Exit($"Label \"{runtimeInfo.SearchLabel}\" not found", true);
|
||||
runtimeInfo.Exit(ExitMessages.LabelNotFound(runtimeInfo.SearchLabel), true);
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(runtimeInfo.SearchFunction))
|
||||
{
|
||||
runtimeInfo.Exit($"Function \"{runtimeInfo.SearchFunction}\" not found", true);
|
||||
runtimeInfo.Exit(ExitMessages.FunctionNotFound(runtimeInfo.SearchFunction), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
runtimeInfo.Exit("End of file", false);
|
||||
runtimeInfo.Exit(ExitMessages.EndOfFile, false);
|
||||
}
|
||||
|
||||
if (runtimeInfo.IsDebugMode)
|
||||
|
||||
Reference in New Issue
Block a user