Expand description
Zsh interpreter and parser in Rust
This crate provides:
- A complete zsh lexer (
lexermodule) - A zsh parser (
parsermodule) - Shell execution engine (
execmodule) - Job control (
jobsmodule) - History management (
historymodule) - ZLE (Zsh Line Editor) support (
zlemodule) - ZWC (compiled zsh) support (
zwcmodule) - Fish-style features (
fish_featuresmodule) - Mathematical expression evaluation (
mathmodule)
Re-exports§
pub use ported::lex;pub use ported::lex as tokens;pub use ported::parse;pub use builtins::sched;pub use modules::attr;pub use modules::cap;pub use modules::clone;pub use modules::curses;pub use modules::datetime;pub use modules::db_gdbm;pub use modules::example;pub use modules::files;pub use modules::hlgroup;pub use modules::ksh93;pub use modules::langinfo;pub use modules::mapfile;pub use modules::mathfunc;pub use modules::nearcolor;pub use modules::newuser;pub use modules::param_private;pub use modules::parameter;pub use modules::pcre;pub use modules::random;pub use modules::random_real;pub use modules::regex as regex_module;pub use modules::socket;pub use modules::stat;pub use modules::system;pub use modules::tcp;pub use modules::termcap;pub use modules::terminfo;pub use modules::watch;pub use modules::zftp;pub use modules::zprof;pub use modules::zpty;pub use modules::zselect;pub use modules::zutil;pub use builtins::rlimits;pub use fish_features::autosuggest_from_history;pub use fish_features::colorize_line;pub use fish_features::expand_abbreviation;pub use fish_features::highlight_shell;pub use fish_features::is_private_mode;pub use fish_features::kill_add;pub use fish_features::kill_replace;pub use fish_features::kill_yank;pub use fish_features::kill_yank_rotate;pub use fish_features::set_private_mode;pub use fish_features::validate_autosuggestion;pub use fish_features::validate_command;pub use fish_features::with_abbrs;pub use fish_features::with_abbrs_mut;pub use fish_features::AbbrPosition;pub use fish_features::Abbreviation;pub use fish_features::AbbreviationSet;pub use fish_features::Autosuggestion;pub use fish_features::HighlightRole;pub use fish_features::HighlightSpec;pub use fish_features::KillRing;pub use fish_features::ValidationStatus;pub use tokens::lextok;pub use vm_helper::ShellExecutor;pub use zshrs_daemon as daemon;pub use ported::*;
Modules§
- aot
aotsubmodule. Ahead-of-time build: bake one or more shell scripts into a copy of the runningzshrsbinary as a compressed trailer, producing a self-contained executable. At startup, zshrs detects the trailer and runs every embedded script IN INPUT ORDER as a single concatenated zsh program.- arith_
compiler arith_compilersubmodule. ArithCompiler — lowers zsh arithmetic expressions ($((...))) into fusevm bytecodes. Used byZshCompiler(incompile_zsh.rs).- ast_
sexp ast_sexpsubmodule. Canonical AST s-expression emitter forZshProgram.- autoload_
cache autoload_cachesubmodule. rkyv-backed bytecode cache for autoload functions.- autopair
autopairsubmodule — native bracket/quote auto-pairing (port of hlissner/zsh-autopair). Port of hlissner/zsh-autopair (autopair.zsh, 227 lines) — auto-insert, skip-over, and pair-delete for brackets/quotes/spaces in ZLE.- autosuggest
autosuggestsubmodule — native fish-style autosuggestions (port of the reader.rs autosuggestion state machine). Port of fish-shell’s autosuggestion state machine fromreader/reader.rs(vendor/fish/reader/reader.rs:5231-5760) — native fish-style autosuggestions.- bash_
complete bash_completesubmodule. Rust-original types for the bash-stylecompletebuiltin extension.- canonical_
apply canonical_applysubmodule. Apply daemon canonical state to a freshly-built ShellExecutor — by reading the daemon’s rkyv shard directly from disk. No IPC.- compile_
zsh compile_zshsubmodule. Bytecode compiler for the portedZshProgramAST.- compinit_
bg compinit_bgsubmodule. Background compinit pre-warm — extension; no zsh C counterpart.- completion
completionsubmodule. SQLite-backed completion engine (legacy / unused).- compsys
compsyssubmodule. Zsh-compatible completion system (compsys)- config
configsubmodule. zshrs configuration file —~/.config/zshrs/config.toml.- daemon_
presence daemon_presencesubmodule. Daemon-presence detection + per-user config knob.- dap
dapsubmodule. DAP server for zshrs —zshrs --dap [HOST:PORT](TCP connect-back, or stdio when no address is given).- dumpers
dumperssubmodule. Source-to-IR dumpers exposed to thezshrsCLI as--dump-tokens,--dump-ast,--dump-wordcode. Same logic asexamples/{lex,ast,parse}_dump.rsand the parity harnesses (tests/lexer_parity.rs,tests/parity_harness.rs,tests/wordcode_parity.rs) — keeping them in one library function per IR so the binary, examples, and tests can all share output format.- exec_
jobs exec_jobssubmodule. Executor-side bg-job tracker. NOT a port ofSrc/jobs.c.- ext_
builtins ext_builtinssubmodule. Extension-only shell builtins (no zsh C counterpart).- extensions
extensionssubmodule. zshrs extensions — features zsh C does not have.- fast_
hash fast_hashsubmodule — dependency-free FxHash for internal name tables. Fast, dependency-free hasher for the shell’s internal name→node tables.- fds
fdssubmodule. File descriptor utilities for zshrs.- fish_
features fish_featuressubmodule. Fish-style features for zshrs - native Rust implementations.- fmt
fmtsubmodule — zsh source formatter (CLI--fmt+ LSPtextDocument/formatting). zsh source formatter — syntax-aware reindenter.- func_
body_ fmt func_body_fmtsubmodule. Non-C helper: format raw function-body source the way zshtypeset -fpresents multi-statement bodies (split on top-level;/ newlines).- fusevm_
bridge fusevm_bridgesubmodule. fusevm bytecode-VM bridge for ShellExecutor.- fusevm_
disasm fusevm_disasmsubmodule. Optional fusevm bytecode listing to stdout whenzshrsis invoked with--disasm.- gen_
docs gen_docssubmodule. Module-doc generator — produces Markdown documentation from a parsed zshrs source file by pairing##doc comments with the top-level function declaration immediately below them.- heredoc_
ast heredoc_astsubmodule. Heredoc AST-glue types — Rust-only, NOT in zsh C.- history
historysubmodule. SQLite-backed command history for zshrs.- history_
lazy history_lazysubmodule — on-demand HISTFILE paging; the history is never slurped whole. Lazy HISTFILE paging — the history is fetched on demand, never slurped whole.- history_
search history_searchsubmodule — native up-arrow prefix/substring/token history search (port of fish reader/history_search.rs). Port of fish-shell’sreader/history_search.rs(vendor/fish/reader/history_search.rs) — the up-arrow / prefix / token / substring history search state machine.- intercepts
interceptssubmodule. Command intercept / advice machinery — extension; no zsh C counterpart.- log
logsubmodule. zshrs logging & profiling framework.- lowfd
lowfdsubmodule — keeps the shell’s own descriptors out of the user’s fd space. Keep the shell’s own file descriptors out of the user’s fd space.- lsp
lspsubmodule. LSP server for zshrs —zshrs --lsp.- lsp_
symbols lsp_symbolssubmodule. AST-walked symbol table for the zshrs LSP server. Powers cross-file rename and find-references with parser-validated scoping instead of the textual occurrence scan incrate::extensions::lsp::references.- opts_
cache opts_cachesubmodule — fast-pathisset()option-state cache. Fast-path option-state cache — a Rust-only optimization backingisset().- overlay_
snapshot overlay_snapshotsubmodule. Shell-side overlay enumeration forzsync up --all.- p10k
p10ksubmodule — native powerlevel10k prompt engine. Native powerlevel10k prompt engine — extension; no zsh C counterpart.- pat_
cache pat_cachesubmodule — global compiled-pattern cache (Rust-only opt). Global compiled-pattern cache — a zshrs-only optimization with NO C counterpart, so it lives here insrc/extensionsrather than insrc/ported.- pkg
pkg— thezpmplugin package manager (global store). zshrs plugin package manager (znative) — a GLOBAL-only package manager for zsh script plugins AND native (Rust cdylib) plugins.- plugin_
cache plugin_cachesubmodule. Plugin source cache — stores side effects ofsource/.in SQLite.- plugin_
host plugin_hostsubmodule — native (Rust) plugin loader (zmodload -R). Native (Rust) plugin host — extension; no zsh C counterpart.- ported
portedsubmodule. Ported subsystems — every submodule here is a faithful 1:1 port of a corresponding upstream zsh C source file undersrc/zsh/Src/.- regex_
mod regex_modsubmodule. Regex module - port of Modules/regex.c- script_
cache script_cachesubmodule. rkyv-backed bytecode cache for zsh scripts.- stringsort
stringsortsubmodule. String manipulation and sorting for zshrs- subexp_
cleanup subexp_cleanupsubmodule — RAII eviction of__subexp_arr_*paramtab scratch temps created during array sub-expression expansion. Rust-only cleanup guard for the transient__subexp_arr_*array temporaries thatparamsubst(src/ported/subst.rs) stashes in the global paramtab while expanding an array sub-expression (${(s: :)$(cmd)},${${(s: :)v}[N]}, …).- syntax_
highlight syntax_highlightsubmodule — native command-line syntax highlighting (port of fish highlight/highlight.rs, driven by the zshrs lexer). Port of fish-shell’shighlight/highlight.rs(vendor/fish/highlight/highlight.rs) — native command-line syntax highlighting.- tolerant_
sort - Rust-only utility (NOT a port — lives outside
src/ported/by design). - vm_
helper vm_helpersubmodule. Shell executor state for zshrs.- vm_pool
vm_poolsubmodule — per-thread pool of recyclable fusevm VMs. Per-thread pool of recyclable fusevmVMs — a Rust-only optimization that stops zshrs from rebuilding a VM (and re-registering its entire builtin table) on every function call, command substitution, pipeline stage, and subshell.- worker
workersubmodule. Worker pool for zshrs — persistent threads for background work.- zle_
file_ tester zle_file_testersubmodule — file-existence/permission tests for native ZLE syntax highlighting (port of fish highlight/file_tester.rs). Port of fish-shell’shighlight/file_tester.rs(vendor/fish/highlight/file_tester.rs).- zle_fx
zle_fxsubmodule — wiring for the native ZLE effects (autosuggest, syntax highlight, history search, autopair) into zlecore + the renderer. Native ZLE effects wiring — connects the fish-ported engines (autosuggest, syntax_highlight, history_search) to the ZLE core loop and renderer.- zle_
param_ sync zle_param_syncsubmodule — ZLE special-param write-back sync (Rust-only adapter for C’s live GSU setters). ZLE special-param write-back sync (Rust-only adapter).- zsh_ast
zsh_astsubmodule. Zsh AST types — Rust-only, NOT in zsh C.- zsh_
builtin_ docs zsh_builtin_docssubmodule.- zsh_
ext_ builtin_ docs zsh_ext_builtin_docssubmodule.- zsh_
keyword_ docs zsh_keyword_docssubmodule.- zsh_
option_ docs zsh_option_docssubmodule.- zsh_
special_ var_ docs zsh_special_var_docssubmodule.- ztest
ztestsubmodule — shell-level unit test framework (port of../strykelangtest framework).ztest— shell-level unit test framework.- zwc
zwcsubmodule. ZWC (Zsh Word Code) file parser. Direct port of the dump-file family in zsh/Src/parse.c:3077-end.- zwc_
decode zwc_decodesubmodule. Recursive wordcode walker — decodes a.zwcblob into the parser’s ownZshProgramAST so the parity harness can compare zsh-side and zshrs-side ASTs through a single sexp emitter (ast_sexp).
Macros§
- DPUTS
- Port of
#define DPUTS(X, Y)macro fromSrc/zsh.h:2918(macro). - DPUTS1
- Port of
#define DPUTS1(X, Y, Z1)macro fromSrc/zsh.h:2919(macro). - DPUTS2
- Port of
#define DPUTS2(X, Y, Z1, Z2)macro fromSrc/zsh.h:2920(macro). - DPUTS3
- Port of
#define DPUTS3(X, Y, Z1, Z2, Z3)macro fromSrc/zsh.h:2921(macro). - ERRMSG
- Port of
#define ERRMSG(x)fromSrc/zsh.h:2917. Build a debug error-message prefix__FILE__ ":" __LINE__ ": " x. - HEAP_
ERROR - Port of
#define HEAP_ERROR(heap_id)fromSrc/zsh.h:2864. Debug- only macro that fprintf’s an “invalid heap” error to stderr. Rust port: eprintln! with the same format. Only active under thezsh-heap-debugfeature. - STRINGIFY
- Port of
#define STRINGIFY(x)fromSrc/zsh.h:2916. Two-pass stringification (expand x first, then stringify). - STRINGIFY_
LITERAL - Port of
#define STRINGIFY_LITERAL(x)fromSrc/zsh.h:2915. C uses the#operator to stringify an identifier. Rust’sstringify!macro does the same.
Statics§
- IS_
ZSH_ MODE - Runtime shell-mode flag set by the binary entrypoint (
bins/zshrs.rs) at startup. The library can’t directly readbins/zshrs.rs::shell_mode()(it lives in the binary crate), so the binary writes this atomic when parsing--zsh/--bash/--posixand the library reads it from bridge / dispatch sites that need to gate bash-compat-vs-zsh behavior. Defaults tofalse(zshrs-native mode) when not explicitly set.
Functions§
- set_
stryke_ handler - Register a handler for @ prefix lines (fat binary sets this to stryke::run).
- try_
stryke_ dispatch - Try to dispatch a line starting with @ to stryke. Returns Some(exit_code) if handled, None if no handler registered.