diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..f72858c --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,39 @@ +version: 11.0.{build} +image: Visual Studio 2017 +configuration: Release +install: +- ps: >- + cd src + + nuget restore Tomlyn.sln + + $env:TOMLYN_BUILD_NUMBER = ([int]$env:APPVEYOR_BUILD_NUMBER).ToString("000") + + $env:appveyor_nuget_push = 'false' + + if(-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { + if($env:appveyor_repo_tag -eq 'True') { + if($env:appveyor_repo_tag_name -match '^v[0-9]') { + $env:appveyor_nuget_push = 'true' + } + } + } +build: + project: src/Tomlyn.sln + verbosity: minimal +before_package: +- cmd: >- + msbuild /t:pack /p:Configuration=Release Tomlyn/Tomlyn.csproj + + msbuild /t:Clean Tomlyn/Tomlyn.csproj + + msbuild /t:pack /p:Configuration=Release;SignAssembly=true Tomlyn/Tomlyn.csproj +artifacts: +- path: src\Tomlyn\Bin\Release\*.nupkg + name: Tomlyn Nugets +deploy: +- provider: NuGet + api_key: + secure: 7cthHh+wYWZjhqxaxR6QObRaRnstvFkQOY7MkxIsC5kpQEBlKZXuinf0IybbYxJt + on: + appveyor_nuget_push: true \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..40474d1 --- /dev/null +++ b/changelog.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.1.0 (12 Feb 2019) + +- Initial version (support for TOML 0.5) diff --git a/img/logo.png b/img/logo.png index 84e7de1..34c7b78 100644 Binary files a/img/logo.png and b/img/logo.png differ diff --git a/readme.md b/readme.md index 2a46c61..85afda6 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,77 @@ -# Tomlyn +# Tomlyn [![Build status](https://ci.appveyor.com/api/projects/status/ig5kv8r63bqjsd9a?svg=true)](https://ci.appveyor.com/project/xoofx/Tomlyn) [![NuGet](https://img.shields.io/nuget/v/Tomlyn.svg)](https://www.nuget.org/packages/Tomlyn/) Tomlyn is a TOML parser, validator and authoring library for .NET Framework and .NET Core -> NOTE: The library is under development and not available yet for public usage. +## Features + +- Very fast parser, GC friendly +- Compatible with latest [TOML 0.5 specs](https://github.com/toml-lang/toml) +- Support perfect load/save roundtrip while preserving all spaces, new line, comments +- Provides a validator with the `Toml.Validate` method +- Allow to work on the syntax tree directly (preserving styles) through the `Toml.Parse` +- Allow to work with a runtime representation `Toml.ToModel` (but cannot be saved back to TOML) + +## Usage + +```C# +var input = @"[mytable] +key = 15 +val = true +"; + +// Gets a syntax tree of the TOML text +var doc = Toml.Parse(input); // returns a DocumentSyntax +// Check for parsing errors with doc.HasErrors and doc.Diagnostics +// doc.HasErrors => throws an exception + +// Prints the exact representation of the input +var docStr = doc.ToString(); +Console.WriteLine(docStr); + +// Gets a runtime representation of the syntax tree +var table = doc.ToModel(); +var key = (long) ((TomlTable) table["mytable"])["key"]; +var value = (bool) ((TomlTable) table["mytable"])["val"]; +Console.WriteLine($"key = {key}, val = {value}"); +``` + +Creates a TOML document programmatically: + +```C# +var doc = new DocumentSyntax() +{ + Tables = + { + new TableSyntax("test") + { + Items = + { + {"a", 1}, + {"b", true }, + {"c", "Check"}, + {"d", "ToEscape\nWithAnotherChar\t" }, + {"e", 12.5 }, + {"f", new int[] {1,2,3,4} }, + {"g", new string[] {"0", "1", "2"} }, + {"key with space", 2} + } + } + } +}; +Console.WriteLine(doc); +// Prints: +// [test] +// a = 1 +// b = true +// c = "Check" +// d = "ToEscape\nWithAnotherChar\t" +// e = 12.5 +// f = [1, 2, 3, 4] +// g = ["0", "1", "2"] +// "key with space" = 2 +``` ## License diff --git a/src/Tomlyn.Tests/SyntaxTests.cs b/src/Tomlyn.Tests/SyntaxTests.cs index 00ad27c..17f63e8 100644 --- a/src/Tomlyn.Tests/SyntaxTests.cs +++ b/src/Tomlyn.Tests/SyntaxTests.cs @@ -2,7 +2,9 @@ // Licensed under the BSD-Clause 2 license. // See license.txt file in the project root for full license information. +using System; using NUnit.Framework; +using Tomlyn.Model; using Tomlyn.Syntax; namespace Tomlyn.Tests @@ -52,5 +54,29 @@ public void TestDocument() var newDoc = Toml.Parse(docStr); AssertHelper.AreEqualNormalizeNewLine(expected, newDoc.ToString()); } + + [Test] + public void Sample() + { + var input = @"[mytable] +key = 15 +val = true +"; + + // Gets a syntax tree of the TOML text + var doc = Toml.Parse(input); // returns a DocumentSyntax + // Check for parsing errors with doc.HasErrors and doc.Diagnostics + // doc.HasErrors => throws an exception + + // Prints the exact representation of the input + var docStr = doc.ToString(); + Console.WriteLine(docStr); + + // Gets a runtime representation of the syntax tree + var table = doc.ToModel(); + var key = (long) ((TomlTable) table["mytable"])["key"]; + var value = (bool) ((TomlTable) table["mytable"])["val"]; + Console.WriteLine($"key = {key}, val = {value}"); + } } } \ No newline at end of file diff --git a/src/Tomlyn/key.snk b/src/Tomlyn/key.snk new file mode 100644 index 0000000..24a2e62 Binary files /dev/null and b/src/Tomlyn/key.snk differ