quiltlang 0.6.0

Quilt, a polyglot metaprogramming language: source code with arrow-bracket syntax for embedding and manipulating code fragments of other languages at code-generation time.
Documentation
//! DO NOT EDIT. GENERATED BY `bootstrap`.

use super::ops::{
    build_quote_code, build_tuple_code, build_unquote_code, build_variadic_block, lift_spelling,
    pattern_let_code, pattern_var_code, prelude_spelling, reduce_method_spelling, reduce_spelling,
    spawn_spelling, type_method_spelling, wrap_emit, wrap_separated, wrap_splice,
};
use crate::lang::Arity;
use crate::meta::OuterKind;
use crate::meta::Prelude;
use crate::prelude::{Index, *};
use crate::qmatch::pattern_binding_at;
use crate::{meta::MetaLanguage, qterm::QTerm, term::CmdOrHole};

/**************************************************************/

#[derive(Default)]
pub struct RustMetaLanguage;

impl MetaLanguage for RustMetaLanguage {
    fn expand_quote(
        &self,
        _lang1: &str,
        tag: &str,
        i: Index,
        lang2: &str,
        qterm: &Arc<QTerm>,
        cmds: &[CmdOrHole],
    ) -> Result<Arc<QTerm>> {
        Ok(build_quote_code(tag, i, lang2, qterm, cmds))
    }

    fn expand_unquote(
        &self,
        _lang1: &str,
        tag: &str,
        i: Index,
        lang2: &str,
        qterm: &Arc<QTerm>,
        cmds: &[CmdOrHole],
    ) -> Result<Arc<QTerm>> {
        Ok(build_unquote_code(tag, i, lang2, qterm, cmds))
    }

    fn expand_tuple(
        &self,
        _lang1: &str,
        tag: &str,
        qterms: &[Arc<QTerm>],
        cmds: &[CmdOrHole],
        arity: Arity,
    ) -> Result<Arc<QTerm>> {
        Ok(if arity == Arity::Variadic {
            build_variadic_block(tag, cmds, qterms)
        } else {
            build_tuple_code(tag, cmds, qterms)
        })
    }

    fn wrap_child(&self, qterm: Arc<QTerm>, okind: OuterKind) -> Result<Arc<QTerm>> {
        Ok(match okind {
            OuterKind::None => qterm,
            OuterKind::Emit => wrap_emit(&qterm),
            OuterKind::Splice => wrap_splice(&qterm),
        })
    }

    fn wrap_separated(&self, qterm: Arc<QTerm>, sep: &str) -> Result<Arc<QTerm>> {
        Ok(wrap_separated(&qterm, sep))
    }

    fn pattern_tag(&self) -> Option<&'static str> {
        Some("let_declaration")
    }

    fn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)> {
        pattern_binding_at(terms, "=", Some(":"))
    }

    fn pattern_var(&self, name: &str) -> Result<Arc<QTerm>> {
        Ok(pattern_var_code(name))
    }

    fn pattern_let(
        &self,
        names: &[Box<str>],
        pattern: &Arc<QTerm>,
        value: &Arc<QTerm>,
    ) -> Result<(Arc<QTerm>, Arc<QTerm>)> {
        Ok(pattern_let_code(names, pattern, value))
    }

    fn lift_str(&self, target: &str) -> Result<&'static str> {
        lift_spelling(target)
    }

    fn reduce_str(&self, target: &str) -> Result<&'static str> {
        reduce_spelling(target)
    }

    fn reduce_method_str(&self, target: &str) -> Result<&'static str> {
        reduce_method_spelling(target)
    }

    fn name_str(&self) -> Result<&'static str> {
        Ok("name")
    }

    fn type_str(&self) -> Result<&'static str> {
        Ok("Arc<QTerm>")
    }

    fn type_method_str(&self) -> Result<&'static str> {
        type_method_spelling()
    }

    fn spawn_str(&self, lang: &str) -> Result<String> {
        spawn_spelling(lang)
    }

    fn emit_str(&self) -> Result<&'static str> {
        Ok("emit(&mut b_)")
    }

    fn prelude(&self, _targets: &[&str]) -> Option<Prelude> {
        Some(prelude_spelling())
    }
}

pub trait Lift {
    /// Lift to a `QTerm` that evaluates to the same term.
    fn lift(&self) -> Arc<QTerm>;
}

pub fn lift<T: Lift>(x: &T) -> Arc<QTerm> {
    x.lift()
}

impl Lift for i8 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}i8"))
    }
}
impl Lift for i16 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}i16"))
    }
}
impl Lift for i32 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}i32"))
    }
}
impl Lift for i64 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}i64"))
    }
}
impl Lift for i128 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}i128"))
    }
}
impl Lift for isize {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}isize"))
    }
}
impl Lift for u8 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}u8"))
    }
}
impl Lift for u16 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}u16"))
    }
}
impl Lift for u32 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}u32"))
    }
}
impl Lift for u64 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}u64"))
    }
}
impl Lift for u128 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}u128"))
    }
}
impl Lift for usize {
    fn lift(&self) -> Arc<QTerm> {
        leaf("integer_literal", &format!("{self}usize"))
    }
}
impl Lift for f32 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("float_literal", &format!("{self}f32"))
    }
}
impl Lift for f64 {
    fn lift(&self) -> Arc<QTerm> {
        leaf("float_literal", &format!("{self}f64"))
    }
}

pub fn foo() {
    let bar = 123;
    dbg!(bar);
}