Files
stgsharp/StgSharp.RegularAnalysis/TextRegex/RegexIR.cs
T
2026-06-16 21:04:51 +08:00

228 lines
5.7 KiB
C#

//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// 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.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex
{
internal enum RegexIRCommand
{
Search = 0,
Jump = 1,
Condition = 2,
Count = 3,
Try = 4,
Pop = 5,
}
internal abstract class RegexIR
{
internal abstract RegexIRCommand Command { get; }
public static RegexIR Condition(
int success,
int fail
)
{
return new RegexConditionIR(success, fail);
}
public static RegexIR PopLevel(
bool isSuccess
)
{
return new RegexPopIR(isSuccess);
}
public static RegexIR Try(
int count
)
{
return new RegexTryIR(count);
}
internal abstract void Execute();
}
internal sealed class RegexPopIR(
bool isSuccess
) : RegexIR
{
public bool IsSuccess { get; } = isSuccess;
internal override RegexIRCommand Command => RegexIRCommand.Pop;
internal override void Execute()
{
throw new NotImplementedException();
}
}
/// <summary>
/// Searches for a certain string pattern or charset from current position.
/// </summary>
internal sealed class RegexSearchStringIR(
string pattern
) : RegexIR
{
public string Pattern { get; } = pattern;
internal override RegexIRCommand Command => RegexIRCommand.Search;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexSearchCharsetIR(
string charset
) : RegexIR
{
public string Charset { get; } = charset;
internal override RegexIRCommand Command => RegexIRCommand.Search;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexSearchCharSetIR(
string c
) : RegexIR
{
public string Target { get; } = c;
internal override RegexIRCommand Command => RegexIRCommand.Search;
internal override void Execute()
{
throw new NotImplementedException();
}
}
/// <summary>
/// JUMP to a certain instruction index.
/// </summary>
/// <param name="target">
///
/// </param>
internal sealed class RegexJumpIR(
int target
) : RegexIR
{
public int TargetIndex { get; } = target;
internal override RegexIRCommand Command => RegexIRCommand.Jump;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexConditionIR(
int success,
int fail
) : RegexIR
{
public int SuccessCase { get; } = success;
public int FailCase { get; } = fail;
internal override RegexIRCommand Command => RegexIRCommand.Condition;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexCountIR(
int min,
int max,
bool isGreedy,
int operation
) : RegexIR
{
public bool IsGreedy { get; } = isGreedy;
public int Min { get; } = min;
public int Max { get; } = max;
public int OperationIndex { get; } = operation;
internal override RegexIRCommand Command => throw new NotImplementedException();
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexTryIR(
int count
) : RegexIR
{
public int CountOfCommand { get; } = count;
internal override RegexIRCommand Command => RegexIRCommand.Try;
internal override void Execute()
{
throw new NotImplementedException();
}
}
}