# `OpenUILang`
[🔗](https://github.com/boxxxie/openui_lang/blob/v1.0.0/lib/openui_lang.ex#L1)

Elixir implementation of the OpenUI 1.0 Language specification (`openui-lang`).

Provides a zero-dependency lexer, Pratt expression parser, schema-aware materializer,
incremental streaming parser, runtime evaluator, statement patch merger, serializer,
form validation rules, message protocol parser, and system prompt generator.

# `auto_close`

```elixir
@spec auto_close(String.t()) :: %{text: String.t(), was_incomplete: boolean()}
```

Auto-closes unclosed strings and brackets in a partial `openui-lang` string.

# `build_message`

```elixir
@spec build_message(map()) :: String.t()
```

Builds an OpenUI wire message with `]]>openui:` section markers.

# `compile_schema`

```elixir
@spec compile_schema(map() | nil) :: map()
```

Compiles a decoded `LibrarySpec` (or JSON Schema map) into a compiled catalog (`cat`)
for use with `parse/3`, `stream_parser/2`, `evaluate_result/2`, and `json_to_openui/3`.

# `decode_json!`

```elixir
@spec decode_json!(String.t()) :: term()
```

Decodes a JSON string while preserving object key insertion order in `"__keys__"`.
Required when loading a `LibrarySpec` JSON file so positional argument order matches
the JSON Schema property order.

# `demux`

```elixir
@spec demux(String.t()) :: %{prose: String.t(), code: String.t()}
```

Demultiplexes mixed conversational Markdown prose and `openui-lang` code blocks.
Returns `%{prose: String.t(), code: String.t()}`.

# `evaluate`

```elixir
@spec evaluate(map(), map(), map() | nil) :: term()
```

Evaluates a single AST node with the given evaluation context.

# `evaluate_result`

```elixir
@spec evaluate_result(map(), map()) :: map()
```

Evaluates a `ParseResult` and returns the canonical OpenUI result map
(`root`, `tree`, `errors`, `errorObjects`, `unresolved`, `orphans`, `incomplete`, `state`).

# `generate_system_prompt`

```elixir
@spec generate_system_prompt(map(), keyword()) :: String.t()
```

Generates a system prompt for an LLM from a `LibrarySpec` map.

# `json_to_openui`

```elixir
@spec json_to_openui(map(), map(), map()) :: String.t()
```

Serializes an `ElementNode` tree back to `openui-lang` source text.

# `merge_statements`

```elixir
@spec merge_statements(String.t(), String.t(), String.t()) :: String.t()
```

Merges an existing `openui-lang` program with a statement patch and garbage-collects
statements unreachable from `root_id`.

# `parse`

```elixir
@spec parse(String.t(), map() | nil, String.t() | nil) :: map()
```

Parses a complete or partial `openui-lang` source string in one batch pass.

# `parse_expression`

```elixir
@spec parse_expression([map()]) :: map()
```

Parses a token list into an AST expression node.

# `parse_message`

```elixir
@spec parse_message(String.t(), keyword()) :: map()
```

Parses an OpenUI wire message with `]]>openui:` section markers.

# `parse_symbols`

```elixir
@spec parse_symbols(String.t()) :: %{optional(String.t()) =&gt; term()}
```

Parses an `openui-lang` source string (complete or mid-stream partial) into a flat
symbol table map `%{"root" => {"Panel", [...]}, "$var" => "default", ...}` for TUI
forward-reference resolution, 80-column layout clamping, and live `$live_*` bindings.

# `push_chunk`

```elixir
@spec push_chunk(OpenUILang.Parser.t(), String.t(), boolean()) ::
  {map(), OpenUILang.Parser.t()}
```

Pushes a streamed chunk into the streaming parser and returns `{parse_result, updated_stream_parser}`.

# `stream_parser`

```elixir
@spec stream_parser(map() | nil, String.t() | nil) :: OpenUILang.Parser.t()
```

Creates a new stateful `OpenUILang.Parser` streaming parser struct.

# `tokenize`

```elixir
@spec tokenize(String.t()) :: [map()]
```

Tokenizes an `openui-lang` source string into a flat token list.

# `validate_rules`

```elixir
@spec validate_rules(term(), map() | [String.t()], map()) :: String.t() | nil
```

Validates a form value against structured validation rules.
Returns `nil` when valid, or an error string when invalid.

---

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