Lines
100 %
Functions
Branches
//! The built-in names no program may define or bind.
use crate::error::{Error, Result};
use crate::runtime::SymbolTable;
use std::collections::HashSet;
use std::sync::OnceLock;
pub(crate) fn is_builtin_name(symbols: &SymbolTable, name: &str) -> bool {
static NAMES: OnceLock<HashSet<String>> = OnceLock::new();
NAMES
.get_or_init(SymbolTable::builtin_names)
.contains(&name.to_uppercase())
|| symbols.is_host_name(name)
}
/// Rejects a user definition or binding of a built-in or host fn name.
pub(crate) fn reject_reserved(symbols: &SymbolTable, name: &str) -> Result<()> {
match is_builtin_name(symbols, name) {
true => Err(Error::Compile(format!(
"'{}' is a built-in and cannot be redefined",
name.to_lowercase()
))),
false => Ok(()),
#[cfg(test)]
#[path = "reserved_tests.rs"]
mod tests;