stop all work on text regex, ngra text regex is now frozen
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="TestRegexAnalyse"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using Nitload.RegularAnalysis.Abstraction;
|
||||
using Nitload.RegularAnalysis.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nitload
|
||||
{
|
||||
public partial class TestRegexAnalyse
|
||||
{
|
||||
|
||||
private static string[] regexSource = [
|
||||
@"12(1234|(012.*34)|9125)34",
|
||||
/**/
|
||||
@"http|https|ftp|ftps",
|
||||
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
|
||||
@"get_name|get_value|get_type|set_name|set_value|set_type",
|
||||
@"helix|hello|help|hero|hers|her",
|
||||
@"a*.[abc]*(?<a>abcd|a(bc)c)(?<name>.*)234"
|
||||
/**/
|
||||
];
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
foreach (string regex in regexSource)
|
||||
{
|
||||
TextRegexSource interpreterSource = RegexAnalyzer.Analyze(regex);
|
||||
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree = interpreterSource.Ast;
|
||||
Console.WriteLine($"result of \"{regex}\"");
|
||||
TreeEnumerator<RegexAstNode, RegexElementLabel> enumerator = new(tree);
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
RegexAstNode node = enumerator.Current;
|
||||
Console.Write(new string('|', enumerator.Depth));
|
||||
Console.WriteLine($"\t{node.Value}\t{node.Source.Flag}");
|
||||
}
|
||||
Console.WriteLine(interpreterSource.AnalyseException?.ToString() ?? "No error");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"(a{2,4}bc)d", RegexOptions.ExplicitCapture)]
|
||||
internal static partial Regex GetRegex();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// file="TestRegexGenerate"
|
||||
// Project: StgSharp
|
||||
// Copyright (c) Nitload.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using Nitload.RegularAnalysis.Abstraction;
|
||||
using Nitload.RegularAnalysis.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using static Nitload.RegularAnalysis.Text.TextRegexSourceGen;
|
||||
|
||||
namespace Nitload
|
||||
{
|
||||
internal static class TestRegexGenerate
|
||||
{
|
||||
|
||||
public static int Run(
|
||||
string arg
|
||||
)
|
||||
{
|
||||
Console.WriteLine($"Text regex to be tested: {arg} :\n\n\n");
|
||||
Print(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void Print(
|
||||
string pattern
|
||||
)
|
||||
{
|
||||
TextRegexSource analysis = RegexAnalyzer.Analyze(pattern);
|
||||
if (analysis.AnalyseException is not null) {
|
||||
ExceptionDispatchInfo.Throw(analysis.AnalyseException);
|
||||
}
|
||||
|
||||
SequenceEmitter<string> body = new();
|
||||
List<SequenceEmitter<string>> functions = [];
|
||||
SourceGenContext context = new();
|
||||
ExitLabel local_fail = context.RequestExitLabel(ExitKind.MatchFailed);
|
||||
ExitLabel backtrack = local_fail;
|
||||
ExitLabel end = context.RequestExitLabel(ExitKind.MatchEnd);
|
||||
GenerateMethodSource(analysis.Ast.Root, body, functions, context, local_fail, ref backtrack);
|
||||
_ = body.AppendLine($"goto {end.GetLabelName()};")
|
||||
.AppendLine($"{local_fail.GetLabelName()}: {{}}")
|
||||
.AppendLine("// TODO(NGRA): Produce the root failure result here.")
|
||||
.AppendLine($"{end.GetLabelName()}: {{}}");
|
||||
|
||||
foreach (string line in body.ToList()) {
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
foreach (SequenceEmitter<string> function in functions)
|
||||
{
|
||||
foreach (string line in function.ToList()) {
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user