From c1b581e2dba9059350c943305084e90f18ef8585 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 31 Mar 2022 21:51:31 +0200 Subject: [PATCH] Fix bugs and add new statement - Add clear call stack (`ccs`) statement - Use `\v` instead of `\r` to support escape sequences in the future --- YesNt.Interpreter/Runtime/YesNtInterpreter.cs | 12 ++++++------ YesNt.Interpreter/Statements/FunctionStatements.cs | 6 ++++++ YesNt.Interpreter/Utilities/StringExtentions.cs | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/YesNt.Interpreter/Runtime/YesNtInterpreter.cs b/YesNt.Interpreter/Runtime/YesNtInterpreter.cs index 9711d7d..1b89015 100644 --- a/YesNt.Interpreter/Runtime/YesNtInterpreter.cs +++ b/YesNt.Interpreter/Runtime/YesNtInterpreter.cs @@ -87,7 +87,7 @@ namespace YesNt.Interpreter.Runtime staticStatements = staticStatements.OrderBy(s => s.Key.Priority).ToList(); runtimeInfo.OnDebugOutput += (s) => OnDebugOutput?.Invoke(s); - runtimeInfo.OnLineExecuted += (DebugEventArgs e) => OnLineExecuted.Invoke(e); + runtimeInfo.OnLineExecuted += (DebugEventArgs e) => OnLineExecuted?.Invoke(e); } public void Execute(string path, bool isDebugMode = false) @@ -138,6 +138,11 @@ namespace YesNt.Interpreter.Runtime runtimeInfo.CurrentLine = runtimeInfo.Lines[runtimeInfo.LineNumber].Content.TrimEnd().Replace("\r", string.Empty); + if (string.IsNullOrWhiteSpace(runtimeInfo.CurrentLine) || runtimeInfo.CurrentLine.StartsWith('#')) + { + continue; + } + DebugEventArgs debugEventArgs = new DebugEventArgs() { LineNumber = runtimeInfo.LineNumber + 1, @@ -146,11 +151,6 @@ namespace YesNt.Interpreter.Runtime TaskId = runtimeInfo.TaskId }; - if (string.IsNullOrWhiteSpace(runtimeInfo.CurrentLine) || runtimeInfo.CurrentLine.StartsWith('#')) - { - continue; - } - foreach (KeyValuePair staticStatement in staticStatements) { StaticStatementAttribute staticStatementAttribute = staticStatement.Key; diff --git a/YesNt.Interpreter/Statements/FunctionStatements.cs b/YesNt.Interpreter/Statements/FunctionStatements.cs index 38a7b01..23d67a6 100644 --- a/YesNt.Interpreter/Statements/FunctionStatements.cs +++ b/YesNt.Interpreter/Statements/FunctionStatements.cs @@ -190,5 +190,11 @@ namespace YesNt.Interpreter.Statements RuntimeInfo.Exit("No function in stack", true); } } + + [Statement("ccs", SearchMode.Exact, SpaceAround.None, ConsoleColor.Red)] + public void ClearCallStack(string _) + { + RuntimeInfo.FunctionCallStack.Clear(); + } } } \ No newline at end of file diff --git a/YesNt.Interpreter/Utilities/StringExtentions.cs b/YesNt.Interpreter/Utilities/StringExtentions.cs index a7ee58e..6c81400 100644 --- a/YesNt.Interpreter/Utilities/StringExtentions.cs +++ b/YesNt.Interpreter/Utilities/StringExtentions.cs @@ -11,14 +11,14 @@ namespace YesNt.Interpreter.Utilities StringBuilder output = new StringBuilder(); foreach (char c in input) { - output.Append($"\r{c}\r"); + output.Append($"\v{c}\v"); } return output.ToString(); } public static string FromSaveString(this string input) { - return input.Replace("\r", ""); + return input.Replace("\v", ""); } public static bool ToStandardizedNumber(this string input, out double result)