add a scanner, but this seems to be a wrong solution. Change open-source head

This commit is contained in:
Youmu Liu
2026-07-07 18:20:38 +08:00
parent b053567eb7
commit 1705d7c245
276 changed files with 3468 additions and 7205 deletions
@@ -0,0 +1,64 @@
// -----------------------------------------------------------------------------
// 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);
}
}
/**/
}
}
}