a few add to source gen
This commit is contained in:
@@ -20,9 +20,7 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
public partial class RegexAnalyzer
|
||||
{
|
||||
|
||||
internal static SequenceEmitter<string> GenerateSource(
|
||||
TextRegexSource source
|
||||
)
|
||||
internal static SequenceEmitter<string> GenerateSource(TextRegexSource source)
|
||||
{
|
||||
SequenceEmitter<string> se = new();
|
||||
List<SequenceEmitter<string>> sub_match_list = [];
|
||||
@@ -33,6 +31,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
RegexIR[] window = new RegexIR[8];
|
||||
Span<RegexIR> scan_win = window;
|
||||
|
||||
const string current_ptr = "current_ptr";
|
||||
|
||||
_ = se.AppendLine(@"public override MatchResult Match(ReadOnlySpan<char> text)")//
|
||||
.AppendLine(@"{");
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
.AppendLine($@"bool region_{i}_success;");
|
||||
}
|
||||
|
||||
_ = se.AppendLine($@"int {current_ptr} = 0;");
|
||||
|
||||
int index = 0;
|
||||
do
|
||||
{
|
||||
@@ -61,15 +63,19 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
return se;
|
||||
/**/
|
||||
int TryGenerateMatch(
|
||||
Span<RegexIR> scan_win,
|
||||
SequenceEmitter<string> sb
|
||||
)
|
||||
int TryGenerateMatch(Span<RegexIR> scan_win, SequenceEmitter<string> sb)
|
||||
{
|
||||
if (scan_win[0] is not RegexMatchSeqIR seq) {
|
||||
return -1;
|
||||
}
|
||||
_ = sb.Append(string.Empty);
|
||||
string pattern = seq.Pattern;
|
||||
int length = pattern.Length;
|
||||
_ = sb.Append(string.Empty)
|
||||
.AppendLine($@"if(text[{current_ptr}..({current_ptr} + {length})] == {pattern})")
|
||||
.AppendLine($@"{{")
|
||||
.AppendLine($@"{current_ptr} += {length};")
|
||||
.AppendLine($@"}}");
|
||||
|
||||
return 1;
|
||||
}
|
||||
/**/
|
||||
@@ -77,3 +83,4 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user