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

use crate::lang::adapter::Adapter;
use crate::lang::args::eval_args;
use crate::lang::arity::Arity;
use crate::lang::arity::assert_func_arity;
use crate::lang::error::Error;
use crate::lang::machine::Machine;
use crate::lang::node::Node;
use crate::value::Value;
use crate::value::print::quote_escaped;

pub(crate) fn quote(
    adapter: &impl Adapter,
    machine: &mut Machine<'_>,
    stdin: Option<&Value>,
    node: Node,
) -> Result<Value, Error> {
    assert_func_arity(adapter, machine, stdin, &node, &Arity::minmax(1, 2))?;

    let mut args = eval_args(adapter, machine, stdin, node)?;
    let last = args.pop().flatten().map(Value::join);
    let first = args.pop().flatten().map(Value::join);

    Ok(Value::from(match (first, last) {
        (Some(quote), Some(value)) => quote_escaped(value, &quote),
        (None, Some(value)) => quote_escaped(value, br#"""#),
        _ => Vec::default(),
    }))
}