Trait cstree::Language [−][src]
The Language
trait is the bridge between the internal cstree
representation and your language
types.
This is essential to providing a SyntaxNode
API that can be used with your types, as in the
s_expressions
example:
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u16)] enum SyntaxKind { ROOT, // top-level node ATOM, // `+`, `15` WHITESPACE, // whitespaces is explicit #[doc(hidden)] __LAST, } use SyntaxKind::*; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] enum Lang {} impl cstree::Language for Lang { type Kind = SyntaxKind; fn kind_from_raw(raw: cstree::SyntaxKind) -> Self::Kind { assert!(raw.0 <= __LAST as u16); unsafe { std::mem::transmute::<u16, SyntaxKind>(raw.0) } } fn kind_to_raw(kind: Self::Kind) -> cstree::SyntaxKind { cstree::SyntaxKind(kind as u16) } }
Associated Types
type Kind: Debug
[src]
A type that represents what items in your Language can be.
Typically, this is an enum
with variants such as Identifier
, Literal
, …
Required methods
fn kind_from_raw(raw: SyntaxKind) -> Self::Kind
[src]
Construct a semantic item kind from the compact representation.
fn kind_to_raw(kind: Self::Kind) -> SyntaxKind
[src]
Convert a semantic item kind into a more compact representation.