Principle:20000419 Fauxnix Command Dispatch Registry
| Knowledge Sources | |
|---|---|
| Domains | Command_Dispatch, Code_Generation |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
A command-dispatch technique that maps each source-shell command name to a generator function via a registry, with shared helpers for strict option validation and string escaping, so the translator can emit correct target-language code per command.
Description
The Command Dispatch Registry is the bridge between the parsed AST and the per-command code generators. A Map<string, Handler> maps bash command names to generator functions that return a block of PowerShell statements following the Fauxnix contract. The registry is populated at import time; lookup(name) retrieves the generator; unknown names fall through to native pass-through execution. Shared helpers enforce consistency: psStr (PowerShell string escaping), psErr/psErr2 (bash-style stderr line + exit-flag), parseArgs/parseWords (word-preserving argv parsing with bundled flags and value-taking options), and CommandSpec (strict GNU-style option validation that fails on unknown options rather than silently ignoring them).
Usage
Use this principle when a source-to-source translator must handle many commands, each with its own option set and output format. The registry + shared-helpers pattern keeps generators consistent and independently testable.
Theoretical Basis
registry = Map<name, (args, ctx) => psBlock>
register(name, handler); registerAll(module)
lookup(name) → handler | undefined
# translator:
handler = lookup(cmd.name)
if handler: psBlock = handler(cmd.args, {position, hasStdin, translationMode})
else: passthrough (native argv execution)