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
@@ -13,11 +13,9 @@ namespace YesNt.Interpreter.Statements
{
internal class ProcessingStatements : StatementRuntimeInformation
{
private static readonly Regex calculationRegex = new Regex(@"((\)?)+(\(?)+[0-9]+(((\s?)+(\)?)(\s?)+\+(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\-(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\*(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\%(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\^(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\/(\s?)+(\(?)+(\s?)+)|[,.])(?=[0-9])+)+[0-9]+(\)?)+");
private static readonly Regex calculationRegex = new Regex(@"[0-9*+().,^%/-]+[0-9*+ ().,^%/-]+[0-9*+().,^%/-]+");
//new Regex(@"((\)?)+(\(?)+[0-9]+(((\s?)+(\)?)(\s?)+\+(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\-(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\*(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\/(\s?)+(\(?)+(\s?)+)|[,.])(?=[0-9])+)+[0-9]+(\)?)+");
[Statement("!calc", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.High, ExecuteInSearchMode = true)]
[Statement("!calc", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.High)]
public void Calculate(string args)
{
MatchCollection matches = calculationRegex.Matches(args.FromSaveString());
@@ -30,7 +28,7 @@ namespace YesNt.Interpreter.Statements
RuntimeInfo.Exit("Invalid operation", true);
return;
}
args = args.FromSaveString().Replace(matches[0].Value, res);
args = args.FromSaveString().Replace(matches[i].Value, res);
}
RuntimeInfo.CurrentLine = args;
@@ -42,6 +40,23 @@ namespace YesNt.Interpreter.Statements
RuntimeInfo.CurrentLine = args.FromSaveString();
}
[Statement("!!", SearchMode.Contains, SpaceAround.None, ConsoleColor.DarkYellow, Priority = Priority.PreProcessing, KeepStatementInArgs = true)]
public void DontEvaluate(string args)
{
int index;
while ((index = args.IndexOf("!!")) != -1)
{
args = args.Remove(index, 2);
if (index < args.Length)
{
char charToEscape = args[index];
args = args.Remove(index, 1);
args = args.Insert(index, charToEscape.ToString().ToSaveString());
}
}
RuntimeInfo.CurrentLine = args;
}
[Statement("!task", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.VeryHigh)]
public void RunTask(string line)
{