60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
// -----------------------------------------------------------------------------
|
|
// 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(@"123.*\w123", RegexOptions.ExplicitCapture)]
|
|
internal static partial Regex GetRegex();
|
|
|
|
}
|
|
}
|