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.
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.
// Install TKN as a Cake Addin
#addin nuget:?package=TKN&version=1.0.0

// Install TKN as a Cake Tool
#tool nuget:?package=TKN&version=1.0.0

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 193 7/22/2022

Released