Coder Social home page Coder Social logo

toml's Introduction

TOML parser for Erlang

toml is an Erlang library application for parsing TOML configuration language. It supports parsing 0.4.0 version of the TOML specification.

Since TOML is a format for configuration files instead of general purpose serialization, toml library focuses on reading the configuration parameters.

toml:parse/2 and toml:read_file/2 allow user to provide a validation callback, which can check correctness of a value (e.g. if a listen address in listen="host:port" has proper format) and even convert such values to a usable Erlang data structure. All this happens at the time of reading a configuration file, so any errors can be rejected in uniform manner.

In smaller scale, toml:get_value/3 returns values as tuples tagged with value type. This allows to fail early and with clear error on an obviously invalid parameter:

# [spool]
# directory = 1024
{string, SpoolDir} = toml:get_value(["spool"], "directory", Config).

Configuration usually consists of flags and parameters and not of complex, nested data structures, so toml leans towards simple sections (or tables, how TOML calls them) and simple access to values in them. Still, all the TOML specification is supported, so nested structures are available.

Usage example

Let's assume an input file called config.toml has following content:

lipsum = "lorem ipsum dolor sit amet"

[apples]
count = 2

[berry.black]
has_some = true

Configuration from this file can be retrieved in following manner:

{ok, Config} = toml:read_file("config.toml").
{string, Val1} = toml:get_value([], "lipsum", Config).
{integer, Val2} = toml:get_value(["apples"], "count", Config).
{boolean, Val3} = toml:get_value(["berry", "black"], "has_some", Config).
none = toml:get_value([], "oranges", Config).

Documentation

toml is documented using EDoc. A local copy is generated with make doc command to ./doc/ directory. An already generated online copy is available at http://dozzie.jarowit.net/api/erlang-toml/.

Known limitations

  • Types conveying time only store 1s precision (fraction of a second is truncated)

Contact and License

toml library is written by Stanislaw Klekot . The primary distribution point is http://dozzie.jarowit.net/.

toml library is distributed under 3-clause BSD license. See COPYING file for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.