All Projects → NimParsers → parsetoml

NimParsers / parsetoml

Licence: MIT license
A Nim library to parse TOML files

Programming Languages

nim
578 projects

Projects that are alternatives of or similar to parsetoml

serdepp
c++ serialize and deserialize adaptor library like rust serde.rs
Stars: ✭ 70 (-27.08%)
Mutual labels:  toml
pp-toml
Paul's Parser for Tom's Own Minimal Language
Stars: ✭ 17 (-82.29%)
Mutual labels:  toml
Boost.toml
header-only C++(98|11|14|17) TOML v0.5.0 parser/encoder depending on Boost
Stars: ✭ 26 (-72.92%)
Mutual labels:  toml
version-sync
Keep version numbers in sync with Cargo.toml
Stars: ✭ 65 (-32.29%)
Mutual labels:  toml
rtoml
A fast TOML library for python implemented in rust.
Stars: ✭ 214 (+122.92%)
Mutual labels:  toml
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (-78.12%)
Mutual labels:  toml
tomlcheck
A syntax checker for TOML files
Stars: ✭ 28 (-70.83%)
Mutual labels:  toml
paerser
No description or website provided.
Stars: ✭ 38 (-60.42%)
Mutual labels:  toml
coc-toml
Toml extension for coc-nvim, using taplo for lsp engine
Stars: ✭ 52 (-45.83%)
Mutual labels:  toml
rcpptoml
Rcpp Bindings to C++ parser for TOML files
Stars: ✭ 26 (-72.92%)
Mutual labels:  toml
gtree
Output tree🌳 or Make directories📁 from #Markdown or Programmatically. Provide CLI, Golang library and Web (using #Wasm ).
Stars: ✭ 88 (-8.33%)
Mutual labels:  toml
toml-f
TOML parser implementation for data serialization and deserialization in Fortran
Stars: ✭ 69 (-28.12%)
Mutual labels:  toml
llmk
Light LaTeX Make
Stars: ✭ 93 (-3.12%)
Mutual labels:  toml
dssg
A static site generator with a different approach
Stars: ✭ 15 (-84.37%)
Mutual labels:  toml
demo-myblog
使用Rust、Actix-web和MongoDB构建简单博客网站
Stars: ✭ 40 (-58.33%)
Mutual labels:  toml
tomlrb
A Racc based TOML parser
Stars: ✭ 63 (-34.37%)
Mutual labels:  toml
generate-awesome
🖨 A command-line tool for generating Awesome Lists from a set of data files.
Stars: ✭ 22 (-77.08%)
Mutual labels:  toml
toml
TOML parser and encoder for Go with reflection.
Stars: ✭ 19 (-80.21%)
Mutual labels:  toml
remark-frontmatter
remark plugin to support frontmatter (YAML, TOML, and more)
Stars: ✭ 167 (+73.96%)
Mutual labels:  toml
tomli
A lil' TOML parser
Stars: ✭ 313 (+226.04%)
Mutual labels:  toml

NimToml

Parsetoml is a Nim library to parse TOML files (https://github.com/toml-lang/toml). Currently it supports v0.5.0 of the TOML specification. It passes all of the validation tests in the validation suite, including various 0.5.0 examples.

Installation

Use nimble to install it:

nimble install parsetoml

Documentation

https://nimparsers.github.io/parsetoml/

Usage

Below are just few snippets of code to show some basic usage of this library. Refer to the above linked documentation for complete details.

Importing the library

import parsetoml

Parsing TOML content

let table1 = parsetoml.parseString("""
[input]
file_name = "test.txt"

[output]
verbose = true
""")
let table2 = parsetoml.parseFile(f)
let table3 = parsetoml.parseFile("test.toml")

Using the parsed content

The return value of parseString and parseFile is a reference to the TomlValue object, TomlValueRef.

Several getter procs are available to query for specific types of fields for an input TomlValueRef variable:

  • getStr : Get the string value.
  • getInt : Get the integer value.
  • getFloat : Get the float value.
  • getBool : Get the bool value.
  • getElems : Get a sequence of TomlValueRef values.
  • getTable : Get a TomlTableRef value.

Using the same table1 variable from the above example:

# Get the value, or fail if it is not found
let verboseFlag = table1["output"]["verbose"].getBool()

# You can specify a default as well
let input = table1["input"]["file_name"].getStr("some_default.txt")

Transforming the parsed date to JSON / Table

For the validation this library needs to output JSON. Therefore it has a proc to convert the TomlValueRef to JSON nodes.

import parsetoml, json

let table1 = parsetoml.parseString("""
[input]
file_name = "test.txt"

[output]
verbose = true
""")

echo table1.toJson.pretty()

Above outputs:

{
  "input": {
    "file_name": {
      "type": "string",
      "value": "test.txt"
    }
  },
  "output": {
    "verbose": {
      "type": "bool",
      "value": "true"
    }
  }
}

To see the parsed TOML in an alternative Nim AST style indented format, use parsetoml.dump(table1.getTable()) with the above example, and you will get:

input = table
    file_name = string("test.txt")
output = table
    verbose = boolean(true)

License

Parsetoml is released under a MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].