Ergo.Terminals.char

You're seeing just the function char, go back to Ergo.Terminals module for more information.

The char/1 parser is a terminal parser that matches a specific character.

Examples

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?H)
iex> Ergo.parse(parser, "Hello World")
%Context{status: :ok, char: ?H, ast: ?H, input: "ello World", index: 1, line: 1, col: 2}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?h)
iex> Ergo.parse(parser, "Hello World")
%Context{status: {:error, :unexpected_char}, message: "Expected: h Actual: H", input: "Hello World"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?H)
iex> Ergo.parse(parser, "")
%Context{status: {:error, :unexpected_eoi}, message: "Unexpected end of input"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?A..?Z)
iex> Ergo.parse(parser, "Hello World")
%Context{status: :ok, char: ?H, ast: ?H, input: "ello World", index: 1, line: 1, col: 2}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?a..?z)
iex> Ergo.parse(parser, "Hello World")
%Context{status: {:error, :unexpected_char}, message: "Expected: a..z Actual: H", input: "Hello World"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?A..?Z)
iex> Ergo.parse(parser, "")
%Context{status: {:error, :unexpected_eoi}, message: "Unexpected end of input"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char([?a..?z, ?A..?Z])
iex> Ergo.parse(parser, "Hello World")
%Context{status: :ok, char: ?H, ast: ?H, input: "ello World", index: 1, line: 1, col: 2}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char([?a..?z, ?A..?Z])
iex> Ergo.parse(parser, "0000")
%Context{status: {:error, :unexpected_char}, message: "Expected: [a..z, A..Z] Actual: 0", input: "0000"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(-?0)
iex> Ergo.parse(parser, "0000")
%Context{status: {:error, :unexpected_char}, message: "Should not have matched 0", input: "0000"}

iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(-?a)
iex> Ergo.parse(parser, "0000")
%Context{status: :ok, input: "000", ast: ?0, char: ?0, index: 1, col: 2}