Change logic of some changes

- `%rnd` now returns a random integer between `32767` and `int.MaxValue`
- Fix syntax hyglighing problems when using comments
- Remove the `mod` statement
This commit is contained in:
Stone_Red
2022-03-27 20:25:44 +02:00
parent 20f7f16dd9
commit 6a4fe4f871
3 changed files with 87 additions and 120 deletions
+7 -4
View File
@@ -20,6 +20,13 @@ namespace YesNt.CodeEditor
public void Write(string input)
{
input = input.Replace("\0", string.Empty);
if (input.StartsWith('#'))
{
input = AddColorInformation(input, input, ConsoleColor.Gray, SearchMode.Exact);
}
else
{
foreach (StatementInformation statement in statementInformation)
{
if (statement.IgnoreSyntaxHighlighting)
@@ -102,10 +109,6 @@ namespace YesNt.CodeEditor
{
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Blue, SearchMode.StartOfLine);
}
if (input.StartsWith('#'))
{
input = AddColorInformation(input, input, ConsoleColor.Gray, SearchMode.Exact);
}
foreach (string part in input.Split("\0"))
@@ -39,7 +39,7 @@ namespace YesNt.Interpreter.Statements
while (args.Contains("%rnd "))
{
args = args.ReplaceFirstOccurrence("%rnd ", $"{random.Next() % 2} ");
args = args.ReplaceFirstOccurrence("%rnd ", $"{random.Next(32767, int.MaxValue)} ");
}
RuntimeInfo.CurrentLine = args.TrimEnd();
@@ -85,7 +85,7 @@ namespace YesNt.Interpreter.Statements
for (int i = 0; i < lines.Length; i++)
{
RuntimeInfo.Lines.Add(new Line(lines[i], Path.GetFileName(path), i));
RuntimeInfo.Lines.Insert(RuntimeInfo.LineNumber + i, new Line(lines[i], Path.GetFileName(path), i));
}
RuntimeInfo.LineNumber--;
}
@@ -99,41 +99,5 @@ namespace YesNt.Interpreter.Statements
RuntimeInfo.Exit($"Could not find file \"{path}\"", true);
}
}
[Statement("mod", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkYellow, Priority = Priority.VeryLow, Seperator = "|")]
public void GetModulo(string args)
{
string[] parts = args.Split('|');
if (parts.Length != 2)
{
RuntimeInfo.Exit("Invalid syntax", true);
return;
}
string[] nums = parts[1].Split(',');
if (nums.Length != 2)
{
RuntimeInfo.Exit("Invalid arguments", true);
return;
}
string variableName = parts[0].Trim();
if (ulong.TryParse(nums[0], out ulong num1) && ulong.TryParse(nums[1], out ulong num2))
{
if (RuntimeInfo.Variables.ContainsKey(variableName))
{
RuntimeInfo.Variables[variableName] = (num1 % num2).ToString();
}
else
{
RuntimeInfo.Variables.Add(variableName, (num1 % num2).ToString());
}
}
else
{
RuntimeInfo.Exit("Invalid arguments", true);
}
}
}
}