# Ergo.Numeric (Ergo v0.9.9)

The Parsers module exists to house utility parsers that while they are terminals in the sense that they are not parameterised, they internally make use of parsers from the Combinators module.

# Parsers

• `uint`
• `decimal`
• `digits`

# Link to this section Summary

## Examples

``````iex> alias Ergo.Context
iex> import Ergo.Numeric
iex> context = Ergo.parse(decimal(), "234.56")
iex> assert %Context{status: :ok, ast: 234.56} = context``````

The `digits` parser matches a series of at least one digit and returns an enumeration of the digits.

The `number` parser matches both integer and decimal string and converts them into their appropriate Elixir integer or float values.

The `unit` parser matches a series of at least one digit and returns the integer value of the digits.

# decimal(opts \\ [])

## Examples

``````iex> alias Ergo.Context
iex> import Ergo.Numeric
iex> context = Ergo.parse(decimal(), "234.56")
iex> assert %Context{status: :ok, ast: 234.56} = context``````

# digits(opts \\ [])

The `digits` parser matches a series of at least one digit and returns an enumeration of the digits.

## Examples

``````iex> alias Ergo.Context
iex> import Ergo.Numeric
iex> context = Ergo.parse(digits(), "2345")
iex> assert %Context{status: :ok, ast: [2, 3, 4, 5]} = context``````

# number(opts \\ [])

The `number` parser matches both integer and decimal string and converts them into their appropriate Elixir integer or float values.

## Examples

``````iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 42} = Ergo.parse(number(), "42")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 42} = Ergo.parse(number(), "+42")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: -42} = Ergo.parse(number(), "-42")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 42.0} = Ergo.parse(number(), "42.0")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: -42.0} = Ergo.parse(number(), "-42.0")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 0} = Ergo.parse(number(), "0")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 0} = Ergo.parse(number(), "0000")

iex> import Ergo.Numeric
iex> assert %{status: {:error, _}} = Ergo.parse(number(), "Fourty Two")

iex> import Ergo.Numeric
iex> assert %{status: :ok, ast: 42} = Ergo.parse(number(), "42Fourty Two")``````
The `unit` parser matches a series of at least one digit and returns the integer value of the digits.
``````iex> alias Ergo.Context