defmodule Yameru do @moduledoc """ Yameru library for Elixir ## Value This parser map any value (scalar, block or tuple) to `{scalar, block}` form. When either one isn't exist, just set `nil`. ## Example ``` iex> input = \"\"\" ...> key 1: scalar ...> key 2: ...> - block ...> key 3: tuple / ...> scalar and block ...> \"\"\" iex> {:ok, result} = Yameru.parse(input) iex> result %{ "key 1" => {"scalar", nil}, "key 2" => {nil, [{"block", nil}]}, "key 3" => {"tuple", "scalar and block"} } ``` """ alias Yameru.Parser @type scalar :: String.t() | special_scalar() @type special_scalar :: integer() | float() | boolean() | Date.t() | Time.t() | NaiveDateTime.t() @type block :: String.t() | dictionary() | sequence() @type dictionary :: %{scalar() => sb()} @type sequence :: [sb()] @type sb :: {scalar(), block()} | {scalar(), nil} | {nil, block()} @doc """ Loads and parses given name file. """ @spec load(Path.t()) :: {:ok, term()} | {:error, term()} def load(path) do with {:ok, string} <- File.read(path), do: Parser.parse(string) end @doc """ Parses given string. """ defdelegate parse(string), to: Yameru.Parser end