use std::cell::Cell; thread_local! { static SUGAR_ON: Cell = Cell::new(false); } pub fn is_enabled_env() -> bool { if std::env::var("NYASH_FORCE_SUGAR").ok().as_deref() == Some("1") { return true; } matches!( std::env::var("NYASH_SYNTAX_SUGAR_LEVEL").ok().as_deref(), Some("basic") | Some("full") ) } pub fn is_enabled() -> bool { SUGAR_ON.with(|c| c.get()) || is_enabled_env() } pub fn with_enabled(f: impl FnOnce() -> T) -> T { SUGAR_ON.with(|c| { let prev = c.get(); c.set(true); let r = f(); c.set(prev); r }) }