pub struct Field<'a> { /* private fields */ }Expand description
A field of a node kind: a label its children carry, the kinds it can
hold, and how many (see Language::fields).
§Examples
use lang_forge::{Cardinality, Language};
let lang = Language::from_lsf(
"[sketch]\nformat = 2\n[language]\nname = \"x\"\nversion = \"1.0.0\"\n\
[rules]\npair = \"key:IDENT '=' value:(NUMBER | IDENT)\"\n",
)?;
let pair = lang.kind("pair").expect("a rule");
let value = lang.fields(pair).find(|f| f.name() == "value").expect("labelled");
assert_eq!(value.cardinality(), Cardinality::One);
let kinds: Vec<&str> = value.kinds().map(|k| lang.kind_name(k)).collect();
assert_eq!(kinds, ["IDENT", "NUMBER"]);
assert_eq!(lang.label_name(value.label()), Some("value"));Implementations§
Source§impl<'a> Field<'a>
impl<'a> Field<'a>
Sourcepub fn label(&self) -> u16
pub fn label(&self) -> u16
The label’s id (see Language::label_id).
Sourcepub fn cardinality(&self) -> Cardinality
pub fn cardinality(&self) -> Cardinality
How many children the field holds.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Field<'a>
impl<'a> RefUnwindSafe for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnsafeUnpin for Field<'a>
impl<'a> UnwindSafe for Field<'a>
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