mainly theoratical work

This commit is contained in:
Youmu Liu
2026-07-21 18:02:46 +08:00
parent a698c47a1c
commit c82a758d97
4 changed files with 162 additions and 22 deletions
@@ -64,10 +64,25 @@ namespace StgSharp.RegularAnalysis.Text
if (scan_win[0] is not RegexFindSeqIR find) {
return -1;
}
const string cur_ptr = "cur_ptr",
begin_ptr = "begin_ptr";
_ = main_emitter.AppendLine()
.AppendLine(@$"//Find sequence:{FormatStringLiteral(find.Pattern)} at any pos")
.AppendLine(@"do")
.AppendLine(@"{");
.AppendLine(@"{")
.AppendLine(@$"int {cur_ptr}, {begin_ptr} = {current_ptr};")
.AppendLine();
string finder = find.IsFirst ? "FirstIndexOf" : "LastIndexOf";
if (scan_win[1] is RegexMatchSeqIR seq)
{
string seq_pat = FormatStringLiteral(seq.Pattern);
_ = main_emitter.AppendLine(@$"//Match sequence:{seq_pat} at current pos")
.AppendLine(string.Empty());
}
_ = main_emitter.AppendLine("}").AppendLine(string.Empty);
return 1;
}
@@ -24,7 +24,7 @@ namespace StgSharp.RegularAnalysis.Text
internal partial class TextRegexSourceGen
{
private const string current_ptr = "current_ptr";
private const string current_ptr = "cur_ptr_global";
private const string offset = "offset";
private const string orig_text = "text";
@@ -39,12 +39,10 @@ namespace StgSharp.RegularAnalysis.Text
RegexInfo info = source.Info;
List<RegexIR> ir = source.IRs;
ReadOnlySpan<RegexIR> ir_sp = CollectionsMarshal.AsSpan(ir);
RegexIR[] window = new RegexIR[8];
Span<RegexIR> scan_win = window;
SequenceEmitter<string> match_e = new();
int index = 0;
int end = FindRrgionEnd(ir_sp, index);
int end = FindRegionEnd(ir_sp, index);
ReadOnlySpan<RegexIR> region = ir_sp[0..end];
while (true)
@@ -55,7 +53,7 @@ namespace StgSharp.RegularAnalysis.Text
break;
}
index = end;
end = FindRrgionEnd(ir_sp, end);
end = FindRegionEnd(ir_sp, end);
region = ir_sp[index..end];
}
@@ -90,7 +88,7 @@ namespace StgSharp.RegularAnalysis.Text
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int FindRrgionEnd(
private static int FindRegionEnd(
ReadOnlySpan<RegexIR> ir_sp,
int current
)
@@ -32,8 +32,14 @@ namespace StgSharp.RegularAnalysis.Text
private const string __remain_cur = "__remain_cur";
private const string __find_result = "__find_result";
private readonly Dictionary<string, int> _search_value_name = [];
private int _min_search_value_index;
private int _min_region_begin_index;
public string MakeNewRegionBegin()
{
string name = $"__region_begin_{_min_region_begin_index}";
_min_region_begin_index++;
return name;
}
public string CurChar
{
@@ -44,19 +50,6 @@ namespace StgSharp.RegularAnalysis.Text
}
}
public int MakeNewSearchValue(
string seq
)
{
if (_search_value_name.TryGetValue(seq, out int idx)) {
return idx;
}
idx = _min_search_value_index;
_min_search_value_index++;
_search_value_name.Add(seq, idx);
return idx;
}
public string FindResult
{
get