A byte-stream state machine over the DEC ANSI / ECMA-48 grammar.
parse/2 takes whatever bytes arrived and returns the parser and the events those
bytes completed. All partial state — a half-read parameter list, an unterminated
OSC payload, a truncated UTF-8 character — is carried in the returned parser, so a
sequence chopped across reads parses exactly as it would have whole. The incomplete
UTF-8 tail is the only case where raw bytes are held rather than classified.
Events:
{:print, text}— a run of printable text, always valid UTF-8{:execute, byte}— a C0 control{:csi, final, params, intermediates, private}— params are semicolon-separated, each a list of colon-separated subparameters, with omitted numbers asnil{:esc, final, intermediates}{:osc, payload}— the payload between the introducer and its terminator
Device control, SOS, PM and APC strings are consumed up to their terminator and discarded.