Skip to main content

Multi

Struct Multi 

Source
pub struct Multi<LS: Languages, MS: MetaLanguages> {
    pub langs: LS,
    pub metas: MS,
    pub machines: Park,
}

Fields§

§langs: LS§metas: MS§machines: Park

Live default machines, one per language, spawned on first use by machine — so successive reduces share definitions for as long as this Multi lives. See docs/design/machines.md.

Implementations§

Source§

impl<LS: Languages, MS: MetaLanguages> Multi<LS, MS>

Source

pub fn get_lang(&self, lang: &str) -> Result<&LS::Language>

Source

pub fn get_lang_mut(&mut self, lang: &str) -> Result<&mut LS::Language>

Source

pub fn get_meta(&self, lang: &str) -> Result<&MS::MetaLanguage>

Source

pub fn get_meta_mut(&mut self, lang: &str) -> Result<&mut MS::MetaLanguage>

Source

pub fn lift_str(&self, lang: &str, target: &str) -> Result<&'static str>

Source

pub fn reduce_str(&self, lang: &str, target: &str) -> Result<&'static str>

Source

pub fn reduce_method_str( &self, lang: &str, target: &str, ) -> Result<&'static str>

Source

pub fn emit_str(&self, lang: &str) -> Result<&'static str>

Source

pub fn prelude(&self, lang: &str, targets: &[&str]) -> Result<Option<Prelude>>

