prefix replaces CONDITION
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -55,19 +56,6 @@ 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
|
||||
{
|
||||
|
||||
@@ -92,7 +80,10 @@ 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; }
|
||||
@@ -103,9 +94,11 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Find_Complex;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t FIND_COMPLEX {(IsNearest ? "NEAREST" : "FURTHEST")} COUNT: {CommandCount}";
|
||||
return $"FIND_COMPLEX {(IsNearest ? "NEAREST" : "FURTHEST")} COUNT: {CommandCount}";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -113,13 +106,25 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
internal abstract class RegexIR
|
||||
{
|
||||
|
||||
public RegexIRPrefix Prefix { get; set; }
|
||||
|
||||
internal abstract RegexIRCommand Command { get; }
|
||||
|
||||
internal abstract string AsCommand(int lineNum);
|
||||
internal string AsCommand(
|
||||
int lineNum
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t{Prefix}\t{AsCommand()}";
|
||||
}
|
||||
|
||||
protected abstract string AsCommand();
|
||||
|
||||
}
|
||||
|
||||
internal sealed class RegexFindSeqIR(string pattern, bool isFirst) : RegexIR
|
||||
internal sealed class RegexFindSeqIR(
|
||||
string pattern,
|
||||
bool isFirst
|
||||
) : RegexIR
|
||||
{
|
||||
|
||||
public bool IsFirst { get; } = isFirst;
|
||||
@@ -128,9 +133,10 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Find_Seq;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t FIND_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "<EPSILON>" : Pattern)}\"";
|
||||
return $"FIND_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "<EPSILON>" : Pattern)}\"";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -138,35 +144,46 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
/// <summary>
|
||||
/// Searches for a certain string pattern or charset from current position.
|
||||
/// </summary>
|
||||
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)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t MATCH_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "<EPSILON>" : Pattern)}\"";
|
||||
return $"MATCH_SEQ \"{(string.IsNullOrEmpty(Pattern) ? "<EPSILON>" : 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)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t MATCH_SET \"{Charset}\"";
|
||||
return $"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;
|
||||
@@ -175,14 +192,19 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Condition;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t CONDITION SUCCESS: {SuccessCase} FAIL: {FailCase}";
|
||||
return $"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;
|
||||
@@ -191,14 +213,21 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Pack;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t PACK {(Condition ? "SUCCESS" : "FAIL")} GROUP: \"{GroupName}\"";
|
||||
return $"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;
|
||||
@@ -217,14 +246,21 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t COUNT {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} OPERATION: {CommandCount}";
|
||||
return $"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;
|
||||
@@ -241,14 +277,21 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Seq;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Sequence}\"";
|
||||
return $"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;
|
||||
@@ -267,14 +310,18 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Count_Set;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t COUNT_SET {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SET: \"{CharSet}\"";
|
||||
return $"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; }
|
||||
@@ -283,23 +330,29 @@ namespace StgSharp.RegularAnalysis.Text
|
||||
|
||||
internal override RegexIRCommand Command => RegexIRCommand.Try;
|
||||
|
||||
internal override string AsCommand(int lineNum)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t TRY {CommandCount}";
|
||||
return $"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)
|
||||
protected override string AsCommand(
|
||||
|
||||
)
|
||||
{
|
||||
return $"[{lineNum}]\t POP {(IsSuccess ? "SUCCESS" : "FAIL")}";
|
||||
return $"POP {(IsSuccess ? "SUCCESS" : "FAIL")}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user