OpenUI.Parser.Statements (OpenUI v0.1.1)

Copy Markdown View Source

Statement boundaries (language.md, section 1.4) and implicit closing (section 4, rule 2).

The batch parser, the stream and the edit merge all split with split/2, which is what keeps their boundaries identical byte for byte.

Summary

Functions

Closes an unterminated string (adding a backslash first when the text ends mid-escape), then unclosed brackets in reverse order. A closing bracket that does not match the open one is skipped. Returns the closed text and whether anything had to be closed.

Splits prepared text into statement texts.

Functions

auto_close(text)

@spec auto_close(String.t()) :: {String.t(), boolean()}

Closes an unterminated string (adding a backslash first when the text ends mid-escape), then unclosed brackets in reverse order. A closing bracket that does not match the open one is skipped. Returns the closed text and whether anything had to be closed.

split(text, opts)

@spec split(String.t(), keyword()) :: {[String.t()], String.t()}

Splits prepared text into statement texts.

A statement ends at a newline outside brackets and strings, unless a ternary is open or the next line starts with ?. With final: false the text may still grow, so a statement completes only once the next line's first non-whitespace character has arrived; the rest is returned as pending. With final: true everything completes.