add a scanner, but this seems to be a wrong solution. Change open-source head

This commit is contained in:
Youmu Liu
2026-07-07 18:20:38 +08:00
parent b053567eb7
commit 1705d7c245
276 changed files with 3468 additions and 7205 deletions
+19 -102
View File
@@ -1,30 +1,10 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------------
// file="RegexIR"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
@@ -53,37 +33,14 @@ namespace StgSharp.RegularAnalysis.Text
Match = Match_Seq | Match_Set,
Count = Count_Seq | Count_Set | Count_Complex,
}
internal interface IRegexComplex
{
bool IsFullyOptimized { get; set; }
int CommandCount { get; set; }
}
internal interface IRegexCount
{
bool IsGreedy { get; }
bool IsStar { get; }
bool IsPlus { get; }
int Min { get; }
int Max { get; }
Find = Find_Seq | Find_Set | Find_Complex,
}
internal sealed class RegexFindComplexIR(
bool nearest,
int count
) : RegexIR, IRegexComplex
) : RegexIR(RegexIRCommand.Find_Complex), IRegexComplex
{
public bool IsFullyOptimized { get; set; }
@@ -92,8 +49,6 @@ namespace StgSharp.RegularAnalysis.Text
public int CommandCount { get; set; } = count;
internal override RegexIRCommand Command => RegexIRCommand.Find_Complex;
protected override string AsCommand(
)
@@ -103,36 +58,16 @@ namespace StgSharp.RegularAnalysis.Text
}
internal abstract class RegexIR
{
public RegexIRPrefix Prefix { get; set; }
internal abstract RegexIRCommand Command { get; }
internal string AsCommand(
int lineNum
)
{
return $"[{lineNum}]\t{Prefix}\t{AsCommand()}";
}
protected abstract string AsCommand();
}
internal sealed class RegexFindSeqIR(
string pattern,
bool isFirst
) : RegexIR
) : RegexIR(RegexIRCommand.Find_Seq), IRegexSequence
{
public bool IsFirst { get; } = isFirst;
public string Pattern { get; } = pattern;
internal override RegexIRCommand Command => RegexIRCommand.Find_Seq;
protected override string AsCommand(
)
{
@@ -146,13 +81,11 @@ namespace StgSharp.RegularAnalysis.Text
/// </summary>
internal sealed class RegexMatchSeqIR(
string pattern
) : RegexIR
) : RegexIR(RegexIRCommand.Match_Seq), IRegexSequence
{
public string Pattern { get; } = pattern;
internal override RegexIRCommand Command => RegexIRCommand.Match_Seq;
protected override string AsCommand(
)
@@ -164,13 +97,11 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexMatchSetIR(
string charset
) : RegexIR
) : RegexIR(RegexIRCommand.Match_Set)
{
public string Charset { get; } = charset;
internal override RegexIRCommand Command => RegexIRCommand.Match_Set;
protected override string AsCommand(
)
@@ -183,15 +114,13 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexConditionIR(
int success,
int fail
) : RegexIR
) : RegexIR(RegexIRCommand.Condition)
{
public int SuccessCase { get; } = success;
public int FailCase { get; } = fail;
internal override RegexIRCommand Command => RegexIRCommand.Condition;
protected override string AsCommand(
)
@@ -204,15 +133,13 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexPackIR(
bool condition,
string name = ""
) : RegexIR
) : RegexIR(RegexIRCommand.Pack)
{
public bool Condition { get; } = condition;
public string GroupName { get; } = name;
internal override RegexIRCommand Command => RegexIRCommand.Pack;
protected override string AsCommand(
)
@@ -227,7 +154,7 @@ namespace StgSharp.RegularAnalysis.Text
int max,
bool isGreedy,
int operation
) : RegexIR, IRegexCount, IRegexComplex
) : RegexIR(RegexIRCommand.Count_Complex), IRegexCount, IRegexComplex
{
public bool IsGreedy { get; } = isGreedy;
@@ -244,8 +171,6 @@ namespace StgSharp.RegularAnalysis.Text
public int CommandCount { get; set; } = operation;
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Complex;
protected override string AsCommand(
)
@@ -260,7 +185,7 @@ namespace StgSharp.RegularAnalysis.Text
int max,
bool isGreedy,
string seq
) : RegexIR, IRegexCount
) : RegexIR(RegexIRCommand.Count_Seq), IRegexCount, IRegexSequence
{
public bool IsGreedy { get; } = isGreedy;
@@ -273,15 +198,13 @@ namespace StgSharp.RegularAnalysis.Text
public int Max { get; } = max;
public string Sequence { get; } = seq.Length == 2 && seq[0] == '\\' ? seq[1..2] : seq;
internal override RegexIRCommand Command { get; } = RegexIRCommand.Count_Seq;
public string Pattern { get; } = seq.Length == 2 && seq[0] == '\\' ? seq[1..2] : seq;
protected override string AsCommand(
)
{
return $"COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Sequence}\"";
return $"COUNT_SEQ {(IsGreedy ? "GREEDY" : "NON_GREEDY")} MIN: {Min} MAX: {Max} SEQ: \"{Pattern}\"";
}
}
@@ -291,7 +214,7 @@ namespace StgSharp.RegularAnalysis.Text
int max,
bool isGreedy,
string set
) : RegexIR, IRegexCount
) : RegexIR(RegexIRCommand.Count_Set), IRegexCount
{
public bool IsGreedy { get; } = isGreedy;
@@ -308,8 +231,6 @@ namespace StgSharp.RegularAnalysis.Text
public string CharSet { get; } = set;
internal override RegexIRCommand Command => RegexIRCommand.Count_Set;
protected override string AsCommand(
)
@@ -321,15 +242,13 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexTryIR(
int count
) : RegexIR, IRegexComplex
) : RegexIR(RegexIRCommand.Try), IRegexComplex
{
public bool IsFullyOptimized { get; set; }
public int CommandCount { get; set; } = count;
internal override RegexIRCommand Command => RegexIRCommand.Try;
protected override string AsCommand(
)
@@ -341,13 +260,11 @@ namespace StgSharp.RegularAnalysis.Text
internal sealed class RegexPopIR(
bool isSuccess
) : RegexIR
) : RegexIR(RegexIRCommand.Pop)
{
public bool IsSuccess { get; } = isSuccess;
internal override RegexIRCommand Command => RegexIRCommand.Pop;
protected override string AsCommand(
)