pub trait MetaLanguage {
Show 21 methods
// Required methods
fn expand_quote(
&self,
lang1: &str,
tag: &str,
i: Index,
lang2: &str,
qterm: &Arc<QTerm>,
cmds: &[CmdOrHole],
) -> Result<Arc<QTerm>>;
fn expand_unquote(
&self,
lang1: &str,
tag: &str,
i: Index,
lang2: &str,
qterm: &Arc<QTerm>,
cmds: &[CmdOrHole],
) -> Result<Arc<QTerm>>;
fn expand_tuple(
&self,
lang1: &str,
tag: &str,
qterms: &[Arc<QTerm>],
cmds: &[CmdOrHole],
arity: Arity,
) -> Result<Arc<QTerm>>;
// Provided methods
fn wrap_child(
&self,
qterm: Arc<QTerm>,
_okind: OuterKind,
) -> Result<Arc<QTerm>> { ... }
fn wrap_separated(
&self,
qterm: Arc<QTerm>,
_sep: &str,
) -> Result<Arc<QTerm>> { ... }
fn pattern_tag(&self) -> Option<&'static str> { ... }
fn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)> { ... }
fn pattern_var(&self, name: &str) -> Result<Arc<QTerm>> { ... }
fn pattern_let(
&self,
names: &[Box<str>],
pattern: &Arc<QTerm>,
value: &Arc<QTerm>,
) -> Result<(Arc<QTerm>, Arc<QTerm>)> { ... }
fn lift_str(&self, target: &str) -> Result<&'static str> { ... }
fn reduce_str(&self, target: &str) -> Result<&'static str> { ... }
fn reduce_method_str(&self, target: &str) -> Result<&'static str> { ... }
fn emit_str(&self) -> Result<&'static str> { ... }
fn lift_str_in(&self, target: &str, repr: Repr) -> Result<&'static str> { ... }
fn emit_str_in(&self, repr: Repr) -> Result<&'static str> { ... }
fn expand_flat(
&self,
repr: Repr,
lang2: &str,
pieces: &[Piece],
) -> Result<Arc<QTerm>> { ... }
fn type_str(&self) -> Result<&'static str> { ... }
fn name_str(&self) -> Result<&'static str> { ... }
fn type_method_str(&self) -> Result<&'static str> { ... }
fn spawn_str(&self, lang: &str) -> Result<String> { ... }
fn prelude(&self, targets: &[&str]) -> Option<Prelude> { ... }
}Required Methods§
fn expand_quote( &self, lang1: &str, tag: &str, i: Index, lang2: &str, qterm: &Arc<QTerm>, cmds: &[CmdOrHole], ) -> Result<Arc<QTerm>>
fn expand_unquote( &self, lang1: &str, tag: &str, i: Index, lang2: &str, qterm: &Arc<QTerm>, cmds: &[CmdOrHole], ) -> Result<Arc<QTerm>>
fn expand_tuple( &self, lang1: &str, tag: &str, qterms: &[Arc<QTerm>], cmds: &[CmdOrHole], arity: Arity, ) -> Result<Arc<QTerm>>
Provided Methods§
Sourcefn wrap_child(&self, qterm: Arc<QTerm>, _okind: OuterKind) -> Result<Arc<QTerm>>
fn wrap_child(&self, qterm: Arc<QTerm>, _okind: OuterKind) -> Result<Arc<QTerm>>
Wrap an expanded child of a tuple.
qterm- the child term to wrapokind- an outer kind like splice/emit/none
Sourcefn wrap_separated(&self, qterm: Arc<QTerm>, _sep: &str) -> Result<Arc<QTerm>>
fn wrap_separated(&self, qterm: Arc<QTerm>, _sep: &str) -> Result<Arc<QTerm>>
Wrap an already-wrapped splice into a
comma-separated list ([↙xs↘], f(↙xs↘)) so that the elements it
contributes are separated by sep (#293): the builder’s
sep(..)/end_sep() region around the child.
The default leaves the child alone, for a meta whose builder has no such region.
Sourcefn pattern_tag(&self) -> Option<&'static str>
fn pattern_tag(&self) -> Option<&'static str>
The ground-tuple tag that introduces a pattern-let (e.g. Rust’s
let_declaration), or None if this meta-language has no pattern
matching. A ground tuple with this tag whose binding position holds a
quote is expanded as let ↖pattern↗ = value; (see
Expander::expand_pattern_let and crate::qmatch).
Sourcefn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)>
fn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)>
Where the pattern and value sit among the children of a
pattern_tag tuple, as (pattern_ix, value_ix).
The expander used to hardcode this: it scanned for a child tagged
literally "=" and took the pattern from terms[1]. Both assumptions are
Rust’s, sitting in the language-agnostic core — so a host whose binding
form uses := or <- could not have pattern-lets even after supplying a
pattern_tag, and let mut ↖p↗ = v (where mutable_specifier shifts the
pattern off index 1) silently expanded to Rust that does not compile
(issue #174, finding E3).
None means this tuple is not a pattern-let, so the expander treats it as
an ordinary ground tuple. Implementations will usually delegate to
crate::qmatch::pattern_binding_at with their separator token.
Sourcefn pattern_var(&self, name: &str) -> Result<Arc<QTerm>>
fn pattern_var(&self, name: &str) -> Result<Arc<QTerm>>
Code for a pattern metavariable: the expression spliced where ↙name↘
sits inside a pattern quote (e.g. mvar("name") for Rust).
Sourcefn pattern_let(
&self,
names: &[Box<str>],
pattern: &Arc<QTerm>,
value: &Arc<QTerm>,
) -> Result<(Arc<QTerm>, Arc<QTerm>)>
fn pattern_let( &self, names: &[Box<str>], pattern: &Arc<QTerm>, value: &Arc<QTerm>, ) -> Result<(Arc<QTerm>, Arc<QTerm>)>
The two terms a pattern-let rewrites to: the destructuring binder that
replaces the pattern quote (e.g. [a, b]) and the matching call that
replaces the initializer (e.g. qmatch_n(&*<pattern>, &<value>)).
Sourcefn lift_str(&self, target: &str) -> Result<&'static str>
fn lift_str(&self, target: &str) -> Result<&'static str>
The spelling ↑ expands to when lifting into the object language
target (e.g. Rust lifting a value into a WGSL term). The homogeneous
case is target == the meta-language’s own language; the default
ignores target, preserving that behavior for metas without
heterogeneous support.
Sourcefn reduce_str(&self, target: &str) -> Result<&'static str>
fn reduce_str(&self, target: &str) -> Result<&'static str>
The spelling ↓ expands to when reducing with meta-language target
(e.g. py↓ inside a Rust meta-program invokes Python evaluation).
The homogeneous case is target == "" (no annotation); the default
ignores target, preserving existing behavior for metas without
heterogeneous support.
Sourcefn reduce_method_str(&self, target: &str) -> Result<&'static str>
fn reduce_method_str(&self, target: &str) -> Result<&'static str>
The spelling ↓ expands to in method position — the glyph flush
against an argument list, recv.↓(term): a bare method name, which
the source’s own parentheses complete. This is machine-directed
reduce (db.↓(schema) evaluates a term on a machine value, issue
#268), so hosts spell it as their machine-eval method.
The default is an error, but unlike the other spellings it is not the
end of the line: a host that returns one has not opted into the
method-position reading, so the expander falls back to the operator
spelling — the meaning a flush ( had before this rule existed, and
still the right one for gen(7).↓(6) in TypeScript, which reduces a
generated function and calls it. Only a host that answers the
un-annotated case and then refuses an annotated one gets its error
surfaced.
Sourcefn emit_str(&self) -> Result<&'static str>
fn emit_str(&self) -> Result<&'static str>
The spelling ← expands to. Like Self::lift_str this returns a
Result because not every meta-language has an emit: a string-based
meta (nix, lean) has no b_ accumulator to emit into, and must fail
loudly rather than leak the EMIT placeholder into generated code.
Sourcefn lift_str_in(&self, target: &str, repr: Repr) -> Result<&'static str>
fn lift_str_in(&self, target: &str, repr: Repr) -> Result<&'static str>
The spelling ↑ expands to inside an unquote of a quote with
representation repr (ts⟨str⟩↖ … ↙↑(x)↘ … ↗), where the lifted value
must be of that representation. Repr::Cst is Self::lift_str.
Sourcefn emit_str_in(&self, repr: Repr) -> Result<&'static str>
fn emit_str_in(&self, repr: Repr) -> Result<&'static str>
The spelling ← expands to inside an unquote of a quote with
representation repr. Repr::Cst is Self::emit_str.
Sourcefn expand_flat(
&self,
repr: Repr,
lang2: &str,
pieces: &[Piece],
) -> Result<Arc<QTerm>>
fn expand_flat( &self, repr: Repr, lang2: &str, pieces: &[Piece], ) -> Result<Arc<QTerm>>
Code that builds a quote’s value in representation repr — ⟨str⟩ or
⟨qt⟩; ⟨cst⟩ quotes go through Self::expand_quote and friends —
from its flattened pieces. lang2 is the quoted language.
Sourcefn type_str(&self) -> Result<&'static str>
fn type_str(&self) -> Result<&'static str>
The spelling ⟨T⟩ expands to: the type of a quilt term in this host’s
meta-code (Arc<QTerm> for Rust). Result because a host language
without a way to write types has no spelling for it.
Sourcefn name_str(&self) -> Result<&'static str>
fn name_str(&self) -> Result<&'static str>
The spelling ⟨N⟩ expands to: the function taking a string to an
identifier term (name for Rust). In a string-based meta a name is its
own text, so this is the host’s identity function.
Sourcefn type_method_str(&self) -> Result<&'static str>
fn type_method_str(&self) -> Result<&'static str>
The spelling ⟨T⟩ expands to in method position — the glyph flush
against an argument list, db.⟨T⟩(term): the machine’s typing
judgment, the companion of Self::reduce_method_str’s value
judgment (issue #273). A bare method name, completed by the source’s
own parentheses; ⟨T⟩ anywhere else keeps meaning the term type.
Falls back to Self::type_str on Err, for the same reason
Self::reduce_method_str falls back to the operator spelling.
Sourcefn spawn_str(&self, lang: &str) -> Result<String>
fn spawn_str(&self, lang: &str) -> Result<String>
The spelling lang⟨M⟩ expands to: an expression obtaining a machine
speaking lang (issue #273). The annotation is already resolved by
the expander, so lang is a concrete language name — which is why
this is the one spelling that is not a &'static str.
The default is an honest error naming what would unblock it, like every other spelling a host may lack: a string-based meta (nix, lean) has no runtime to hold a machine handle, so it needs the out-of-process daemon from issue #268 rather than a spelling.
Sourcefn prelude(&self, targets: &[&str]) -> Option<Prelude>
fn prelude(&self, targets: &[&str]) -> Option<Prelude>
What must be in scope for the code this meta generates: the runtime
import an expanded file opens with (issue #274). None — the default —
means this host needs none.
It belongs here rather than on Language
because the import exists to satisfy the expander’s output, and the
output vocabulary is the meta’s business: ops.rs is what decides a
quote becomes tb("block").c(…). A quotable-only target (wgsl, html,
sql, the shells) has no meta and needs no prelude, and a string-based
meta (nix, lean, text) calls no runtime at all, so both get the right
answer from this default.
targets are the object languages the file may lift into — the file’s
language chain plus every annotation its quotes name. Rust and Python
ignore them and return one glob import; TypeScript, whose lift spelling
is target-directed (see Self::lift_str), builds its named import
list from them, which is the half of this that a human gets wrong.
The injection itself belongs to what writes the file — quilt expand,
quilt run and the in-browser expander, through
Multi::prelude_for and
with_prelude — not to expansion: a prelude is a property of the
file written, not of the term, so quilt check stays a pure
parse-and-expand and the expander snapshots do not carry it.
Trait Implementations§
Source§impl MetaLanguage for Box<dyn MetaLanguage>
impl MetaLanguage for Box<dyn MetaLanguage>
fn expand_quote( &self, lang1: &str, tag: &str, i: Index, lang2: &str, qterm: &Arc<QTerm>, cmds: &[CmdOrHole], ) -> Result<Arc<QTerm>>
fn expand_unquote( &self, lang1: &str, tag: &str, i: Index, lang2: &str, qterm: &Arc<QTerm>, cmds: &[CmdOrHole], ) -> Result<Arc<QTerm>>
fn expand_tuple( &self, lang1: &str, tag: &str, qterms: &[Arc<QTerm>], cmds: &[CmdOrHole], arity: Arity, ) -> Result<Arc<QTerm>>
Source§fn wrap_child(&self, qterm: Arc<QTerm>, okind: OuterKind) -> Result<Arc<QTerm>>
fn wrap_child(&self, qterm: Arc<QTerm>, okind: OuterKind) -> Result<Arc<QTerm>>
Source§fn pattern_tag(&self) -> Option<&'static str>
fn pattern_tag(&self) -> Option<&'static str>
let_declaration), or None if this meta-language has no pattern
matching. A ground tuple with this tag whose binding position holds a
quote is expanded as let ↖pattern↗ = value; (see
Expander::expand_pattern_let and crate::qmatch).Source§fn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)>
fn pattern_binding(&self, terms: &[Arc<QTerm>]) -> Option<(usize, usize)>
pattern_tag tuple, as (pattern_ix, value_ix). Read moreSource§fn pattern_var(&self, name: &str) -> Result<Arc<QTerm>>
fn pattern_var(&self, name: &str) -> Result<Arc<QTerm>>
↙name↘
sits inside a pattern quote (e.g. mvar("name") for Rust).Source§fn pattern_let(
&self,
names: &[Box<str>],
pattern: &Arc<QTerm>,
value: &Arc<QTerm>,
) -> Result<(Arc<QTerm>, Arc<QTerm>)>
fn pattern_let( &self, names: &[Box<str>], pattern: &Arc<QTerm>, value: &Arc<QTerm>, ) -> Result<(Arc<QTerm>, Arc<QTerm>)>
[a, b]) and the matching call that
replaces the initializer (e.g. qmatch_n(&*<pattern>, &<value>)).Source§fn lift_str(&self, target: &str) -> Result<&'static str>
fn lift_str(&self, target: &str) -> Result<&'static str>
↑ expands to when lifting into the object language
target (e.g. Rust lifting a value into a WGSL term). The homogeneous
case is target == the meta-language’s own language; the default
ignores target, preserving that behavior for metas without
heterogeneous support.Source§fn reduce_str(&self, target: &str) -> Result<&'static str>
fn reduce_str(&self, target: &str) -> Result<&'static str>
↓ expands to when reducing with meta-language target
(e.g. py↓ inside a Rust meta-program invokes Python evaluation).
The homogeneous case is target == "" (no annotation); the default
ignores target, preserving existing behavior for metas without
heterogeneous support.Source§fn reduce_method_str(&self, target: &str) -> Result<&'static str>
fn reduce_method_str(&self, target: &str) -> Result<&'static str>
↓ expands to in method position — the glyph flush
against an argument list, recv.↓(term): a bare method name, which
the source’s own parentheses complete. This is machine-directed
reduce (db.↓(schema) evaluates a term on a machine value, issue
#268), so hosts spell it as their machine-eval method. Read moreSource§fn emit_str(&self) -> Result<&'static str>
fn emit_str(&self) -> Result<&'static str>
← expands to. Like Self::lift_str this returns a
Result because not every meta-language has an emit: a string-based
meta (nix, lean) has no b_ accumulator to emit into, and must fail
loudly rather than leak the EMIT placeholder into generated code.Source§fn lift_str_in(&self, target: &str, repr: Repr) -> Result<&'static str>
fn lift_str_in(&self, target: &str, repr: Repr) -> Result<&'static str>
↑ expands to inside an unquote of a quote with
representation repr (ts⟨str⟩↖ … ↙↑(x)↘ … ↗), where the lifted value
must be of that representation. Repr::Cst is Self::lift_str.Source§fn emit_str_in(&self, repr: Repr) -> Result<&'static str>
fn emit_str_in(&self, repr: Repr) -> Result<&'static str>
← expands to inside an unquote of a quote with
representation repr. Repr::Cst is Self::emit_str.Source§fn expand_flat(
&self,
repr: Repr,
lang2: &str,
pieces: &[Piece],
) -> Result<Arc<QTerm>>
fn expand_flat( &self, repr: Repr, lang2: &str, pieces: &[Piece], ) -> Result<Arc<QTerm>>
repr — ⟨str⟩ or
⟨qt⟩; ⟨cst⟩ quotes go through Self::expand_quote and friends —
from its flattened pieces. lang2 is the quoted language.Source§fn type_str(&self) -> Result<&'static str>
fn type_str(&self) -> Result<&'static str>
⟨T⟩ expands to: the type of a quilt term in this host’s
meta-code (Arc<QTerm> for Rust). Result because a host language
without a way to write types has no spelling for it.Source§fn name_str(&self) -> Result<&'static str>
fn name_str(&self) -> Result<&'static str>
⟨N⟩ expands to: the function taking a string to an
identifier term (name for Rust). In a string-based meta a name is its
own text, so this is the host’s identity function.Source§fn type_method_str(&self) -> Result<&'static str>
fn type_method_str(&self) -> Result<&'static str>
⟨T⟩ expands to in method position — the glyph flush
against an argument list, db.⟨T⟩(term): the machine’s typing
judgment, the companion of Self::reduce_method_str’s value
judgment (issue #273). A bare method name, completed by the source’s
own parentheses; ⟨T⟩ anywhere else keeps meaning the term type. Read moreSource§fn spawn_str(&self, lang: &str) -> Result<String>
fn spawn_str(&self, lang: &str) -> Result<String>
lang⟨M⟩ expands to: an expression obtaining a machine
speaking lang (issue #273). The annotation is already resolved by
the expander, so lang is a concrete language name — which is why
this is the one spelling that is not a &'static str. Read moreDyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".