add state nodes for regex state machine

This commit is contained in:
Youmu Liu
2026-01-27 18:40:44 +08:00
parent a36e6cbab4
commit 3881078770
13 changed files with 510 additions and 820 deletions
+5 -5
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="ISimpleStateMachine"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
// 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
@@ -35,13 +35,13 @@ using System.Threading.Tasks;
namespace StgSharp.State
{
public interface ISimpleStateMachine<TStateNode, TStateLabel, TStateContext>
where TStateNode : ISimpleStateMachineNode<TStateLabel, TStateContext>
where TStateNode : SimpleStateMachineNode<TStateNode, TStateLabel, TStateContext>
where TStateLabel : unmanaged, IEquatable<TStateLabel>
where TStateContext : StateContext
{
ref readonly TStateNode this[
TStateLabel label
TStateNode this[
TStateLabel label
] { get; }
ref readonly TStateNode GetCurrentStateNode();
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="ISimpleStateMachineNode"
// file="SimpleStateMachineNode"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
@@ -29,24 +29,29 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.State
{
public abstract class SimpleStateMachineNode<TLabel, TStateContext>
public abstract class SimpleStateMachineNode<TSelf, TLabel, TStateContext>
where TSelf : SimpleStateMachineNode<TSelf, TLabel, TStateContext>
where TLabel : unmanaged, IEquatable<TLabel>
where TStateContext : StateContext
{
private List<Func<SimpleStateMachineNode<TLabel, TStateContext>, SimpleStateMachineNode<TLabel, TStateContext>, TStateContext, bool>>
_jumpRule;
private List<(int, SimpleStateMachineNode<TLabel, TStateContext>)> _jumpTable;
private readonly List<int> _jumpTable = [];
public IReadOnlyCollection<(int, SimpleStateMachineNode<TLabel, TStateContext>)>
AvailableNodes => _jumpTable;
public ReadOnlySpan<int> AvailableNodes => CollectionsMarshal.AsSpan(_jumpTable);
public abstract bool IsValidateFrom(
TSelf former,
TStateContext context
);
public abstract bool TryTransaction(
ReadOnlySpan<TSelf> nodeSpan,
TStateContext context,
out TLabel label
);