maxoncheeg.FiniteStateMachine
0.3.0
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package maxoncheeg.FiniteStateMachine --version 0.3.0
NuGet\Install-Package maxoncheeg.FiniteStateMachine -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="maxoncheeg.FiniteStateMachine" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="maxoncheeg.FiniteStateMachine" Version="0.3.0" />
<PackageReference Include="maxoncheeg.FiniteStateMachine" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add maxoncheeg.FiniteStateMachine --version 0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: maxoncheeg.FiniteStateMachine, 0.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package maxoncheeg.FiniteStateMachine@0.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=maxoncheeg.FiniteStateMachine&version=0.3.0
#tool nuget:?package=maxoncheeg.FiniteStateMachine&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FiniteStateMachine
Example:
For example create our own custom state machine.
From state A to state B you can move by words: setsomany, set.
Also you can move from state A to C by 'setso'.
From C to D by ' '.
From D to F by 'man'.
From F to G by ' '.
From G to B by 'x'.
From state B to E you can move by '.' and it's our finale state.
It means that we have only three right lines of code: 'setsomany.', 'set.', 'setso man x.'.
In code it looks like:
List<IRoute> states =
[
new StringRoute(@"setsomany", "A", "B")
{
Priority = 0, ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.RollBack }
},
new StringRoute(@"setso", "A", "C")
{
Priority = 1, ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.RollBack }
},
new StringRoute(@" ", "C", "D")
{
ErrorMessage = "missing space",
ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.SkipState }
},
new StringRoute(@"man", "D", "F"),
new StringRoute(@" ", "F", "G")
{
ErrorMessage = "missing space",
ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.SkipState }
},
new StringRoute(@"x", "G", "B"),
new StringRoute(@"set", "A", "B")
{
ErrorMessage = "unsupported key word",
Priority = 2
},
new StringRoute(@".", "B", "E")
{
ErrorMessage = "unsupported keys",
ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.Skip }
},
new StringRoute(@",", "B", "E")
{
ErrorMessage = "unsupported keys",
ErrorOptions = new RouteErrorOptions { Action = RouteErrorAction.Skip }
},
];
_stateMachine = new FiniteStateMachine(states, "A", "E");
With this configuration let's try this string: 'setsomanx.'.
var input= "setsomanx.";
Console.WriteLine($"INPUT: {input}\n");
_stateMachine.StateChanged += (sender, args) =>
{
if (args.IsFinalState && args.StartIndex == 0 && args.Length == input.Length)
Console.WriteLine($"\nFOUND: {args.Result}");
};
_stateMachine.ErrorOccurred += (sender, args) =>
{
Console.WriteLine(
$"(pos {args.Error.Position}): {args.Error.Text}");
};
for (int i = 0; i < input.Length; i++)
{
_stateMachine.PutChar(input[i], i);
}
In output we have:
INPUT: setsomanx.
(pos 0): missing space
(pos 3): missing space
FOUND: setsomanx.
Happy using!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.4.1-notforuse | 208 | 4/18/2025 |
| 0.4.0-notforuse | 206 | 4/18/2025 |
| 0.3.0 | 263 | 4/17/2025 |
| 0.2.0 | 249 | 4/14/2025 |
| 0.1.2 | 194 | 4/12/2025 |
| 0.1.1 | 236 | 4/10/2025 |
| 0.1.0 | 230 | 4/9/2025 |
New features