regex ir opt code on rewrite
This commit is contained in:
@@ -37,16 +37,34 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
internal enum RegexIRCommand
|
||||
{
|
||||
|
||||
Match_Seq = 0,
|
||||
Match_Set = 1,
|
||||
Condition = 3,
|
||||
Try = 4,
|
||||
Count = 5,
|
||||
Count_Seq = 6,
|
||||
Count_Set = 7,
|
||||
Pop = 8,
|
||||
Pack = 9,
|
||||
Find_Seq = 10,
|
||||
Match_Seq = 1 << 0,
|
||||
Match_Set = 1 << 1,
|
||||
Condition = 1 << 2,
|
||||
Try = 1 << 3,
|
||||
Count_Complex = 1 << 4,
|
||||
Count_Seq = 1 << 5,
|
||||
Count_Set = 1 << 6,
|
||||
Pop = 1 << 7,
|
||||
Pack = 1 << 8,
|
||||
Find_Seq = 1 << 9,
|
||||
|
||||
Match = Match_Seq | Match_Set,
|
||||
Count = Count_Seq | Count_Set | Count_Complex,
|
||||
|
||||
}
|
||||
|
||||
internal interface IRegexCount
|
||||
{
|
||||
|
||||
bool IsGreedy { get; }
|
||||
|
||||
bool IsStar { get; }
|
||||
|
||||
bool IsPlus { get; }
|
||||
|
||||
int Min { get; }
|
||||
|
||||
int Max { get; }
|
||||
|
||||
}
|
||||
|
||||
@@ -163,29 +181,33 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
}
|
||||
|
||||
internal sealed class RegexCountIR(
|
||||
internal sealed class RegexCountComplexIR(
|
||||
int min,
|
||||
int max,
|
||||
bool isGreedy,
|
||||
int operation
|
||||
) : RegexIR
|
||||
) : RegexIR, IRegexCount
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
|
||||
public bool IsStar => Min == 0 && Max < 0;
|
||||
|
||||
public bool IsPlus => Min == 1 && Max < 0;
|
||||
|
||||
public int Min { get; } = min;
|
||||
|
||||
public int Max { get; } = max;
|
||||
|
||||
public int OperationIndex { get; } = operation;
|
||||
public int OperationCount { get; } = operation;
|
||||
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count;
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex;
|
||||
|
||||
internal override string AsCommand(
|
||||
int lineNum
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {OperationIndex}";
|
||||
return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {OperationCount}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -195,11 +217,15 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int max,
|
||||
bool isGreedy,
|
||||
string seq
|
||||
) : RegexIR
|
||||
) : RegexIR, IRegexCount
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
|
||||
public bool IsStar => Min == 0 && Max < 0;
|
||||
|
||||
public bool IsPlus => Min == 1 && Max < 0;
|
||||
|
||||
public int Min { get; } = min;
|
||||
|
||||
public int Max { get; } = max;
|
||||
@@ -222,11 +248,17 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
int max,
|
||||
bool isGreedy,
|
||||
string set
|
||||
) : RegexIR
|
||||
) : RegexIR, IRegexCount
|
||||
{
|
||||
|
||||
public bool IsGreedy { get; } = isGreedy;
|
||||
|
||||
public bool IsDotStar => CharSet == "." && Min == 0 && Max < 0;
|
||||
|
||||
public bool IsStar => Min == 0 && Max < 0;
|
||||
|
||||
public bool IsPlus => Min == 1 && Max < 0;
|
||||
|
||||
public int Min { get; } = min;
|
||||
|
||||
public int Max { get; } = max;
|
||||
|
||||
Reference in New Issue
Block a user