GitXplorerGitXplorer
R

TomlDotNet

public
7 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
491a1d2a6134b5fe5fa093332fd549be238e88a1

Create README.md

RRichardVasquez committed 12 years ago
Unverified
5cded7df33916a8c7a7273b522e2ebfc190448e9

Reset README.MD due to Windows filename case issues.

RRichardVasquez committed 12 years ago
Unverified
ac67c84936d5370dc0450775500813723fb67e27

cleanup due to filename case on Windows.

RRichardVasquez committed 12 years ago
Unverified
5e29a313e253a2e860ea8dabac8e5eb28013fe2a

Tweaking stuff with README issues.

RRichardVasquez committed 12 years ago
Unverified
47d47497a5cd8f96f3527c0faf07f1f47f85e9b8

Small tweaks before real refactoring and tests.

RRichardVasquez committed 12 years ago
Unverified
a85dd8e211ee8565b94f2c0820541781e59e1343

Cleaner namespace, and TomlDocument.ToString() works now.

RRichardVasquez committed 12 years ago

README

The README file for this repository.

TomlDotNet

This is a very dirty version of a TOML parser. However, though, it works.

It uses dynamic so it's only going to work in .NET 4.0 or above.

The main code is in the TOMLParser project, and some examples of the usage are in the TOML.Demo project.

Since this does use dynamic, dotted names are available as well as indexing.

Using the demo TOML file at https://github.com/mojombo/toml , you can use the following ways to get the same value:

Parsing a TOML Document

  1. Reference the TomlParser library.
  2. Create a dynamic.
    • dynamic td;
  3. Make a string with the contents of the TOML to parse.
    • string s = "# Just a comment.\nnumber = 3";
  4. Try to parse it, result is a boolean.
    • var checkParse = TomlParser.TryParse(s, out td);
  5. If checkParse is true, it parsed.

Referencing a TOML Document

(Assume your TOML document has been parsed into td, and we're using the original test file)

  • Get the last port in database.ports

    • long i = td.database.ports[2];
    • long i = td["database"]["ports"][2];
    • long i = td["database", "ports", 2];
    • long i = td["database.ports"][2];
  • Retrieve a Hashtable (two types, flat and nested), then query that.

    • Flat Hashtables have all the possible keygroups listed out as keys barring the array indices. As above, you'd have to do this:
      long i = flatHash["database.ports"][2];
    • Treed Hashtables:
      long i = treeHash["database"]["ports"][2];

Other things

There's a ToString() in the resulting TomlDocument that will recreate the original TOML document sans comments. The output is sorted first with keys and then with arrays. Each subgroup is alphabetized by name, and arrays attempt to pretty print.

I'm not that good at pretty print.

I implemented GetDynamicMemberNames(), but it's for debugging only, obviously.

TODO

More testing. Right now, I do the following:

  1. Read a TOML text file.
  2. Parse it into a TomlDocument.
  3. Extract the string version of the TomlDocument.
  4. Parse the new string.
  5. Extract the string version of the new TomlDocument.
  6. Compare the strings.
  7. Since they should represent the same data, and thus parse to the same results, if the strings match, then the test passes.

I've run this on both the example.toml file provided initially, and then the harder.toml version presented in the tests directory of the original TOML, and it worked swimmingly both times.

Final

  • The TOMLParser project relies on Sprache available here at https://github.com/sprache/Sprache .
  • This is proof of concept, including documentation. I'll be cleaning both up as time goes by.