mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-04 00:56:31 +02:00
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:
@@ -20,93 +20,96 @@ namespace YesNt.CodeEditor
|
||||
public void Write(string input)
|
||||
{
|
||||
input = input.Replace("\0", string.Empty);
|
||||
foreach (StatementInformation statement in statementInformation)
|
||||
{
|
||||
if (statement.IgnoreSyntaxHighlighting)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string name = statement.SpaceAround switch
|
||||
{
|
||||
SpaceAround.StartEnd => $" {statement.Name.Trim()} ",
|
||||
SpaceAround.Start => $" {statement.Name.Trim()}",
|
||||
SpaceAround.End => $"{statement.Name.Trim()} ",
|
||||
_ => statement.Name
|
||||
};
|
||||
input = input.TrimEnd();
|
||||
if (statement.SearchMode == SearchMode.StartOfLine && input.StartsWith(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input[..name.Length], statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.Contains && $" {input} ".Contains(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation($"{input} ", $"{input} ".Substring($"{input} ".IndexOf(name), name.Length), statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.EndOfLine && input.EndsWith(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input[^name.Length..], statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.Exact && input.Equals(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input, statement.Color, statement.SearchMode);
|
||||
}
|
||||
}
|
||||
|
||||
MatchCollection 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);
|
||||
}
|
||||
|
||||
matches = Regex.Matches(input, @"^<[a-zA-Z0-9]+");
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.DarkCyan, SearchMode.StartOfLine);
|
||||
}
|
||||
|
||||
matches = Regex.Matches(input, @"^!<[a-zA-Z0-9]+");
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Blue, SearchMode.StartOfLine);
|
||||
}
|
||||
|
||||
if (input.StartsWith('#'))
|
||||
{
|
||||
input = AddColorInformation(input, input, ConsoleColor.Gray, SearchMode.Exact);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (StatementInformation statement in statementInformation)
|
||||
{
|
||||
if (statement.IgnoreSyntaxHighlighting)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string name = statement.SpaceAround switch
|
||||
{
|
||||
SpaceAround.StartEnd => $" {statement.Name.Trim()} ",
|
||||
SpaceAround.Start => $" {statement.Name.Trim()}",
|
||||
SpaceAround.End => $"{statement.Name.Trim()} ",
|
||||
_ => statement.Name
|
||||
};
|
||||
input = input.TrimEnd();
|
||||
if (statement.SearchMode == SearchMode.StartOfLine && input.StartsWith(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input[..name.Length], statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.Contains && $" {input} ".Contains(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation($"{input} ", $"{input} ".Substring($"{input} ".IndexOf(name), name.Length), statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.EndOfLine && input.EndsWith(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input[^name.Length..], statement.Color, statement.SearchMode);
|
||||
}
|
||||
if (statement.SearchMode == SearchMode.Exact && input.Equals(name))
|
||||
{
|
||||
if (statement.Seperator is not null && input.Contains(statement.Seperator))
|
||||
{
|
||||
input = AddColorInformation(input, statement.Seperator, statement.Color, SearchMode.StartOfLine);
|
||||
}
|
||||
else if (statement.Seperator is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
input = AddColorInformation(input, input, statement.Color, statement.SearchMode);
|
||||
}
|
||||
}
|
||||
|
||||
MatchCollection 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);
|
||||
}
|
||||
|
||||
matches = Regex.Matches(input, @"^<[a-zA-Z0-9]+");
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.DarkCyan, SearchMode.StartOfLine);
|
||||
}
|
||||
|
||||
matches = Regex.Matches(input, @"^!<[a-zA-Z0-9]+");
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Blue, SearchMode.StartOfLine);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user