Add more statements and bug fixes

Add `Execute(List<string>...` method to interpreter
Add escape sequence (`!!`)
Fix `Evaluator.Calulate` method not correctly handling `-` and `+` prefixes
This commit is contained in:
Stone_Red
2022-03-31 13:00:12 +02:00
parent 29bbcebf74
commit 3333641541
11 changed files with 101 additions and 41 deletions
+7 -7
View File
@@ -61,7 +61,7 @@ namespace YesNt.CodeEditor
if (SizeChanged())
{
drawAll = true;
inputHandler.WriteStatus(string.Empty);
InputHandler.WriteStatus(string.Empty);
}
if (LineOffset < 0 || CursorPosition.Y < 0 || CursorPosition.Y < 0)
@@ -111,14 +111,14 @@ namespace YesNt.CodeEditor
if (!File.Exists(path))
{
inputHandler.WriteStatus("File does not exist!");
InputHandler.WriteStatus("File does not exist!");
return false;
}
Lines.Clear();
Lines.AddRange(File.ReadAllLines(path));
CurrentPath = path;
inputHandler.WriteStatus("File Loaded!");
InputHandler.WriteStatus("File Loaded!");
return true;
}
@@ -152,12 +152,12 @@ namespace YesNt.CodeEditor
}
else if (input.Split(' ').Length > 2)
{
inputHandler.WriteStatus("Invalid arguments!");
InputHandler.WriteStatus("Invalid arguments!");
return false;
}
else
{
inputHandler.WriteStatus("File path is empty! (Save the file before you can use this command)");
InputHandler.WriteStatus("File path is empty! (Save the file before you can use this command)");
return false;
}
@@ -174,12 +174,12 @@ namespace YesNt.CodeEditor
try
{
File.WriteAllLines(path, Lines);
inputHandler.WriteStatus("File Saved!");
InputHandler.WriteStatus("File Saved!");
return true;
}
catch (Exception ex)
{
inputHandler.WriteStatus(ex.Message);
InputHandler.WriteStatus(ex.Message);
return false;
}
}
+7 -3
View File
@@ -1,4 +1,5 @@
using System;
using System.Text;
namespace YesNt.CodeEditor
{
@@ -124,11 +125,14 @@ namespace YesNt.CodeEditor
textEditor.Lines.Add("");
}
while (textEditor.Lines[textEditor.CursorPosition.Y].Length <= textEditor.CursorPosition.X)
StringBuilder lineBuilder = new StringBuilder(textEditor.Lines[textEditor.CursorPosition.Y]);
while (lineBuilder.Length <= textEditor.CursorPosition.X)
{
textEditor.Lines[textEditor.CursorPosition.Y] += " ";
lineBuilder.Append(' ');
}
textEditor.Lines[textEditor.CursorPosition.Y] = lineBuilder.ToString();
if (keyInfo.Key == ConsoleKey.Backspace)
{
if (textEditor.CursorPosition.X > 0)
@@ -307,7 +311,7 @@ namespace YesNt.CodeEditor
return true;
}
public void WriteStatus(string input)
internal static void WriteStatus(string input)
{
Console.SetCursorPosition(0, Console.WindowHeight - 1);
Console.Write(input + new string(' ', Console.WindowWidth - input.Length - 1));
+9 -3
View File
@@ -27,6 +27,12 @@ namespace YesNt.CodeEditor
}
else
{
MatchCollection matches = Regex.Matches(input, @"!!.");
for (int i = 0; i < matches.Count; i++)
{
input = AddColorInformation(input, matches[i].Value, Console.ForegroundColor, SearchMode.Contains);
}
foreach (StatementInformation statement in statementInformation)
{
if (statement.IgnoreSyntaxHighlighting)
@@ -92,7 +98,7 @@ namespace YesNt.CodeEditor
}
}
MatchCollection matches = Regex.Matches(input, @">[a-zA-Z0-9]+");
matches = Regex.Matches(input, @">[a-zA-Z0-9]+");
for (int i = 0; i < matches.Count; i++)
{
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Cyan, SearchMode.Contains);
@@ -134,11 +140,11 @@ namespace YesNt.CodeEditor
}
Console.ForegroundColor = consoleColor;
Console.Write(messagePart);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.ForegroundColor = ConsoleColor.Gray;
}
private string AddColorInformation(string originalString, string value, ConsoleColor color, SearchMode searchMode)
private static string AddColorInformation(string originalString, string value, ConsoleColor color, SearchMode searchMode)
{
int spacesAtEnd = value.WhiteSpaceAtEnd();
string reult = searchMode switch