# `Macaw.Frame.TextForm`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/text_form.ex#L1)

A text form of the frame document (spec/02 §11.3): a notation a person types, read into
a fragment of the frame document type and judged as any value is. A text form never
defines a second document type.

A text form is a module implementing this behavior: `name/0`, the first word of a
document written in it; `parse/2`, the text read into a fragment and its **source map**
(`%{path => {line, column, length}}`, lines and columns from 1, columns in grapheme
clusters), or positioned faults; and optionally `print/1` and `vocabulary/0`.

**The registry is explicit and default closed** (`registry/1`), built from the modules a
host lists; a name two forms claim is a fault of the registry. `read/3` reads a text: the
form named by its first word, the kernel's `bytes` limit first, `parse/2`, then
`Macaw.Frame.Document.check/2` of the fragment, every fault re-rooted at its position as
`{[:text, line, column], {:at, path, reason}}`. **Never a raise, never an atom.** The
second cut's diagram forms are `Macaw.Frame.TextForms`' (flowchart, sequence, state,
class, ER, Gantt and timeline); a host lists the ones it reads.

    iex> Macaw.Frame.TextForm.registry([])
    {:ok, %{}}
    iex> Macaw.Frame.TextForm.read("flowchart\nA --> B", %{})
    {:error, [{[:text, 1, 1], {:unknown, :text_form, "flowchart"}}]}

# `position`

```elixir
@type position() :: {pos_integer(), pos_integer(), non_neg_integer()}
```

Where a path of the fragment was written: line, column and length, from 1.

# `positioned_fault`

```elixir
@type positioned_fault() :: {[:text | pos_integer()], term()}
```

A positioned fault: a kernel fault whose path names the position.

# `registry`

```elixir
@type registry() :: %{required(String.t()) =&gt; module()}
```

A registry of text forms by name.

# `source_map`

```elixir
@type source_map() :: %{required([term()]) =&gt; position()}
```

A fragment's source map: each path the parser wrote, and where.

# `name`

```elixir
@callback name() :: String.t()
```

The form's name, unique in a registry, the first word of a document written in it.

# `parse`

```elixir
@callback parse(text :: String.t(), opts :: keyword()) ::
  {:ok, map(), source_map()} | {:error, [positioned_fault()]}
```

The text read into a fragment and its source map, or every positioned fault.

# `print`
*optional* 

```elixir
@callback print(fragment :: map()) :: {:ok, String.t()} | :error
```

The fragment written back in the form, where it can be.

# `vocabulary`
*optional* 

```elixir
@callback vocabulary() :: %{keywords: [String.t()]}
```

The words the form reserves, for an editor's completion.

# `format`

```elixir
@spec format(term()) :: String.t()
```

A positioned fault in words: `line 3, column 5: …`; any other fault as
`Macaw.Frame.Document.format/1` words it.

    iex> Macaw.Frame.TextForm.format({[:text, 3, 5], {:unknown, :text_form, "x"}})
    "line 3, column 5: no registered text form is named \"x\""

# `read`

```elixir
@spec read(term(), term(), term()) ::
  {:ok, map()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

A text read into a fragment and judged (§11.3): `{:ok, fragment}`, or every fault
ordered by position. `opts` are `Macaw.Frame.Document.check/2`'s, and `limits:` whose
`bytes` bounds the text.

# `registry`

```elixir
@spec registry(term()) :: {:ok, registry()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The registry of the forms `modules` lists (§11.3): `{:ok, %{name => module}}`, or every
fault: a module that is no text form `{[:text_forms, i], {:type, :text_form}}`, a name
two forms claim `{[:text_forms, name], {:named_twice, module, other}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
