Toml Elixir v1.1.0 TomlElixir View Source

TomlElixir

TOML parser for elixir.

Installation

The package can be installed by adding toml_elixir to your list of dependencies in mix.exs:

def deps do
  [{:toml_elixir, "~> 1.1.0"}]
end

Usage

TomlElixir is used by calling parse functions

Link to this section Summary

Types

Toml group means list of values

Toml ident is same as value tuple but this means identifier or key

Toml key value means tuple with toml identifier and value

Multi is same as group but with difference that it’s a list of maps

Toml return is just list of any toml types

Toml value is a tuple with type and actual value

Functions

Parse toml string to map or return toml tuple list

Same as parse/2, but raises error on failure

Parse toml file, uses same options as parse/2

Same as parse_file/2, but raises error on failure

Link to this section Types

Link to this type options() View Source
options() :: [{:to_map, boolean}]
Link to this type toml_group() View Source
toml_group() :: {:group, [toml_ident], [toml_key_val]}

Toml group means list of values

First list is list of identifiers which point to place in map

Example

Toml:

[key]
example = ["value", true]

Tuple:

{:group,
  [{:identifier, "key"}, {:identifier, "example"}],
  [{:string, "value"}, {:boolean, true}]}

Map:

%{
  "key" => %{
    "example" => ["value", true]
  }
}
Link to this type toml_ident() View Source
toml_ident() :: {:identifier, binary}

Toml ident is same as value tuple but this means identifier or key

Link to this type toml_key_val() View Source
toml_key_val() :: {toml_ident, toml_value}

Toml key value means tuple with toml identifier and value

Example

Toml:

key = value

Tuple:

{{:identifier, "key"}, {:string, "value"}}

Map:

%{"key" => "val"}
Link to this type toml_multi() View Source
toml_multi() :: {:multi, [toml_ident], [toml_key_val]}

Multi is same as group but with difference that it’s a list of maps

Example

Toml:

[[key]]
example1 = val1

[[key]]
example2 = val2

Tuple:

[
  {:multi,
    [{:identifier, "key"}, {:identifier, "example1"}],
    [{:string, "val1"}]},
  {:multi,
    [{:identifier, "key"}, {:identifier, "example2"}],
    [{:string, "val2"}]},
]

Map:

%{
  "key" => [
    %{"example1" => "val1"},
    %{"example2" => "val2"},
  ]
}
Link to this type toml_return() View Source
toml_return() :: [toml_key_val | toml_multi | toml_group] | []

Toml return is just list of any toml types

Link to this type toml_value() View Source
toml_value ::
  {:string, binary} |
  {:datetime, tuple} |
  {:number, number} |
  {:boolean, boolean}

Toml value is a tuple with type and actual value

Link to this section Functions

Link to this function parse(str, opts \\ []) View Source
parse(binary, options) :: {:ok, result} | {:error, String.t}

Parse toml string to map or return toml tuple list.

Example

TomlElixir.parse("toml = true")
Link to this function parse!(str, opts \\ []) View Source
parse!(binary, options) :: result

Same as parse/2, but raises error on failure

Example

TomlElixir.parse!("toml = true")
Link to this function parse_file(path, opts \\ []) View Source
parse_file(binary, options) ::
  {:ok, result} |
  {:error, String.t}

Parse toml file, uses same options as parse/2

Example

TomlElixir.parse_file("path/to/example.toml")
Link to this function parse_file!(path, opts \\ []) View Source
parse_file!(binary, options) :: result

Same as parse_file/2, but raises error on failure

Example

TomlElixir.parse_file!("path/to/example.toml")