diff --git a/YesNt-Interpreter/Attributes/StatementAttribute.cs b/YesNt-Interpreter/Attributes/StatementAttribute.cs index 4353100..853224b 100644 --- a/YesNt-Interpreter/Attributes/StatementAttribute.cs +++ b/YesNt-Interpreter/Attributes/StatementAttribute.cs @@ -10,16 +10,27 @@ namespace YesNt.Interpreter.Attributes public string Name { get; } public SearchMode SearchMode { get; } public SpaceAround SpaceAround { get; } + public ConsoleColor Color { get; set; } public Priority Priority { get; set; } = Priority.Normal; public bool ExecuteInSearchLabelMode { get; set; } public bool KeepStatementInArgs { get; set; } - public bool IgnoreSyntaxHighlighting { get; set; } + public bool IgnoreSyntaxHighlighting { get; } + public string Seperator { get; set; } + + internal StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround, ConsoleColor color) + { + Name = name; + SearchMode = searchMode; + SpaceAround = spaceAround; + Color = color; + } internal StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround) { Name = name; SearchMode = searchMode; SpaceAround = spaceAround; + IgnoreSyntaxHighlighting = true; } } } \ No newline at end of file diff --git a/YesNt-Interpreter/Runtime/StatementInformation.cs b/YesNt-Interpreter/Runtime/StatementInformation.cs index 617e03e..ed9489c 100644 --- a/YesNt-Interpreter/Runtime/StatementInformation.cs +++ b/YesNt-Interpreter/Runtime/StatementInformation.cs @@ -1,4 +1,6 @@ -using YesNt.Interpreter.Enums; +using System; + +using YesNt.Interpreter.Enums; namespace YesNt.Interpreter.Runtime { @@ -7,6 +9,8 @@ namespace YesNt.Interpreter.Runtime public string Name { get; internal set; } public SearchMode SearchMode { get; internal set; } public SpaceAround SpaceAround { get; internal set; } + public ConsoleColor Color { get; internal set; } public bool IgnoreSyntaxHighlighting { get; internal set; } + public string Seperator { get; set; } } } \ No newline at end of file diff --git a/YesNt-Interpreter/Runtime/YesNtInterpreter.cs b/YesNt-Interpreter/Runtime/YesNtInterpreter.cs index ae14c25..d21830c 100644 --- a/YesNt-Interpreter/Runtime/YesNtInterpreter.cs +++ b/YesNt-Interpreter/Runtime/YesNtInterpreter.cs @@ -29,9 +29,12 @@ namespace YesNt.Interpreter Name = s.Key.Name, SearchMode = s.Key.SearchMode, SpaceAround = s.Key.SpaceAround, - IgnoreSyntaxHighlighting = s.Key.IgnoreSyntaxHighlighting + Color = s.Key.Color, + IgnoreSyntaxHighlighting = s.Key.IgnoreSyntaxHighlighting, + Seperator = s.Key.Seperator }; }).ToList(); + return new ReadOnlyCollection(informations); } } @@ -179,9 +182,9 @@ namespace YesNt.Interpreter statement.Value.Invoke(copyLine); statementFound = true; } - else if (statementAttribute.SearchMode == SearchMode.Contains && $"{runtimeInfo.CurrentLine} ".Contains(name)) + else if (statementAttribute.SearchMode == SearchMode.Contains && $" {runtimeInfo.CurrentLine} ".Contains(name)) { - runtimeInfo.CurrentLine = $"{runtimeInfo.CurrentLine} "; + runtimeInfo.CurrentLine = $" {runtimeInfo.CurrentLine} "; string copyLine = statementAttribute.KeepStatementInArgs ? runtimeInfo.CurrentLine : runtimeInfo.CurrentLine.Replace(name, string.Empty); statement.Value.Invoke(copyLine); statementFound = true; diff --git a/YesNt-Interpreter/Statements/CodeFlowStatements.cs b/YesNt-Interpreter/Statements/CodeFlowStatements.cs index a661c4d..b3d0b16 100644 --- a/YesNt-Interpreter/Statements/CodeFlowStatements.cs +++ b/YesNt-Interpreter/Statements/CodeFlowStatements.cs @@ -1,4 +1,6 @@ -using YesNt.Interpreter.Attributes; +using System; + +using YesNt.Interpreter.Attributes; using YesNt.Interpreter.Enums; using YesNt.Interpreter.Utilities; @@ -6,7 +8,7 @@ namespace YesNt.Interpreter.Statements { internal class CodeFlowStatements : StatementRuntimeInformation { - [Statement("jmp", SearchMode.StartOfLine, SpaceAround.End, Priority = Priority.VeryLow)] + [Statement("jmp", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Green, Priority = Priority.VeryLow)] public void Jump(string args) { string key = args.Trim(); @@ -26,7 +28,7 @@ namespace YesNt.Interpreter.Statements } } - [Statement("jif", SearchMode.StartOfLine, SpaceAround.End, Priority = Priority.VeryLow)] + [Statement("jif", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Green, Priority = Priority.VeryLow, Seperator = "|")] public void JumpIf(string args) { string[] parts = args.Split('|'); @@ -65,7 +67,7 @@ namespace YesNt.Interpreter.Statements } } - [Statement("lbl", SearchMode.StartOfLine, SpaceAround.End, ExecuteInSearchLabelMode = true)] + [Statement("lbl", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Green, ExecuteInSearchLabelMode = true)] public void FindLabel(string args) { string key = args.Trim(); @@ -84,7 +86,12 @@ namespace YesNt.Interpreter.Statements } } - [Statement("ret", SearchMode.Exact, SpaceAround.None)] + [Statement("fnc", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkYellow, ExecuteInSearchLabelMode = true)] + public void FindFunction(string args) + { + } + + [Statement("ret", SearchMode.Exact, SpaceAround.None, ConsoleColor.Red)] public void Return(string _) { if (RuntimeInfo.LabelStack.Count > 0) @@ -97,13 +104,13 @@ namespace YesNt.Interpreter.Statements } } - [Statement("end", SearchMode.Exact, SpaceAround.None)] + [Statement("end", SearchMode.Exact, SpaceAround.None, ConsoleColor.Red)] public void End(string _) { RuntimeInfo.Exit("Planned termination by code", false); } - [Statement("trm", SearchMode.Exact, SpaceAround.None)] + [Statement("trm", SearchMode.Exact, SpaceAround.None, ConsoleColor.Red)] public void Terminate(string _) { RuntimeInfo.Exit("Planned termination by code. Canceling all tasks", true); diff --git a/YesNt-Interpreter/Statements/ConsoleStatements.cs b/YesNt-Interpreter/Statements/ConsoleStatements.cs index cfe73ba..9b97943 100644 --- a/YesNt-Interpreter/Statements/ConsoleStatements.cs +++ b/YesNt-Interpreter/Statements/ConsoleStatements.cs @@ -8,19 +8,19 @@ namespace YesNt.Interpreter.Statements { internal class ConsoleStatements : StatementRuntimeInformation { - [Statement("cwl", SearchMode.StartOfLine, SpaceAround.End, Priority = Priority.VeryLow)] + [Statement("cwl", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkGreen, Priority = Priority.VeryLow)] public void WriteLine(string args) { RuntimeInfo.WriteLine(args); } - [Statement("cw", SearchMode.StartOfLine, SpaceAround.End, Priority = Priority.VeryLow)] + [Statement("cw", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkGreen, Priority = Priority.VeryLow)] public void Write(string args) { RuntimeInfo.Write(args); } - [Statement("%crl", SearchMode.Contains, SpaceAround.End, KeepStatementInArgs = true, Priority = Priority.Highest)] + [Statement("%crl", SearchMode.Contains, SpaceAround.End, ConsoleColor.DarkGreen, KeepStatementInArgs = true, Priority = Priority.Highest)] public void ReadLine(string args) { args += " "; @@ -37,7 +37,7 @@ namespace YesNt.Interpreter.Statements RuntimeInfo.CurrentLine = args.TrimEnd(); } - [Statement("%cr", SearchMode.Contains, SpaceAround.End, KeepStatementInArgs = true, Priority = Priority.Highest)] + [Statement("%cr", SearchMode.Contains, SpaceAround.End, ConsoleColor.DarkGreen, KeepStatementInArgs = true, Priority = Priority.Highest)] public void ReadKey(string args) { args += " "; @@ -49,7 +49,7 @@ namespace YesNt.Interpreter.Statements RuntimeInfo.CurrentLine = args.TrimEnd(); } - [Statement("cls", SearchMode.Exact, SpaceAround.None)] + [Statement("cls", SearchMode.Exact, SpaceAround.None, ConsoleColor.Magenta)] public void Clear(string args) { Console.Clear(); diff --git a/YesNt-Interpreter/Statements/ProcessingStatements.cs b/YesNt-Interpreter/Statements/ProcessingStatements.cs index 9ae513a..ef1ccdb 100644 --- a/YesNt-Interpreter/Statements/ProcessingStatements.cs +++ b/YesNt-Interpreter/Statements/ProcessingStatements.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -11,7 +12,7 @@ namespace YesNt.Interpreter.Statements { internal class ProcessingStatements : StatementRuntimeInformation { - [Statement("!calc", SearchMode.EndOfLine, SpaceAround.Start, Priority = Priority.High, ExecuteInSearchLabelMode = true)] + [Statement("!calc", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.High, ExecuteInSearchLabelMode = true)] public void Calculate(string args) { MatchCollection matches = Regex.Matches(args, @"((\)?)+(\(?)+[0-9]+(((\s?)+(\)?)(\s?)+\+(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\-(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\*(\s?)+(\(?)+(\s?)+|(\s?)+(\)?)(\s?)+\/(\s?)+(\(?)+(\s?)+)|[,.])(?=[0-9])+)+[0-9]+(\)?)+"); @@ -30,13 +31,13 @@ namespace YesNt.Interpreter.Statements RuntimeInfo.CurrentLine = args; } - [Statement("!eval", SearchMode.EndOfLine, SpaceAround.Start, Priority = Priority.VeryHigh)] + [Statement("!eval", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.VeryHigh)] public void Evaluate(string args) { RuntimeInfo.CurrentLine = args.FromSaveString(); } - [Statement("!task", SearchMode.EndOfLine, SpaceAround.Start, Priority = Priority.VeryHigh)] + [Statement("!task", SearchMode.EndOfLine, SpaceAround.Start, ConsoleColor.DarkYellow, Priority = Priority.VeryHigh)] public void RunTask(string line) { int lineNumer = RuntimeInfo.LineNumber; @@ -52,14 +53,14 @@ namespace YesNt.Interpreter.Statements RuntimeInfo.CurrentLine = string.Empty; } - [Statement("slp", SearchMode.StartOfLine, SpaceAround.End)] + [Statement("slp", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta)] public void Sleep(string args) { _ = int.TryParse(args, out int millisecondsTimeout); ConsoleExtentions.Sleep(millisecondsTimeout, RuntimeInfo); } - [Statement("imp", SearchMode.StartOfLine, SpaceAround.End)] + [Statement("imp", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Magenta)] public void Import(string path) { if (string.IsNullOrEmpty(Path.GetExtension(path))) diff --git a/YesNt-Interpreter/Statements/VariableStatements.cs b/YesNt-Interpreter/Statements/VariableStatements.cs index 2de1b29..ac9a45e 100644 --- a/YesNt-Interpreter/Statements/VariableStatements.cs +++ b/YesNt-Interpreter/Statements/VariableStatements.cs @@ -7,7 +7,7 @@ namespace YesNt.Interpreter.Statements { internal class VariableStatements : StatementRuntimeInformation { - [Statement("<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow, IgnoreSyntaxHighlighting = true)] + [Statement("<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow)] public void DefineVariable(string args) { string[] parts = args.Split('='); @@ -35,7 +35,7 @@ namespace YesNt.Interpreter.Statements } } - [Statement("!<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow, IgnoreSyntaxHighlighting = true)] + [Statement("!<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow)] public void DefineGlobalVariable(string args) { string[] parts = args.Split('='); diff --git a/YesNt.CodeEditor/Editor.cs b/YesNt.CodeEditor/Editor.cs index d67e015..870c83c 100644 --- a/YesNt.CodeEditor/Editor.cs +++ b/YesNt.CodeEditor/Editor.cs @@ -206,7 +206,7 @@ namespace YesNt.CodeEditor } else { - Console.WriteLine($"{sharedString} [{e.OriginalLine}] => [{e.CurrentLine}] ==>"); + Console.WriteLine($"{sharedString}[{e.OriginalLine}] => [{e.CurrentLine}] ==>"); } Console.ForegroundColor = ConsoleColor.Gray; } @@ -240,7 +240,7 @@ namespace YesNt.CodeEditor return padding; } - private Point oldSize = new Point(0, 0); + private readonly Point oldSize = new Point(0, 0); private bool SizeChanged() { diff --git a/YesNt.CodeEditor/SyntaxHighlighter.cs b/YesNt.CodeEditor/SyntaxHighlighter.cs index c1a2657..30e28fc 100644 --- a/YesNt.CodeEditor/SyntaxHighlighter.cs +++ b/YesNt.CodeEditor/SyntaxHighlighter.cs @@ -37,19 +37,51 @@ namespace YesNt.CodeEditor input = input.TrimEnd(); if (statement.SearchMode == SearchMode.StartOfLine && input.StartsWith(name)) { - input = AddColorInformation(input, input.Substring(0, name.Length), ConsoleColor.DarkGreen, statement.SearchMode); + 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(0, name.Length), statement.Color, statement.SearchMode); } - if (statement.SearchMode == SearchMode.Contains && $"{input} ".Contains(name)) + if (statement.SearchMode == SearchMode.Contains && $" {input} ".Contains(name)) { - input = AddColorInformation($"{input} ", $"{input} ".Substring($"{input} ".IndexOf(name), name.Length), ConsoleColor.Green, statement.SearchMode); + 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)) { - input = AddColorInformation(input, input.Substring(input.Length - name.Length), ConsoleColor.DarkYellow, statement.SearchMode); + 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.Length - name.Length), statement.Color, statement.SearchMode); } if (statement.SearchMode == SearchMode.Exact && input.Equals(name)) { - input = AddColorInformation(input, input, ConsoleColor.Red, statement.SearchMode); + 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); } }