Packages
Add a dice-rolling DSL with sigil support and reusable compiled functions to your application.
Current section
Files
Jump to
Current section
Files
lib/sigil.ex
defmodule ExDiceRoller.Sigil do
@moduledoc "Functionality for sigil usage."
alias ExDiceRoller.{Compiler, Parser, Tokenizer}
@doc """
Handles the sigil `~a` for dice rolling.
Returns the compiled version of the dice roll.
## Example
```elixir
iex>
```
"""
def sigil_a(string, []) do
{:ok, tokens} = Tokenizer.tokenize(string)
{:ok, parsed} = Parser.parse(tokens)
Compiler.compile(parsed)
end
def sigil_a(string, [mod]) when mod == ?r do
{:ok, tokens} = Tokenizer.tokenize(string)
{:ok, parsed} = Parser.parse(tokens)
fun = Compiler.compile(parsed)
fun.([])
end
end