[][src]Trait rowan::syntax::Language

pub trait Language: Clone {
    type Kind: Debug;
    fn kind_into_raw(&self, kind: Self::Kind) -> Kind;
fn kind_from_raw(&self, kind: Kind) -> Self::Kind; fn is_token(&self, node: &Node<Self>) -> bool { ... } }

Specialization information for a particular language grammar.

Rather than be a purely typesystem-level trait where all functions are associated functions, this trait's methods take self by reference. This allows dynamic interpretation of language rules for interpreters. For the common, statically known case, you should use a ZST impl.

The language resolver must be cloneable, as all node handles have one. (As such, it should also be small and quickly cloneable – Rc level.) If at all possible, it should be a Copy handle and only usize big.

Associated Types

type Kind: Debug

A typed kind to identify the kind of a node in the tree.

The kind must be representable as a raw u16, but may use an arbitrarily complex encoding if desired. This allows you to use a different kind model than rowan's fully erased storage layer.

Loading content...

Required methods

fn kind_into_raw(&self, kind: Self::Kind) -> Kind

Turn a typed kind into a raw kind.

fn kind_from_raw(&self, kind: Kind) -> Self::Kind

Turn a raw kind into a typed kind.

Loading content...

Provided methods

fn is_token(&self, node: &Node<Self>) -> bool

Determine if a node is a token.

For a node to be a token, it must be backed by a GreenToken.

By default, all GreenToken nodes are considered tokens. However, it is possible to implement delayed parsing by implementing this method to check the kind instead, and allowing non-token nodes to remain as unparsed GreenToken nodes until their content is required to be parsed.

If doing this, the root node should be stored in a cell or similar structure to allow updating it when needed. arc-swap explains the pattern here, though it uses atomic reference counting instead of nonatomic.

Loading content...

Implementors

impl Language for Generic[src]

type Kind = Kind

Loading content...