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:
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesNt.Interpreter.Tests", "YesNt.Interpreter.Tests\YesNt.Interpreter.Tests.csproj", "{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesNt.Interpreter.Tests", "YesNt.Interpreter.Tests\YesNt.Interpreter.Tests.csproj", "{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesNt.Interpreter.App", "YesNt.Interpreter.App\YesNt.Interpreter.App.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
|
||||||
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesNt.Interpreter.Generator", "YesNt.Interpreter.Generator\YesNt.Interpreter.Generator.csproj", "{85AAB233-9C4D-4B42-8117-00010958DD1D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesNt.Interpreter.Generator", "YesNt.Interpreter.Generator\YesNt.Interpreter.Generator.csproj", "{85AAB233-9C4D-4B42-8117-00010958DD1D}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
@@ -62,6 +64,18 @@ Global
|
|||||||
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x64.Build.0 = Release|x64
|
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x64.Build.0 = Release|x64
|
||||||
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x86.ActiveCfg = Release|Any CPU
|
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x86.Build.0 = Release|Any CPU
|
{2F95DCA7-3E43-4F2E-8FB2-067F0EC962B1}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|x64.Build.0 = Release|x64
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
{85AAB233-9C4D-4B42-8117-00010958DD1D}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using YesNt.Interpreter.Runtime;
|
||||||
|
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||||
|
interpreter.Initialize();
|
||||||
|
interpreter.Execute(args[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No path specified!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\YesNt.Interpreter\YesNt.Interpreter.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -5,7 +5,7 @@ using YesNt.Interpreter.Enums;
|
|||||||
namespace YesNt.Interpreter.Attributes;
|
namespace YesNt.Interpreter.Attributes;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||||
internal class StatementAttribute : Attribute
|
public class StatementAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public SearchMode SearchMode { get; }
|
public SearchMode SearchMode { get; }
|
||||||
@@ -17,7 +17,7 @@ internal class StatementAttribute : Attribute
|
|||||||
public bool IgnoreSyntaxHighlighting { get; }
|
public bool IgnoreSyntaxHighlighting { get; }
|
||||||
public string Separator { get; set; }
|
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;
|
Name = name;
|
||||||
SearchMode = searchMode;
|
SearchMode = searchMode;
|
||||||
@@ -25,7 +25,7 @@ internal class StatementAttribute : Attribute
|
|||||||
Color = color;
|
Color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround)
|
public StatementAttribute(string name, SearchMode searchMode, SpaceAround spaceAround)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
SearchMode = searchMode;
|
SearchMode = searchMode;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using YesNt.Interpreter.Enums;
|
|||||||
namespace YesNt.Interpreter.Attributes;
|
namespace YesNt.Interpreter.Attributes;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||||
internal class StaticStatementAttribute : Attribute
|
public class StaticStatementAttribute : Attribute
|
||||||
{
|
{
|
||||||
public bool ExecuteInSearchMode { get; set; }
|
public bool ExecuteInSearchMode { get; set; }
|
||||||
public Priority Priority { get; set; } = Priority.Normal;
|
public Priority Priority { get; set; } = Priority.Normal;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace YesNt.Interpreter.Enums;
|
namespace YesNt.Interpreter.Enums;
|
||||||
|
|
||||||
internal enum Priority
|
public enum Priority
|
||||||
{
|
{
|
||||||
PreProcessing,
|
PreProcessing,
|
||||||
Highest,
|
Highest,
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
using YesNt.Interpreter.Runtime;
|
using YesNt.Interpreter.Runtime;
|
||||||
|
|
||||||
|
namespace YesNt.Interpreter;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
internal static void Main(string[] args)
|
||||||
|
{
|
||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
{
|
{
|
||||||
YesNtInterpreter interpreter = new YesNtInterpreter();
|
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||||
@@ -12,3 +18,5 @@ else
|
|||||||
{
|
{
|
||||||
Console.WriteLine("No path specified!");
|
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()
|
public void Stop()
|
||||||
{
|
{
|
||||||
runtimeInfo.Exit("Terminated by external process", true);
|
runtimeInfo.Exit("Terminated by external process", true);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<RootNamespace>YesNt.Interpreter</RootNamespace>
|
<RootNamespace>YesNt.Interpreter</RootNamespace>
|
||||||
<ApplicationIcon />
|
<ApplicationIcon />
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user