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