Optimizer is almost ok. Will go on source generate

This commit is contained in:
Youmu Liu
2026-02-13 18:36:59 +08:00
parent 6c78373375
commit 27add7c6e8
5 changed files with 163 additions and 53 deletions
+20 -7
View File
@@ -38,16 +38,29 @@ namespace StgSharp
public class TestRegexAnalyse
{
private const string regex = @"abc|abd|abe|abf";
private static string[] regexSource = [
@"http|https",
@"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"
];
public static void Run()
{
RegexInterpreter interpreter = RegexInterpreter.Analyze(regex);
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree = interpreter.Tree;
Console.WriteLine();
Console.WriteLine();
foreach (RegexAstNode node in tree) {
Console.WriteLine($"{node.Source.Value}\t{node.Source.Flag}");
foreach (string regex in regexSource)
{
RegexInterpreter interpreter = RegexInterpreter.Analyze(regex);
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree = interpreter.Tree;
Console.WriteLine($"result of \"{regex}\"");
TreeEnumerator<RegexAstNode, RegexElementLabel> enumerator = new TreeEnumerator<RegexAstNode, RegexElementLabel>(tree);
while (enumerator.MoveNext())
{
RegexAstNode node = enumerator.Current;
Console.Write(new string('|', enumerator.Depth));
Console.WriteLine($"\t{node.Source.Value}\t{node.Source.Flag}");
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}
}