use rule table instead a single jump funcfor state machine
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ISimpleStateMachine"
|
// file="ISimpleStateMachine"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
@@ -28,24 +28,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.State
|
namespace StgSharp.State
|
||||||
{
|
{
|
||||||
public interface ISimpleStateMachine<TStateNode, TStateLabel, TStateContext>
|
public interface ISimpleStateMachine<TStateNode, TStateLabel, TStateContext>
|
||||||
where TStateNode: ISimpleStateMachineNode<TStateLabel, TStateContext>
|
where TStateNode : ISimpleStateMachineNode<TStateLabel, TStateContext>
|
||||||
where TStateLabel: unmanaged, Enum
|
where TStateLabel : unmanaged, IEquatable<TStateLabel>
|
||||||
where TStateContext: StateContext
|
where TStateContext : StateContext
|
||||||
{
|
{
|
||||||
|
|
||||||
ref readonly TStateNode this[TStateLabel label] { get; }
|
ref readonly TStateNode this[
|
||||||
|
TStateLabel label
|
||||||
|
] { get; }
|
||||||
|
|
||||||
ref readonly TStateNode GetCurrentStateNode();
|
ref readonly TStateNode GetCurrentStateNode();
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
bool TryMoveNext(TStateContext ctx);
|
bool TryMoveNext(
|
||||||
|
TStateContext ctx
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="ISimpleStateMachineNode"
|
// file="ISimpleStateMachineNode"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -28,18 +28,28 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace StgSharp.State
|
namespace StgSharp.State
|
||||||
{
|
{
|
||||||
public interface ISimpleStateMachineNode<TLabel, TStateContext> where TLabel: unmanaged, Enum
|
public abstract class SimpleStateMachineNode<TLabel, TStateContext>
|
||||||
where TStateContext: StateContext
|
where TLabel : unmanaged, IEquatable<TLabel>
|
||||||
|
where TStateContext : StateContext
|
||||||
{
|
{
|
||||||
|
|
||||||
public ICollection<TLabel> AvailableStateLabels { get; }
|
private List<Func<SimpleStateMachineNode<TLabel, TStateContext>, SimpleStateMachineNode<TLabel, TStateContext>, TStateContext, bool>>
|
||||||
|
_jumpRule;
|
||||||
|
private List<(int, SimpleStateMachineNode<TLabel, TStateContext>)> _jumpTable;
|
||||||
|
|
||||||
bool TryGetNextStateLabel(TLabel label, TStateContext context, out TLabel nextLabel);
|
public IReadOnlyCollection<(int, SimpleStateMachineNode<TLabel, TStateContext>)>
|
||||||
|
AvailableNodes => _jumpTable;
|
||||||
|
|
||||||
|
public abstract bool TryTransaction(
|
||||||
|
TStateContext context,
|
||||||
|
out TLabel label
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="RegularExpression.StateMachine"
|
// file="RegularExpression.StateMachine"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -41,9 +41,49 @@ namespace StgSharp.RegularAnalysis
|
|||||||
|
|
||||||
private readonly RegularExpressionState _state;
|
private readonly RegularExpressionState _state;
|
||||||
|
|
||||||
private class RegularExpressionState : ISimpleStateMachine<, RegularExpressionCases, RegularExpressionStateContext> { }
|
private class RegularExpressionState : ISimpleStateMachine<RegularExpressionStateNode, int, RegularExpressionStateContext>
|
||||||
|
{
|
||||||
|
|
||||||
private enum RegularExpressionCases { }
|
public ref readonly RegularExpressionStateNode this[
|
||||||
|
int label
|
||||||
|
] => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public ref readonly RegularExpressionStateNode GetCurrentStateNode()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryMoveNext(
|
||||||
|
RegularExpressionStateContext ctx
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct RegularExpressionStateNode : ISimpleStateMachineNode<int, RegularExpressionStateContext>
|
||||||
|
{
|
||||||
|
|
||||||
|
public ICollection<int> AvailableStateLabels => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public SimpleStateMachineNodeTransition<int, RegularExpressionStateContext>
|
||||||
|
Transition => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public bool TryTransaction(
|
||||||
|
RegularExpressionStateContext context,
|
||||||
|
out int label
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class RegularExpressionStateContext : StateContext
|
private class RegularExpressionStateContext : StateContext
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user