pipa-lang 1.0.0-alpha.1

A tiny template language
Documentation
// SPDX-FileCopyrightText: Copyright 2026 olav@occy.org
// SPDX-License-Identifier: MPL-2.0

//! Define template functions and built-in values.

use crate::lang::arity::Arity;
use crate::value::Value;
use crate::value::keys::Keys;
use crate::value::map::Map;
use crate::value::operation;
use crate::value::operation::Operation;
use crate::value::span::Span;

/// Define a custom adapter for your environment.
pub trait Adapter: core::fmt::Debug {
    fn template_source(&self) -> Option<&str> {
        None
    }

    fn template_span(&self) -> Option<Span> {
        None
    }

    fn value_get(&self, map: &Map, keys: &Keys) -> Option<Value> {
        operation::get_map_value(map, keys)
    }

    #[doc(hidden)]
    fn record_setter(&self, _: &Value) -> Result<Option<Operation>, String> {
        Ok(None)
    }

    #[doc(hidden)]
    fn record_getter(&self, _: &Value) -> Result<Option<Operation>, String> {
        Ok(None)
    }

    #[doc(hidden)]
    fn record_operation(&self, _: &Operation) -> Result<(), String> {
        Ok(())
    }

    #[doc(hidden)]
    fn erase_operation(&self, _: &Value) -> Result<Vec<Operation>, String> {
        Ok(Vec::default())
    }

    fn func_find(&self, _: &[u8]) -> Option<Arity> {
        None
    }

    fn func_call(&self, _: &[u8], _: Vec<Option<Value>>) -> Result<Option<Value>, String> {
        Ok(None)
    }
}

/// A default noop-y adapter for simple scenarios.
#[derive(Debug, Default)]
pub struct Default {
    _private: (),
}

impl super::Adapter for Default {}