mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-10 07:56:08 +02:00
Make YesNtInterpreter usable as a library and add AddStatement method to be able to define custom statement
This commit is contained in:
@@ -5,7 +5,7 @@ using YesNt.Interpreter.Enums;
|
||||
namespace YesNt.Interpreter.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
internal class StatementAttribute : Attribute
|
||||
public class StatementAttribute : Attribute
|
||||
{
|
||||
public string Name { get; }
|
||||
public SearchMode SearchMode { get; }
|
||||
@@ -17,7 +17,7 @@ internal class StatementAttribute : Attribute
|
||||
public bool IgnoreSyntaxHighlighting { get; }
|
||||
public string Separator { get; set; }
|
||||
|
||||
internal StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround, ConsoleColor color)
|
||||
public StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround, ConsoleColor color)
|
||||
{
|
||||
Name = name;
|
||||
SearchMode = searchMode;
|
||||
@@ -25,7 +25,7 @@ internal class StatementAttribute : Attribute
|
||||
Color = color;
|
||||
}
|
||||
|
||||
internal StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround)
|
||||
public StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround)
|
||||
{
|
||||
Name = name;
|
||||
SearchMode = searchMode;
|
||||
|
||||
@@ -5,7 +5,7 @@ using YesNt.Interpreter.Enums;
|
||||
namespace YesNt.Interpreter.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
internal class StaticStatementAttribute : Attribute
|
||||
public class StaticStatementAttribute : Attribute
|
||||
{
|
||||
public bool ExecuteInSearchMode { get; set; }
|
||||
public Priority Priority { get; set; } = Priority.Normal;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace YesNt.Interpreter.Enums;
|
||||
|
||||
internal enum Priority
|
||||
public enum Priority
|
||||
{
|
||||
PreProcessing,
|
||||
Highest,
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
using YesNt.Interpreter.Runtime;
|
||||
|
||||
if (args.Length == 1)
|
||||
namespace YesNt.Interpreter;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||
interpreter.Initialize();
|
||||
interpreter.Execute(args[0]);
|
||||
internal static void Main(string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||
interpreter.Initialize();
|
||||
interpreter.Execute(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No path specified!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No path specified!");
|
||||
}
|
||||
@@ -41,6 +41,25 @@ public class YesNtInterpreter
|
||||
}
|
||||
}
|
||||
|
||||
public void AddStatement(StatementAttribute attribute, Action<string> handler)
|
||||
{
|
||||
statements[attribute] = handler;
|
||||
statements = statements
|
||||
.OrderBy(s => s.Key.Priority)
|
||||
.ThenByDescending(s => s.Key.Name.Length)
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
|
||||
public void AddStatement(string name, SearchMode searchMode, SpaceAround spaceAround, Action<string> handler)
|
||||
{
|
||||
AddStatement(new StatementAttribute(name, searchMode, spaceAround), handler);
|
||||
}
|
||||
|
||||
public void AddStatement(string name, SearchMode searchMode, SpaceAround spaceAround, ConsoleColor consoleColor, Action<string> handler)
|
||||
{
|
||||
AddStatement(new StatementAttribute(name, searchMode, spaceAround, consoleColor), handler);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
runtimeInfo.Exit("Terminated by external process", true);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>YesNt.Interpreter</RootNamespace>
|
||||
<ApplicationIcon />
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>Library</OutputType>
|
||||
<StartupObject />
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user