- Better Syntax coloring

This commit is contained in:
Stone-Red-Code
2021-10-17 00:09:17 +02:00
parent e6d31c8277
commit 812b780942
9 changed files with 90 additions and 32 deletions
@@ -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;
}
}
}
@@ -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; }
}
}
@@ -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<StatementInformation>(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;
@@ -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);
@@ -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();
@@ -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)))
@@ -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('=');
+2 -2
View File
@@ -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()
{
+37 -5
View File
@@ -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);
}
}