Skip to content

String Engine

Pt edited this page Jun 17, 2026 · 1 revision

String Engine is the textual backend in Lc.

It is suitable for:

  • command-oriented runtimes,
  • script-like processing layers,
  • language-front execution stages,
  • text transformation and compilation steps.

Runtime flow

  1. Input stored in INPUT string.
  2. Parser returns []ParsedNode.
  3. Parsed nodes stored in PARSED []ParsedNode.
  4. Runtime dispatches command handlers by ParsedNode.Switch.
  5. Handlers write to UEP.Generator.

Parser options

All parser results has automatic __prev / __next node references.

Parser1 (grammar-first)

Use when you need:

  • regex grammar matching,
  • multiline continuation support,
  • bracket-balance parsing,
  • capture-group metadata extraction.

Parser2 (line-command parser)

Use when lines follow command args shape.

  • command -> Switch
  • rest of line -> metadata args

Lexer (token-first)

Use when tokenization is a separate concern:

  • ordered regexp2 matching,
  • named metadata groups,

Command contract

Registration:

  • NewCommandString(cmdSwitch, handler, doc)

Handler signature:

  • func(*engine.StringEngine, stringParsing.ParsedNode) error

Recommended behavior:

  • validate metadata early,
  • keep side effects explicit,
  • write deterministic output to known pipeline points,
  • return typed/context-rich errors.

Metadata discipline

Typical metadata keys:

  • parser-defined capture groups,
  • __raw,
  • __value (lexer),
  • __prev, __next.

In large projects, treat metadata as schema:

  • define key constants centrally,
  • version key contracts with parser evolution.

Output strategy

Write:

  • Generator.AddString(...)
  • Generator.AddStrings(...)

Read:

  • Generator.GetStringArrRes()
  • Generator.GetStringRes(sep)

Use explicit pipeline points to separate runtime phases.

Clone this wiki locally