65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
// -----------------------------------------------------------------------------
|
|
// file="RegexAnalyzer.SourceGen"
|
|
// Project: StgSharp
|
|
// Copyright (c) Nitload.
|
|
// SPDX-License-Identifier: MIT
|
|
// -----------------------------------------------------------------------------
|
|
|
|
using Microsoft.CodeAnalysis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StgSharp.RegularAnalysis.Text
|
|
{
|
|
public partial class RegexAnalyzer
|
|
{
|
|
|
|
internal static StringBuilder GenerateSource(
|
|
List<RegexIR> ir
|
|
)
|
|
{
|
|
StringBuilder sb = new();
|
|
List<StringBuilder> sub_match_list = [];
|
|
|
|
ReadOnlySpan<RegexIR> source = CollectionsMarshal.AsSpan(ir);
|
|
RegexIR[] window = new RegexIR[8];
|
|
Span<RegexIR> scan_win = window;
|
|
|
|
_ = sb.AppendLine(@"public abstract MatchResult Match(ReadOnlySpan<char> text)")//
|
|
.AppendLine(@"{");
|
|
|
|
int index = 0;
|
|
do
|
|
{
|
|
int count = int.Min(8, source.Length - index);
|
|
source.Slice(index, count).CopyTo(scan_win);
|
|
} while (index < ir.Count);
|
|
|
|
foreach (StringBuilder _sub in sub_match_list)
|
|
{
|
|
_ = sb.AppendLine() //
|
|
.Append(_sub);
|
|
}
|
|
|
|
return sb;
|
|
/*
|
|
int TryGenerateMatch(
|
|
Span<RegexIR> scan_win,
|
|
StringBuilder sb
|
|
)
|
|
{
|
|
if (scan_win[0] is RegexMatchSeqIR seq) {
|
|
_ = sb.AppendLine(string.Empty);
|
|
}
|
|
}
|
|
/**/
|
|
}
|
|
|
|
}
|
|
}
|