README.md

# Pelecanus

Pelecanus is simple parser combinator for elixir.

## Usage
In Pelecanus, parsers are just (anonymous) pure function
`(state -> {:ok, state, value} | {:ok, state} | {:error, reason})`.
Useful functions that return parser are provided.

```elixir
use Pelecanus, sigil_p: true

# create parser state
init = State.init("pelican come!")

# Terminal Symbols can be written almost regex
parser = ~p(\w+)
{:ok, _state, matched} = parser.(init)

# PEG like operators can be used
parser = sequence [~p(\w+), ~p( ), ~p(\w+), option ~p(!)]
{:ok, _state, list} = parser.(init)
```

You can simply define custom parser;

```elixir
int =
  fn state -> 
    with {:ok, s, v} <- ~p(\d+).(state),
         do: {:ok, s, String.to_integer v}
  end

{:ok, _state, 1758} = int.(State.init("1758"))
```

passing state contain context field.
You can use this as you like.

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `pelecanus` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [
    {:pelecanus, "~> 0.1.0"}
  ]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/pelecanus](https://hexdocs.pm/pelecanus).