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 ast_opt;
23pub mod attr;
24pub mod cap;
25pub mod compiler;
26pub mod clone;
27pub mod compat;
28pub mod completion;
29pub mod config;
30pub mod cond;
31pub mod context;
32pub mod curses;
33pub mod datetime;
34pub mod db_gdbm;
35pub mod exec;
36pub mod fds;
37pub mod files;
38pub mod fish_features;
39pub mod glob;
40pub mod hashnameddir;
41pub mod hashtable;
42pub mod hist;
43pub mod history;
44pub mod hlgroup;
45pub mod init;
46pub mod input;
47pub mod jobs;
48pub mod ksh93;
49pub mod langinfo;
50pub mod lexer;
51pub mod linklist;
52pub mod log;
53pub mod loop_port;
54pub mod mapfile;
55pub mod math;
56pub mod mathfunc;
57pub mod mem;
58pub mod modentry;
59pub mod module;
60pub mod nearcolor;
61pub mod newuser;
62pub mod options;
63pub mod param_private;
64pub mod parameter;
65pub mod params;
66pub mod parser;
67pub mod pattern;
68pub mod pcre;
69pub mod plugin_cache;
70pub mod prompt;
71pub mod random;
72pub mod random_real;
73pub mod regex_mod;
74pub mod rlimits;
75pub mod sched;
76pub mod signals;
77pub mod socket;
78pub mod sort;
79pub mod stat;
80pub mod string_port;
81pub mod stringsort;
82pub mod subscript;
83pub mod subst;
84pub mod subst_port;
85pub mod system;
86pub mod tcp;
87pub mod termcap;
88pub mod terminfo;
89pub mod text;
90pub mod tokens;
91pub mod utils;
92pub mod watch;
93pub mod zftp;
94pub mod zle;
95pub mod zprof;
96pub mod zpty;
97pub mod zselect;
98pub mod shell_compiler;
99pub mod worker;
100pub mod zutil;
101pub mod zwc;
102
103pub use exec::ShellExecutor;
104pub use fish_features::{
105    autosuggest_from_history,
106    colorize_line,
107    expand_abbreviation,
108    // Syntax highlighting
109    highlight_shell,
110    // Private mode
111    is_private_mode,
112    // Killring
113    kill_add,
114    kill_replace,
115    kill_yank,
116    kill_yank_rotate,
117    set_private_mode,
118    validate_autosuggestion,
119    // Validation
120    validate_command,
121    with_abbrs,
122    with_abbrs_mut,
123    AbbrPosition,
124    // Abbreviations
125    Abbreviation,
126    AbbreviationSet,
127    // Autosuggestions
128    Autosuggestion,
129    HighlightRole,
130    HighlightSpec,
131    KillRing,
132    ValidationStatus,
133};
134pub use lexer::ZshLexer;
135pub use parser::ZshParser;
136pub use tokens::{char_tokens, LexTok};
137
138// ── Stryke integration hook ──
139// The fat binary registers a handler for @ prefix dispatch.
140// The thin binary leaves this as None — @ is treated as a normal character.
141
142use std::sync::OnceLock;
143
144type StrykeHandler = Box<dyn Fn(&str) -> i32 + Send + Sync>;
145static STRYKE_HANDLER: OnceLock<StrykeHandler> = OnceLock::new();
146
147/// Register a handler for @ prefix lines (fat binary sets this to stryke::run).
148pub fn set_stryke_handler<F>(f: F)
149where
150    F: Fn(&str) -> i32 + Send + Sync + 'static,
151{
152    let _ = STRYKE_HANDLER.set(Box::new(f));
153}
154
155/// Try to dispatch a line starting with @ to stryke.
156/// Returns Some(exit_code) if handled, None if no handler registered.
157pub fn try_stryke_dispatch(code: &str) -> Option<i32> {
158    STRYKE_HANDLER.get().map(|f| f(code))
159}
160