Ergo.Terminals.char
You're seeing just the function
char
, go back to Ergo.Terminals module for more information.
Link to this function
char(c, opts \\ [])
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> assert %Context{status: :ok, ast: ?H, input: "ello World", index: 1, line: 1, col: 2} = Ergo.parse(parser, "Hello World")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?h)
iex> assert %Context{status: {:error, :unexpected_char}, message: "Expected: h Actual: H", input: "Hello World"} = Ergo.parse(parser, "Hello World")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?H)
iex> assert %Context{status: {:error, :unexpected_eoi}, message: "Unexpected end of input"} = Ergo.parse(parser, "")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?A..?Z)
iex> assert %Context{status: :ok, ast: ?H, input: "ello World", index: 1, line: 1, col: 2} = Ergo.parse(parser, "Hello World")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?a..?z)
iex> assert %Context{status: {:error, :unexpected_char}, message: "Expected: a..z Actual: H", input: "Hello World"} = Ergo.parse(parser, "Hello World")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(?A..?Z)
iex> assert %Context{status: {:error, :unexpected_eoi}, message: "Unexpected end of input"} = Ergo.parse(parser, "")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char([?a..?z, ?A..?Z])
iex> assert %Context{status: :ok, ast: ?H, input: "ello World", index: 1, line: 1, col: 2} = Ergo.parse(parser, "Hello World")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char([?a..?z, ?A..?Z])
iex> assert %Context{status: {:error, :unexpected_char}, message: "Expected: [a..z, A..Z] Actual: 0", input: "0000"} = Ergo.parse(parser, "0000")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(-?0)
iex> assert %Context{status: {:error, :unexpected_char}, message: "Should not have matched 0", input: "0000"} = Ergo.parse(parser, "0000")
iex> alias Ergo.Context
iex> import Ergo.Terminals
iex> parser = char(-?a)
iex> assert %Context{status: :ok, input: "000", ast: ?0, index: 1, col: 2} = Ergo.parse(parser, "0000")