Lines
84.48 %
Functions
36.67 %
Branches
100 %
use std::collections::HashMap;
use crate::ast::Expr;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SymbolKind {
/// Built-in operators like +, -, *, /
Operator,
/// Native functions implemented in the runtime
Native,
/// User-defined functions
Function,
/// Variables and constants
Variable,
/// Special forms like if, let, define, lambda
SpecialForm,
/// User-defined macros
Macro,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Symbol {
pub(super) name: String,
pub(super) kind: SymbolKind,
pub(super) value: Option<Expr>,
pub(super) function: Option<Expr>,
pub(super) doc: Option<String>,
pub(super) properties: HashMap<String, Expr>,
impl Symbol {
pub fn new(name: impl Into<String>, kind: SymbolKind) -> Self {
Self {
name: name.into(),
kind,
value: None,
function: None,
doc: None,
properties: HashMap::new(),
#[must_use]
pub fn with_value(mut self, value: Expr) -> Self {
self.value = Some(value);
self
pub fn name(&self) -> &str {
&self.name
pub fn kind(&self) -> SymbolKind {
self.kind
pub fn value(&self) -> Option<&Expr> {
self.value.as_ref()
pub fn set_value(&mut self, value: Expr) {
pub fn with_function(mut self, func: Expr) -> Self {
self.function = Some(func);
pub fn function(&self) -> Option<&Expr> {
self.function.as_ref()
pub fn set_function(&mut self, func: Expr) {
pub fn with_doc(mut self, doc: impl Into<String>) -> Self {
self.doc = Some(doc.into());
pub fn doc(&self) -> Option<&str> {
self.doc.as_deref()
pub fn set_doc(&mut self, doc: impl Into<String>) {
pub fn get_property(&self, key: &str) -> Option<&Expr> {
self.properties.get(key)
pub fn set_property(&mut self, key: impl Into<String>, value: Expr) {
self.properties.insert(key.into(), value);
pub fn remove_property(&mut self, key: &str) -> Option<Expr> {
self.properties.remove(key)
pub fn properties(&self) -> &HashMap<String, Expr> {
&self.properties