ETee.Parser (e_tee v0.1.0)

Copy Markdown View Source

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 as nil
  • {: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.

Summary

Functions

A parser in the ground state.

Feed bytes to the parser.

Types

event()

@type event() ::
  {:print, String.t()}
  | {:execute, byte()}
  | {:csi, byte(), [[non_neg_integer() | nil]], [byte()], byte() | nil}
  | {:esc, byte(), [byte()]}
  | {:osc, String.t()}

t()

@type t() :: %ETee.Parser{
  digits: term(),
  intermediates: term(),
  osc: term(),
  params: term(),
  private: term(),
  state: term(),
  subparams: term(),
  utf8: term()
}

Functions

new()

@spec new() :: t()

A parser in the ground state.

parse(parser, input)

@spec parse(t(), binary()) :: {t(), [event()]}

Feed bytes to the parser.

Returns the updated parser and the events completed by these bytes, in order.