57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
// -----------------------------------------------------------------------------
|
|
// 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 exit = context.RequestExitLabel(ExitMode.Goto);
|
|
GenerateMethodSource(analysis.Ast.Root, body, functions, context, exit);
|
|
|
|
foreach (string line in body.ToList()) {
|
|
Console.WriteLine(line);
|
|
}
|
|
foreach (SequenceEmitter<string> function in functions)
|
|
{
|
|
foreach (string line in function.ToList()) {
|
|
Console.WriteLine(line);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|