TKN 1.0.0

dotnet add package TKN --version 1.0.0
                    
NuGet\Install-Package TKN -Version 1.0.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="TKN" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TKN" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TKN" />
                    
Project file
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 TKN --version 1.0.0
                    
#r "nuget: TKN, 1.0.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 TKN@1.0.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=TKN&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TKN&version=1.0.0
                    
Install as a Cake Tool

TKN is a package to create advanced tokenizers.

Creating tokenizer

Creating tokenizer from TKN scheme

Tokenizer tokenizer = new Tokenizer(@"- token ------------
                                      MYTOKEN     | [A-Z]+
                                      SECONDTOKEN | [0-9]+
                                      THIRDTOKEN  | [A-Z_]+
                                      - group ------------------------
                                      MYGROUP | MYTOKEN (SECONDTOKEN)*");

Creating tokenizer manually

Tokenizer tokenizer = new Tokenizer();
tokenizer.Register(new TokenType("MYTOKEN", "[A-Z]+"));
tokenizer.Register(new TokenType("SECONDTOKEN", "[0-9]+"));
tokenizer.Register(new TokenGroupType("MYGROUP", new Tknex("MYTOKEN (SECONDTOKEN)*")));

Using tokenizer

string source = "HELLO 12 24 GULGDEVS TKN 12345678 THIS_IS_NOT_IN_GROUP";
TKNElementCollection elements = tokenizer.Tokenize(source);

TKN element collection

foreach (TKNElement element in elements)
{
    if (element is Token)
    {
        Token token = (Token)element;
        switch (token.Type.Name)
        {
            case "MYTOKEN":
                // Do something with token
                break;
        }
    }
    else if (element is TokenGroup)
    {
        TokenGroup group = (TokenGroup)element;
        switch (group.Type.Name)
        {
            case "MYGROUP":
                foreach (TKNElement child in group.Elements)
                {
                    // Do something with child element
                }
                break;
        }
    }
}

Console.WriteLine(elements);
/* The result is:
TKNElementCollection: {
    MYGROUP: {
        MYTOKEN: HELLO,
        SECONDTOKEN: 12,
        SECONDTOKEN: 24
    },
    MYGROUP: {
        MYTOKEN: GULGDEVS
    },
    MYGROUP: {
        MYTOKEN: TKN,
        SECONDTOKEN: 12345678
    },
    THIRDTOKEN: THIS_IS_NOT_IN_GROUP
}*/
Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 291 7/22/2022

Released