mainly theoratical work on semi, add regex sample

This commit is contained in:
Youmu Liu
2026-07-22 18:17:10 +08:00
parent c82a758d97
commit c1a8b39502
2 changed files with 58 additions and 3 deletions
@@ -71,15 +71,15 @@ namespace StgSharp.RegularAnalysis.Text
.AppendLine(@"do") .AppendLine(@"do")
.AppendLine(@"{") .AppendLine(@"{")
.AppendLine(@$"int {cur_ptr}, {begin_ptr} = {current_ptr};") .AppendLine(@$"int {cur_ptr}, {begin_ptr} = {current_ptr};")
.AppendLine(); .AppendLine($@"{ROS_char} rest = ");
string finder = find.IsFirst ? "FirstIndexOf" : "LastIndexOf"; string finder = find.IsFirst ? "FirstIndexOf" : "LastIndexOf";
if (scan_win[1] is RegexMatchSeqIR seq) if (scan_win[1] is RegexMatchSeqIR seq)
{ {
string seq_pat = FormatStringLiteral(seq.Pattern); string seq_pat = FormatStringLiteral(find.Pattern + seq.Pattern);
_ = main_emitter.AppendLine(@$"//Match sequence:{seq_pat} at current pos") _ = main_emitter.AppendLine(@$"//Match sequence:{seq_pat} at current pos")
.AppendLine(string.Empty()); .AppendLine($@"if( )");
} }
_ = main_emitter.AppendLine("}").AppendLine(string.Empty); _ = main_emitter.AppendLine("}").AppendLine(string.Empty);
+55
View File
@@ -0,0 +1,55 @@
using System;
//abc
static void Match_ABC(ReadOnlySpan<char> input)
{
int ptr = 0;
int region_start = ptr;
int region_end = region_start;
const string pattern = @"abc";
if(input[0..3].SequenceEqual(pattern))
{
ptr += 3;
region_end = ptr;
}
}
//a[abc]d
static void Match_A_charset_ABC_C(ReadOnlySpan<char> input)
{
int ptr = 0;
int region_start = ptr;
int region_end = region_start;
if(input[0] == 'a' && (input[1] == 'a' || input[1] == 'b' || input[1] == 'c') && input[2] == 'd')
{
ptr += 3;
region_end = ptr;
}
}
//[abc]
static void Match_charset_ABC(ReadOnlySpan<char> input)
{
int ptr = 0;
int region_start = ptr;
int region_end = region_start;
if(input[0] == 'a' || input[0] == 'b' || input[0] == 'c')
{
ptr += 1;
region_end = ptr;
}
}
//.
static void Match_Dot(ReadOnlySpan<char> input)
{
int ptr = 0;
int region_start = ptr;
int region_end = region_start;
ptr += 1;
region_end = ptr;
}