The runtime import a file expanded with lang’s meta must open with (issue #274), given the object languages it may lift into. See MetaLanguage::prelude.

Source

pub fn prelude_for(&self, chain: &[&str], input: &str) -> Option<Prelude>

The runtime import the file expanded from input under chain (ground language first) should open with, or None (issue #274). Paired with with_prelude, this is what quilt expand writes, and what the in-browser expander (quilt-expand-wasm) writes too, so a generated module is runnable whichever of them produced it.

None for a host whose meta needs none (nix, lean and text generate no runtime calls at all), and by the two rules that keep the injection from becoming a footgun:

  • The source uses no Quilt construct. examples/hello.rs.quilt expands to itself and must stay import-free: Rust tolerates an unused glob silently, but a Python or TypeScript linter will not.
  • The author already imported the runtime. Two identical globs are harmless in Rust and Python, but a doubled named import is a hard error in TypeScript — so this is checked rather than assumed. See Prelude::present_in.

The targets the meta is asked about — which only a target-directed host like TypeScript reads — are the language chain plus every annotation the source’s quotes name, so that a sql↖…↗ inside a .rs.quilt counts even though the chain never mentions SQL. It over-approximates: a language listed but never lifted into costs an unused name, one missing costs a name that is not in scope.

Source

pub fn type_str(&self, lang: &str) -> Result<&'static str>

Source

pub fn name_str(&self, lang: &str) -> Result<&'static str>

Source

pub fn type_method_str(&self, lang: &str) -> Result<&'static str>

Source

pub fn spawn_str(&self, lang: &str, target: &str) -> Result<String>

Source

pub fn spawn_machine(&self, lang: &str) -> Result<Box<dyn Machine>>

Spawn a fresh machine for lang: the persistent ReplMachine when the language declares a repl_spec, else the replay-based ScriptMachine from its machine_spec. The caller owns it: nothing is parked, so it shares state with no other machine.

Source

pub fn machine(&mut self, lang: &str) -> Result<&mut dyn Machine>

The default machine for lang: parked in machines, spawned on first use, shared by every caller of this Multi — which is what lets one reduce see the definitions another fed. Keyed by the canonical language name, so aliases (py / python) share one machine.

Source

pub fn feed_on( &mut self, lang: &str, kind: InnerKind, src: &str, ) -> Result<Answer>

The end-user text door (tenet 2’s actual subject): parse src as kind with lang’s Language — validating it — then feed the term to the default machine. Machines themselves traffic only in terms; raw text is turned into a term here, where the parser lives.

Source

pub fn eval_on(&mut self, lang: &str, term: &QTerm) -> Result<Arc<QTerm>>

Evaluate a term on lang’s default machine and parse the answered literal back into a term of lang — machines answer with the value’s own syntax, and the Language re-reads it here, where it lives.

Source

pub fn classify_for_feed(&self, lang: &str, term: &QTerm) -> Result<InnerKind>

Classify a term for feeding a machine — which message sort it is — seeing through the tagless root wrapper parse_chain builds around a parsed fragment (whose tag would otherwise classify by the language’s default). The REPL and the notebook both route feeds through this.

Source

pub fn parse(&mut self, s: &str) -> Result<Arc<QTerm>>

Source

pub fn parse_lang(&mut self, lang: &str, s: &str) -> Result<Arc<QTerm>>

Source

pub fn parse_chain(&mut self, chain: &[&str], s: &str) -> Result<Arc<QTerm>>

Parse s whose language is given by a chain of file extensions: the host (ground) language first, then the default language for successively nested un-annotated ↖…↗ quotes. This comes from a file name like shaders.wgsl.rs.quilt (chain ["rs", "wgsl"]): Rust is the host and a bare ↖…↗ defaults to WGSL. A single-element chain (["rs"]) is the plain foo.rs.quilt case where bare quotes default to the host.

Source

pub fn build_nodes( &mut self, builder: QTermBuilder, hole: &Hole, nodes: &[Arc<Node>], zipper: &Zipper<Box<str>>, splice_target: Option<&str>, enclosing: Option<(&str, Repr)>, bracketed: bool, sky_depth: usize, ) -> Result<QTermBuilder>

Build a QTerm from quilt Nodes. splice_target is the language the fragment’s value will be spliced into: Some only for unquote bodies (the lang of the enclosing quote), None otherwise. It directs ↑ — a lift inside wgsl↖ … ↙x.↑↘ … ↗ targets WGSL; elsewhere a lift is homogeneous (targets the fragment’s own language). bracketed is true when nodes is the body of a ↖…↗/↙…↘ pair and false at the top level: only bracketed bodies get their boundary newlines trimmed. sky_depth is the net quote nesting (quotes minus unquotes) at this level: 0 at ground, +1 per enclosing quote, −1 per enclosing unquote. An operator (↑/↓/←) at sky depth > 0 runs at a later stage, so it is deferred (emitted as the glyph) rather than spelled out now. enclosing is the language and Repr of the nearest quote around nodes (None at the top): a bare quote inside its unquotes inherits its representation, and a ↑/← there spells that representation’s.

Source

pub fn expand(&mut self, qterm: &QTerm) -> Result<Arc<QTerm>>

Source

pub fn expand_lang(&mut self, lang: &str, qterm: &QTerm) -> Result<Arc<QTerm>>

Source§

impl Multi<DictLanguages, DictMetaLanguages>

Source

pub fn add_lang( &mut self, lang: &str, language: <DictLanguages as Languages>::Language, )

Source

pub fn add_meta( &mut self, lang: &str, meta: <DictMetaLanguages as MetaLanguages>::MetaLanguage, )

Source

pub fn add_alias(&mut self, alias: &str, canonical: &str)

Register alias as an alternate name for canonical in both the language and meta-language registries. Lookups under the alias resolve to the canonical entry’s instance (no entry there → “not found”).

Trait Implementations§

Source§

impl<LS: Default + Languages, MS: Default + MetaLanguages> Default for Multi<LS, MS>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<LS, MS> !RefUnwindSafe for Multi<LS, MS>

§

impl<LS, MS> !Sync for Multi<LS, MS>

§

impl<LS, MS> !UnwindSafe for Multi<LS, MS>

§

impl<LS, MS> Forget for Multi<LS, MS>

§

impl<LS, MS> Freeze for Multi<LS, MS>
where LS: Freeze, MS: Freeze,

§

impl<LS, MS> Move for Multi<LS, MS>

§

impl<LS, MS> Send for Multi<LS, MS>
where MS: Send, LS: Send,

§

impl<LS, MS> Unpin for Multi<LS, MS>
where MS: Unpin, LS: Unpin,

§

impl<LS, MS> UnsafeUnpin for Multi<LS, MS>
where LS: UnsafeUnpin, MS: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> QLiftTo for T
where T: ?Sized,

Source§

fn qlift_to<L>(&self) -> Arc<QTerm> ⓘ
where Self: LiftTo<L>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more