Skip to main content

zsh/
lib.rs

1//! Zsh interpreter and parser in Rust
2//!
3//! This crate provides:
4//! - A complete zsh lexer (`lexer` module)
5//! - A zsh parser (`parser` module)  
6//! - Shell execution engine (`exec` module)
7//! - Job control (`jobs` module)
8//! - History management (`history` module)
9//! - ZLE (Zsh Line Editor) support (`zle` module)
10//! - ZWC (compiled zsh) support (`zwc` module)
11//! - Fish-style features (`fish_features` module)
12//! - Mathematical expression evaluation (`math` module)
13
14#![allow(dead_code)]
15#![allow(unused_variables)]
16#![allow(unused_imports)]
17#![allow(unused_assignments)]
18#![allow(unreachable_patterns)]
19#![allow(deprecated)]
20#![allow(unexpected_cfgs)]
21
22pub mod aot;
23pub mod arith_compiler;
24pub mod attr;
25pub mod cap;
26pub mod clone;
27pub mod compat;
28pub mod compile_zsh;
29pub mod completion;
30pub mod cond;
31pub mod config;
32pub mod context;
33pub mod curses;
34// Daemon lives in the `zshrs-daemon` workspace crate. Re-export it as `daemon`
35// so existing `crate::daemon::...` (in exec.rs) and `zsh::daemon::...` (in bins,
36// integration tests) paths keep resolving without churn.
37//
38// The `daemon` feature gates the actual zshrs-daemon dep. When disabled
39// (--no-default-features), a stub module covers the call sites in exec.rs.
40// This lets the library compile in isolation while the daemon crate is
41// being refactored in a concurrent session.
42#[cfg(feature = "daemon")]
43pub use zshrs_daemon as daemon;
44
45#[cfg(not(feature = "daemon"))]
46pub mod daemon {
47    //! Stub module used when the `daemon` feature is disabled. Provides
48    //! the minimal surface that `src/exec.rs` calls — the real
49    //! implementation lives in the `zshrs-daemon` workspace crate.
50    pub mod builtins {
51        pub const ZSHRS_BUILTIN_NAMES: &[&str] = &[];
52        pub fn is_zshrs_builtin(_name: &str) -> bool {
53            false
54        }
55        pub fn try_dispatch(_name: &str, _argv: &[String]) -> Option<i32> {
56            None
57        }
58        pub fn dispatch(_name: &str, _args: &[String]) -> Option<i32> {
59            None
60        }
61    }
62}
63pub mod datetime;
64pub mod db_gdbm;
65pub mod exec;
66pub mod fds;
67pub mod files;
68pub mod fish_features;
69pub mod ast_sexp;
70pub mod glob;
71// `tokens`, `lexer`, `parser` live in the standalone `zshrs-parse` crate
72// so the daemon can use them too. Re-export so existing call sites
73// (`crate::tokens::...`, `zsh::lexer::...`, etc.) keep resolving without
74// touching consumers.
75pub use zshrs_parse::lexer;
76pub use zshrs_parse::parser;
77pub use zshrs_parse::tokens;
78pub mod hashnameddir;
79pub mod hashtable;
80pub mod hist;
81pub mod history;
82pub mod hlgroup;
83pub mod init;
84pub mod input;
85pub mod jobs;
86pub mod ksh93;
87pub mod langinfo;
88pub mod linklist;
89pub mod log;
90pub mod loop_port;
91pub mod mapfile;
92pub mod math;
93pub mod mathfunc;
94pub mod mem;
95pub mod modentry;
96pub mod module;
97pub mod nearcolor;
98pub mod newuser;
99pub mod options;
100pub mod param_private;
101pub mod parameter;
102pub mod params;
103pub mod pattern;
104pub mod pcre;
105pub mod plugin_cache;
106pub mod prompt;
107pub mod random;
108pub mod random_real;
109pub mod regex_mod;
110pub mod rlimits;
111pub mod sched;
112pub mod signals;
113pub mod socket;
114pub mod sort;
115pub mod stat;
116pub mod string_port;
117pub mod stringsort;
118pub mod subscript;
119pub mod subst;
120pub mod subst_port;
121pub mod system;
122pub mod tcp;
123pub mod termcap;
124pub mod terminfo;
125pub mod text;
126pub mod utils;
127pub mod watch;
128pub mod worker;
129pub mod zftp;
130pub mod zle;
131pub mod zprof;
132pub mod zpty;
133pub mod zselect;
134pub mod zutil;
135pub mod zwc;
136pub mod zwc_decode;
137
138pub use exec::ShellExecutor;
139pub use fish_features::{
140    autosuggest_from_history,
141    colorize_line,
142    expand_abbreviation,
143    // Syntax highlighting
144    highlight_shell,
145    // Private mode
146    is_private_mode,
147    // Killring
148    kill_add,
149    kill_replace,
150    kill_yank,
151    kill_yank_rotate,
152    set_private_mode,
153    validate_autosuggestion,
154    // Validation
155    validate_command,
156    with_abbrs,
157    with_abbrs_mut,
158    AbbrPosition,
159    // Abbreviations
160    Abbreviation,
161    AbbreviationSet,
162    // Autosuggestions
163    Autosuggestion,
164    HighlightRole,
165    HighlightSpec,
166    KillRing,
167    ValidationStatus,
168};
169pub use lexer::ZshLexer;
170pub use parser::ZshParser;
171pub use tokens::{char_tokens, LexTok};
172
173// ── Stryke integration hook ──
174// The fat binary registers a handler for @ prefix dispatch.
175// The thin binary leaves this as None — @ is treated as a normal character.
176
177use std::sync::OnceLock;
178
179type StrykeHandler = Box<dyn Fn(&str) -> i32 + Send + Sync>;
180static STRYKE_HANDLER: OnceLock<StrykeHandler> = OnceLock::new();
181
182/// Register a handler for @ prefix lines (fat binary sets this to stryke::run).
183pub fn set_stryke_handler<F>(f: F)
184where
185    F: Fn(&str) -> i32 + Send + Sync + 'static,
186{
187    let _ = STRYKE_HANDLER.set(Box::new(f));
188}
189
190/// Try to dispatch a line starting with @ to stryke.
191/// Returns Some(exit_code) if handled, None if no handler registered.
192pub fn try_stryke_dispatch(code: &str) -> Option<i32> {
193    STRYKE_HANDLER.get().map(|f| f(code))
194}