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>
impl<K: Copy + Ord> Mapping<K>
Sourcepub fn rule_for(&self, kind: &K) -> Option<&Arch<K>>
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);Sourcepub fn modifier_for(&self, kind: &K) -> Option<Modifier>
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));Sourcepub fn modifier_in(&self, kind: &K, archetype: &str) -> Option<Modifier>
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);Sourcepub fn template(&self, id: TemplateId) -> Option<&Template>
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("??"));Sourcepub const fn policy(&self) -> &LangPolicy
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§
Auto Trait Implementations§
impl<K> Freeze for Mapping<K>
impl<K> RefUnwindSafe for Mapping<K>where
Vec<Rule<K>>: RefUnwindSafe,
Vec<(K, u32)>: RefUnwindSafe,
Vec<(K, TokenRole)>: RefUnwindSafe,
Vec<(K, Modifier)>: RefUnwindSafe,
Vec<(K, &'static str, Modifier)>: RefUnwindSafe,
Vec<(K, PathRoot)>: RefUnwindSafe,
Vec<K>: RefUnwindSafe,
Vec<(K, OpSpec)>: RefUnwindSafe,
Vec<Pick<K>>: RefUnwindSafe,
impl<K> Send for Mapping<K>
impl<K> Sync for Mapping<K>
impl<K> Unpin for Mapping<K>
impl<K> UnsafeUnpin for Mapping<K>where
Vec<Rule<K>>: UnsafeUnpin,
Vec<(K, u32)>: UnsafeUnpin,
Vec<(K, TokenRole)>: UnsafeUnpin,
Vec<(K, Modifier)>: UnsafeUnpin,
Vec<(K, &'static str, Modifier)>: UnsafeUnpin,
Vec<(K, PathRoot)>: UnsafeUnpin,
Vec<K>: UnsafeUnpin,
Vec<(K, OpSpec)>: UnsafeUnpin,
Vec<Pick<K>>: UnsafeUnpin,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more