Kadlet 0.1.0
dotnet add package Kadlet --version 0.1.0
NuGet\Install-Package Kadlet -Version 0.1.0
<PackageReference Include="Kadlet" Version="0.1.0" />
<PackageVersion Include="Kadlet" Version="0.1.0" />
<PackageReference Include="Kadlet" />
paket add Kadlet --version 0.1.0
#r "nuget: Kadlet, 0.1.0"
#:package Kadlet@0.1.0
#addin nuget:?package=Kadlet&version=0.1.0
#tool nuget:?package=Kadlet&version=0.1.0
Kadlet
A .NET implementation of a parser for the KDL Document Language. Most of its logic and structure is based around kdl4j by hkolbeck.
Usage
using System.IO;
using Kadlet;
// ...
KdlReader reader = new KdlReader(KdlPrintOptions.PrettyPrint);
using (FileStream fs = File.OpenRead("file.kdl")) {
KdlDocument document = reader.Parse(fs);
using (StringWriter sw = new StringWriter()) {
document.Write(sw);
Console.Write(sw.ToString());
};
}
The resulting KdlDocument can be traversed or written back into a stream or string with its methods Write or ToKdlString. The output format can be customized by changing the fields of a KdlPrintOptions instance and passing it as an argument.
The values in properties and arguments are encapsulated in a wrapper KdlValue<T> object, of which there are derivations for most commonly used types. Integers are returned as a KdlInt32 (int), a KdlInt64 (long), or a KdlBigInteger depending on their size. Floating point numbers are returned as a KdlFloat64 by default.
Type annotations
Kadlet supports type annotation overrides, instructing the parser to interpret annotated values differently according to their type.
KdlDocument overrides = reader.Parse(@"
node (u8)123
node (f32)123
");
Console.Write(overrides.ToKdlString());
// Output:
//
// node (u8)123
// node (f32)123.0
All numeric overrides are supported save for isize and usize, which are ignored. The following string overrides are supported.
date-timedatetimedecimalipv4ìpv6regexbase64
Custom type annotations
It's possible to define string overrides for custom types.
public enum Color { Red = 1, Green = 2, Blue = 3 };
// ...
Dictionary<string, KdlTypeConverter> converters = new Dictionary<string, KdlTypeConverter> {
{"hex", (input, type) => new KdlByteArray(Convert.FromHexString(input), type)},
{"color", (input, type) => new KdlEnum(Enum.Parse<Color>(input, true), type)} // slow due to Enum.Parse
};
KdlReader reader = new KdlReader(new KdlReaderOptions {
TypeConverters = converters
});
string kdl = "node (hex)\"5F3759DF\" (color)\"green\"";
KdlDocument doc = reader.Parse(kdl);
Console.Write(doc.ToKdlString());
// Output:
// node (hex)"XzdZ3w== (color)"Green"
Remarks
This library is in an early state and bugs may be found. Issues and pull requests are welcome and encouraged.
License
Kadlet is made available under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.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.1.0 | 6,926 | 7/23/2022 |