ExDiceRoller v0.3.0-alpha ExDiceRoller.Tokenizer

Provides functionality around tokenizing dice roll strings.

Link to this section Summary

Functions

Converts a roll-based string into tokens using leex. The input definition file is located at src/dice_lexer.xrl. See token_type/0, token/0, and tokens/0 for the possible return values

Link to this section Types

Link to this type token()
token() :: {token_type(), integer(), list()}
Link to this type token_type()
token_type() ::
  :digit | :basic_operator | :complex_operator | :roll | :"(" | :")"
Link to this type tokens()
tokens() :: [token(), ...]

Link to this section Functions

Link to this function tokenize(roll_string)
tokenize(String.t()) :: {:ok, tokens()}

Converts a roll-based string into tokens using leex. The input definition file is located at src/dice_lexer.xrl. See token_type/0, token/0, and tokens/0 for the possible return values.

iex> ExDiceRoller.Tokenizer.tokenize("2d8+3")
{:ok,
[
  {:digit, 1, '2'},
  {:roll, 1, 'd'},
  {:digit, 1, '8'},
  {:basic_operator, 1, '+'},
  {:digit, 1, '3'}
]}