Skip to main content

MacroExpander

Struct MacroExpander 

Source
pub struct MacroExpander { /* private fields */ }
Expand description

The macro expansion engine.

Maintains a registry of macro definitions and provides expansion services.

Implementations§

Source§

impl MacroExpander

Source

pub fn new() -> Self

Create a new macro expander.

Source

pub fn set_max_depth(&mut self, depth: u32)

Set the maximum expansion depth.

Source

pub fn fresh_scope(&mut self) -> u64

Generate a fresh scope id for hygiene.

Source

pub fn register_macro(&mut self, def: MacroDef)

Register a macro definition.

Source

pub fn unregister_macro(&mut self, name: &str) -> Option<MacroDef>

Unregister a macro by name.

Source

pub fn has_macro(&self, name: &str) -> bool

Check whether a macro with the given name is registered.

Source

pub fn get_macro(&self, name: &str) -> Option<&MacroDef>

Get a macro definition by name.

Source

pub fn macro_count(&self) -> usize

Get the number of registered macros.

Source

pub fn register_syntax(&mut self, def: SyntaxDef)

Register a syntax definition.

Source

pub fn syntax_defs_for(&self, kind: &SyntaxKind) -> Vec<&SyntaxDef>

Get all syntax definitions for a given kind.

Source

pub fn expand( &mut self, name: &str, input: &[Token], ) -> Result<Vec<Token>, MacroError>

Expand a macro invocation.

Looks up the macro by name, tries each rule in order, and returns the expanded token sequence on the first match.

Source

pub fn macro_names(&self) -> Vec<&str>

List all registered macro names.

Trait Implementations§

Source§

impl Default for MacroExpander

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.