lumesh 0.18.2

a lighting shell ⚡ bash alternative
Documentation
// `RuntimeError` carries an `Expression` context, intentionally making the Err
// variant large in exchange for richer runtime error info. The `result_large_err`
// lint is not actionable at function-signature levels here.
#![allow(clippy::result_large_err)]
// `Expression` intentionally contains interior-mutability types (Rc, Mutex),
// and BTreeSet/BTreeMap are used for ordered set/map semantics around them.
// The keys are accessed through dedupe + equality, not via Ord, so the keyed
// collection choice is already carefully bounded by those operations.
#![allow(clippy::mutable_key_type)]

#[cfg(test)]
mod tests;

pub type Int = i64;

mod expression;

pub use expression::Expression;
pub use expression::eval;
// mod expr2;
// pub use expr2::*;

mod env;
pub use env::*;

mod errors;
pub use errors::LmError;
pub use errors::error_runtime::*;
pub use errors::error_syntax::*;

mod parser;
pub use parser::*;

mod tokens;
pub use tokens::{Token, TokenKind};

mod tokenizer;
pub use tokenizer::*;

pub mod repl;

pub mod runtime;
pub use runtime::{check, parse, parse_and_eval, parse_with_mode};

pub mod syntax;
pub use syntax::highlight;

pub mod ai;
pub mod cmdhelper;
pub mod prompt;

pub mod childman;
pub mod editor;

pub mod utils;
// pub use utils::abs;
// pub use utils::canon;
pub mod completion;
pub mod jobman;
pub mod modman;
// pub mod excutor;
pub mod libs;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");

// pub static mut STRICT: bool = false;
// pub static mut PRINT_DIRECT: bool = true;
// pub static mut CFM_ENABLED: bool = false;
// // pub static mut ENV: Environment = Environment::new();
// pub static mut MAX_RUNTIME_RECURSION: usize = 800;
// pub static mut MAX_SYNTAX_RECURSION: usize = 100;
// pub static MAX_USEMODE_RECURSION: usize = 100;

use std::cell::RefCell;

thread_local! {
    static PRINT_DIRECT: RefCell<bool> = const {RefCell::new(true)};
    // static CFM_ENABLED: RefCell<bool> = const {RefCell::new(false)};
    static CFM_CONFIG: RefCell<Option<bool>> = const {RefCell::new(None)};
    static STRICT_ENABLED: RefCell<bool> = const {RefCell::new(false)};
    static MAX_RUNTIME_RECURSION: RefCell<usize> = const {RefCell::new(800)};
    static MAX_SYNTAX_RECURSION: RefCell<usize> = const {RefCell::new(100)};
    static MAX_USEMODE_RECURSION: RefCell<usize> = const {RefCell::new(100)};
}

// 辅助函数
pub fn with_print_direct<R>(f: impl FnOnce(bool) -> R) -> R {
    PRINT_DIRECT.with(|v| f(*v.borrow()))
}

pub fn set_print_direct(value: bool) {
    PRINT_DIRECT.with(|v| *v.borrow_mut() = value);
}

// pub fn with_cfm_enabled<R>(f: impl FnOnce(bool) -> R) -> R {
//     CFM_ENABLED.with(|v| f(*v.borrow()))
// }

pub fn set_cfm_enabled(value: Option<bool>) {
    CFM_CONFIG.with(|v| *v.borrow_mut() = value);
}

pub fn with_cfm_config<R>(f: impl FnOnce(Option<bool>) -> R) -> R {
    CFM_CONFIG.with(|v| f(*v.borrow()))
}

pub fn set_strict_enabled(value: bool) {
    STRICT_ENABLED.with(|v| *v.borrow_mut() = value);
}