Skip to main content

Mapping

Struct Mapping 

Source
pub struct Mapping<K> { /* private fields */ }
Expand description

A language’s semantics as data: what each node kind means, what each token is, which operators map to what, and the templates for sugar.

§Examples

use lower_lang::{Arch, MappingBuilder, Pick, TokenRole};

const IDENT: u8 = 1;
const LET: u8 = 2;
let mut b = MappingBuilder::new();
b.token(IDENT, TokenRole::Name);
b.node(LET, Arch::Let {
    pat: Pick::Kind(IDENT),
    ty: Pick::Absent,
    init: Pick::Back(0),
    else_: Pick::Absent,
    mutable: false,
    hoist: false,
});
let mapping = b.build()?;
assert_eq!(mapping.role_for(&IDENT), Some(TokenRole::Name));
assert!(mapping.rule_for(&LET).is_some());

Implementations§

Source§

impl<K: Copy + Ord> Mapping<K>

Source

pub fn rule_for(&self, kind: &K) -> Option<&Arch<K>>

The archetype of the first rule registered for kind.

§Examples
use lower_lang::{Arch, MappingBuilder};

let mut b = MappingBuilder::<u8>::new();
b.node(3, Arch::binary());
let m = b.build()?;
assert_eq!(m.rule_for(&3), Some(&Arch::binary()));
assert_eq!(m.rule_for(&4), None);
Source

pub fn role_for(&self, kind: &K) -> Option<TokenRole>

The role of token kind kind.

§Examples

See Mapping.

Source

pub fn modifier_for(&self, kind: &K) -> Option<Modifier>

The modifier token kind kind stands for.

§Examples
use lower_lang::{MappingBuilder, Modifier};

let mut b = MappingBuilder::<u8>::new();
b.modifier(9, Modifier::Mut);
assert_eq!(b.build()?.modifier_for(&9), Some(Modifier::Mut));
Source

pub fn modifier_in(&self, kind: &K, archetype: &str) -> Option<Modifier>

The modifier token kind kind stands for inside archetype archetype (its Arch::lsf_name): the per-archetype entry, else the plain one (modifier_for).

§Examples
use lower_lang::{MappingBuilder, Modifier};

const DOTS: u8 = 7;
let mut b = MappingBuilder::<u8>::new();
b.modifier_in(DOTS, "param", Modifier::Rest)
    .modifier_in(DOTS, "arg", Modifier::Spread);
let m = b.build()?;
assert_eq!(m.modifier_in(&DOTS, "param"), Some(Modifier::Rest));
assert_eq!(m.modifier_in(&DOTS, "arg"), Some(Modifier::Spread));
assert_eq!(m.modifier_in(&DOTS, "map_entry"), None);
assert_eq!(m.modifier_for(&DOTS), None);
Source

pub fn template(&self, id: TemplateId) -> Option<&Template>

The registered template id.

§Examples
use lower_lang::{templates, MappingBuilder};

let mut b = MappingBuilder::<u8>::new();
let id = b.template(templates::coalesce())?;
let m = b.build()?;
assert_eq!(m.template(id).map(|t| t.name()), Some("??"));
Source

pub const fn policy(&self) -> &LangPolicy

The language-wide policies.

§Examples
use lower_lang::{LangPolicy, MappingBuilder};

let m = MappingBuilder::<u8>::new().build()?;
assert_eq!(*m.policy(), LangPolicy::default());

Trait Implementations§

Source§

impl<K: Clone> Clone for Mapping<K>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug> Debug for Mapping<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K> Freeze for Mapping<K>
where Vec<Rule<K>>: Freeze, Vec<(K, u32)>: Freeze, Vec<(K, TokenRole)>: Freeze, Vec<(K, Modifier)>: Freeze, Vec<(K, &'static str, Modifier)>: Freeze, Vec<(K, PathRoot)>: Freeze, Vec<K>: Freeze, Vec<(K, OpSpec)>: Freeze, Vec<Pick<K>>: Freeze,

§

impl<K> RefUnwindSafe for Mapping<K>

§

impl<K> Send for Mapping<K>
where Vec<Rule<K>>: Send, Vec<(K, u32)>: Send, Vec<(K, TokenRole)>: Send, Vec<(K, Modifier)>: Send, Vec<(K, &'static str, Modifier)>: Send, Vec<(K, PathRoot)>: Send, Vec<K>: Send, Vec<(K, OpSpec)>: Send, Vec<Pick<K>>: Send,

§

impl<K> Sync for Mapping<K>
where Vec<Rule<K>>: Sync, Vec<(K, u32)>: Sync, Vec<(K, TokenRole)>: Sync, Vec<(K, Modifier)>: Sync, Vec<(K, &'static str, Modifier)>: Sync, Vec<(K, PathRoot)>: Sync, Vec<K>: Sync, Vec<(K, OpSpec)>: Sync, Vec<Pick<K>>: Sync,

§

impl<K> Unpin for Mapping<K>
where Vec<Rule<K>>: Unpin, Vec<(K, u32)>: Unpin, Vec<(K, TokenRole)>: Unpin, Vec<(K, Modifier)>: Unpin, Vec<(K, &'static str, Modifier)>: Unpin, Vec<(K, PathRoot)>: Unpin, Vec<K>: Unpin, Vec<(K, OpSpec)>: Unpin, Vec<Pick<K>>: Unpin,

§

impl<K> UnsafeUnpin for Mapping<K>

§

impl<K> UnwindSafe for Mapping<K>
where Vec<Rule<K>>: UnwindSafe, Vec<(K, u32)>: UnwindSafe, Vec<(K, TokenRole)>: UnwindSafe, Vec<(K, Modifier)>: UnwindSafe, Vec<(K, &'static str, Modifier)>: UnwindSafe, Vec<(K, PathRoot)>: UnwindSafe, Vec<K>: UnwindSafe, Vec<(K, OpSpec)>: UnwindSafe, Vec<Pick<K>>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.