diff options
| author | eunhhu <[email protected]> | 2026-09-25 12:09:41 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-09-25 12:09:41 +0100 |
| commit | a2a430f6c2d973232a4e995133b372ba877558cf (patch) | |
| tree | f1e22521ba03ff4683737131eec0af05e6e0cbd4 /prototypes/connections/module-text.h | |
| parent | 08056bb65bb9d1cfa4ccb1cd0b9cb67554d560a3 (diff) | |
| download | pure-a2a430f6c2d973232a4e995133b372ba877558cf.tar.gz pure-a2a430f6c2d973232a4e995133b372ba877558cf.zip | |
Add text states and cursors to Pure modules
Module format v3 adds text states, cursors, UTF-8 constants, text inputs
and text views. A text state is a runtime-owned draft without a store, so a
large text edits as an extent tree. Cursors are byte positions the runtime
keeps on character boundaries: insertion pushes cursors at or after the
point, removal gathers cursors inside the range, and a failed event returns
every text draft and cursor to where it was. The verifier types a cursor by
the text it belongs to and rejects editing one text with another's cursor.
Operations cover constants, concatenation, shortest round-trip number text,
character, line and byte counts, character and column-keeping line moves,
insert, remove, line views, whole-text replacement and UTF-8 checked
conversion from bytes. Replies of edited documents or texts are copied before
they are finished. pure-run gains text input and text output.
test-module covers typing Korean and emoji, moves that stop at the ends,
line moves, views, rollback, invalid UTF-8 and replacement, text-specific
verifier rules, and 20,000 damaged text modules whose cursors always stay
on character boundaries under ASan/UBSan.
Diffstat (limited to 'prototypes/connections/module-text.h')
| -rw-r--r-- | prototypes/connections/module-text.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/prototypes/connections/module-text.h b/prototypes/connections/module-text.h new file mode 100644 index 0000000..4843928 --- /dev/null +++ b/prototypes/connections/module-text.h @@ -0,0 +1,34 @@ +#ifndef PURE_MODULE_TEXT_H +#define PURE_MODULE_TEXT_H +#include "flow.h" +#include "state.h" +#include <stdbool.h> +#include <stddef.h> + +/* Text helpers of the module executor. Text is valid UTF-8; a character is a + * Unicode scalar value, so every position these return is a scalar boundary. */ + +/* Strict UTF-8: no overlongs, surrogates or values past U+10FFFF. state + * carries a sequence split across spans; start it at 0 and finish with + * pure_utf8_complete. */ +bool pure_utf8_step(unsigned *state, PureSpan span); +bool pure_utf8_complete(unsigned state); +bool pure_utf8_valid(PureSpan span); + +/* Scalars (bytes that are not 10xxxxxx) and newlines in a span. */ +size_t pure_utf8_scalars(PureSpan span); +size_t pure_utf8_newlines(PureSpan span); + +/* Shortest decimal that reads back to the same finite double: integers + * below 1e15 without a point or exponent, otherwise %g form with a trimmed + * exponent. -0 prints as 0. Returns the length written (at most 32). */ +size_t pure_format_number(double value, char out[32]); + +/* Positions in one version of a text draft (size is version.bytes). */ +size_t pure_text_step(const PureDraft *, PureVersion, size_t position, double count); +size_t pure_text_line_step(const PureDraft *, PureVersion, size_t position, double count); +size_t pure_text_line_start(const PureDraft *, PureVersion, size_t position); +size_t pure_text_line_end(const PureDraft *, PureVersion, size_t position); +/* Scalars (unit 0) or line number counting from 1 (unit 1) before position. */ +size_t pure_text_count(const PureDraft *, PureVersion, size_t position, unsigned unit); +#endif |
