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

Functions

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.

Link to this section Functions

Link to this function

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
Link to this function

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
Link to this function

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")
Link to this function

uint(opts \\ [])

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

Examples

iex> alias Ergo.Context
iex> import Ergo.Numeric
iex> context = Ergo.parse(uint(), "2345")
iex> assert %Context{status: :ok, ast: 2345, index: 4, col: 5} = context