diff --git a/StgSharp.RegularAnalysis/Text/RegexIR.cs b/StgSharp.RegularAnalysis/Text/RegexIR.cs index 4bcf2fec..3cf6e270 100644 --- a/StgSharp.RegularAnalysis/Text/RegexIR.cs +++ b/StgSharp.RegularAnalysis/Text/RegexIR.cs @@ -55,6 +55,19 @@ namespace StgSharp.RegularAnalysis.Text } + internal enum RegexIRPrefix + { + + Prev_Success = 1 << 0, + Prev_Fail = 1 << 1, + Always = 1 << 2, + ExeCondition = Prev_Fail | Prev_Success | Always, + Pop_Fail = 1 << 3, + Pop_Success = 1 << 4, + Pop_Condition = Pop_Success | Pop_Fail, + + } + internal interface IRegexComplex { @@ -79,10 +92,7 @@ namespace StgSharp.RegularAnalysis.Text } - internal sealed class RegexFindComplexIR( - bool nearest, - int count - ) : RegexIR, IRegexComplex + internal sealed class RegexFindComplexIR(bool nearest, int count) : RegexIR, IRegexComplex { public bool IsFullyOptimized { get; set; } @@ -93,9 +103,7 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Find_Complex; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t FIND_COMPLEX {(IsNearest ? "NEAREST" : "FURTHEST")} COUNT: {CommandCount}"; } @@ -107,16 +115,11 @@ namespace StgSharp.RegularAnalysis.Text internal abstract RegexIRCommand Command { get; } - internal abstract string AsCommand( - int lineNum - ); + internal abstract string AsCommand(int lineNum); } - internal sealed class RegexFindSeqIR( - string pattern, - bool isFirst - ) : RegexIR + internal sealed class RegexFindSeqIR(string pattern, bool isFirst) : RegexIR { public bool IsFirst { get; } = isFirst; @@ -125,9 +128,7 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Find_Seq; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t FIND_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "" : Pattern)}\""; } @@ -137,46 +138,35 @@ namespace StgSharp.RegularAnalysis.Text /// /// Searches for a certain string pattern or charset from current position. /// - internal sealed class RegexMatchSeqIR( - string pattern - ) : RegexIR + internal sealed class RegexMatchSeqIR(string pattern) : RegexIR { public string Pattern { get; } = pattern; internal override RegexIRCommand Command => RegexIRCommand.Match_Seq; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t MATCH_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "" : Pattern)}\""; } } - internal sealed class RegexMatchSetIR( - string charset - ) : RegexIR + internal sealed class RegexMatchSetIR(string charset) : RegexIR { public string Charset { get; } = charset; internal override RegexIRCommand Command => RegexIRCommand.Match_Set; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t MATCH_SET \"{Charset}\""; } } - internal sealed class RegexConditionIR( - int success, - int fail - ) : RegexIR + internal sealed class RegexConditionIR(int success, int fail) : RegexIR { public int SuccessCase { get; } = success; @@ -185,19 +175,14 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Condition; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t CONDITION SUCCESS: {SuccessCase} FAIL: {FailCase}"; } } - internal sealed class RegexPackIR( - bool condition, - string name = "" - ) : RegexIR + internal sealed class RegexPackIR(bool condition, string name = "") : RegexIR { public bool Condition { get; } = condition; @@ -206,21 +191,14 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Pack; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t PACK {(Condition ? "SUCCESS" : "FAIL")} GROUP: \"{GroupName}\""; } } - internal sealed class RegexCountComplexIR( - int min, - int max, - bool isGreedy, - int operation - ) : RegexIR, IRegexCount, IRegexComplex + internal sealed class RegexCountComplexIR(int min, int max, bool isGreedy, int operation) : RegexIR, IRegexCount, IRegexComplex { public bool IsGreedy { get; } = isGreedy; @@ -239,21 +217,14 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {CommandCount}"; } } - internal sealed class RegexCountSeqIR( - int min, - int max, - bool isGreedy, - string seq - ) : RegexIR, IRegexCount + internal sealed class RegexCountSeqIR(int min, int max, bool isGreedy, string seq) : RegexIR, IRegexCount { public bool IsGreedy { get; } = isGreedy; @@ -270,21 +241,14 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Seq; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Sequence}\""; } } - internal sealed class RegexCountSetIR( - int min, - int max, - bool isGreedy, - string set - ) : RegexIR, IRegexCount + internal sealed class RegexCountSetIR(int min, int max, bool isGreedy, string set) : RegexIR, IRegexCount { public bool IsGreedy { get; } = isGreedy; @@ -303,18 +267,14 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Count_Set; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t COUNT_SET {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SET: \"{CharSet}\""; } } - internal sealed class RegexTryIR( - int count - ) : RegexIR, IRegexComplex + internal sealed class RegexTryIR(int count) : RegexIR, IRegexComplex { public bool IsFullyOptimized { get; set; } @@ -323,27 +283,21 @@ namespace StgSharp.RegularAnalysis.Text internal override RegexIRCommand Command => RegexIRCommand.Try; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t TRY {CommandCount}"; } } - internal sealed class RegexPopIR( - bool isSuccess - ) : RegexIR + internal sealed class RegexPopIR(bool isSuccess) : RegexIR { public bool IsSuccess { get; } = isSuccess; internal override RegexIRCommand Command => RegexIRCommand.Pop; - internal override string AsCommand( - int lineNum - ) + internal override string AsCommand(int lineNum) { return $"[{lineNum}]\t POP {(IsSuccess ? "SUCCESS" : "FAIL")}"; }