Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/filmor/tomerl

Erlang TOML Parser
https://github.com/filmor/tomerl

Last synced: 2 months ago
JSON representation

Erlang TOML Parser

Awesome Lists containing this project

README

        

TOML Parser for Erlang
======================

[![CI](https://github.com/filmor/tomerl/workflows/CI/badge.svg)](https://github.com/filmor/tomerl/actions)
[![Hex](https://img.shields.io/hexpm/v/tomerl)](https://hex.pm/packages/tomerl)
[![TOML](https://img.shields.io/badge/TOML-1.0.0-blue)](https://toml.io/en/v1.0.0)
[![License](https://img.shields.io/hexpm/l/tomerl)](./LICENSE.md)

`tomerl` is an Erlang library for parsing
[TOML 1.0.0](https://toml.io/en/v1.0.0) data, forked from [toml](https://github.com/dozzie/toml)
by Stanisław Klekot.

The documentation at [Hexdocs](https://hexdocs.pm/tomerl) is updated on release, it can be generated locally via `rebar3 edoc`.

Usage Example
-------------

Assuming an input file called `config.toml` with the following content:

```toml
lipsum = "lorem ipsum dolor sit amet"

[apples]
count = 2

[berry.black]
has_some = true
```

the data can be read in Erlang like this:

```erlang
{ok, Data} = tomerl:read_file("config.toml").

>>> Data = #{
<<"lipsum">> => <<"lorem ipsum dolor sit amet">>,
<<"apples">> => #{ <<"count">> => 2 },
<<"berry">> => #{ <<"black">> => #{ <<"has_some">> => true }}
}.
```

To access the data, there is a simple `get` function that accepts lists of strings, binaries and atoms:

```erlang
{ok, true} = tomerl:get(Data, [berry, black, has_some]),
{ok, 2} = tomerl:get(Data, ["apples", <<"count">>]),
{error, not_found} = tomerl:get(Data, [something, undefined]).
```