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
impl MacroExpander
Sourcepub fn set_max_depth(&mut self, depth: u32)
pub fn set_max_depth(&mut self, depth: u32)
Set the maximum expansion depth.
Sourcepub fn fresh_scope(&mut self) -> u64
pub fn fresh_scope(&mut self) -> u64
Generate a fresh scope id for hygiene.
Sourcepub fn register_macro(&mut self, def: MacroDef)
pub fn register_macro(&mut self, def: MacroDef)
Register a macro definition.
Sourcepub fn unregister_macro(&mut self, name: &str) -> Option<MacroDef>
pub fn unregister_macro(&mut self, name: &str) -> Option<MacroDef>
Unregister a macro by name.
Sourcepub fn has_macro(&self, name: &str) -> bool
pub fn has_macro(&self, name: &str) -> bool
Check whether a macro with the given name is registered.
Sourcepub fn macro_count(&self) -> usize
pub fn macro_count(&self) -> usize
Get the number of registered macros.
Sourcepub fn register_syntax(&mut self, def: SyntaxDef)
pub fn register_syntax(&mut self, def: SyntaxDef)
Register a syntax definition.
Sourcepub fn syntax_defs_for(&self, kind: &SyntaxKind) -> Vec<&SyntaxDef>
pub fn syntax_defs_for(&self, kind: &SyntaxKind) -> Vec<&SyntaxDef>
Get all syntax definitions for a given kind.
Sourcepub fn expand(
&mut self,
name: &str,
input: &[Token],
) -> Result<Vec<Token>, MacroError>
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.
Sourcepub fn macro_names(&self) -> Vec<&str>
pub fn macro_names(&self) -> Vec<&str>
List all registered macro names.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MacroExpander
impl RefUnwindSafe for MacroExpander
impl Send for MacroExpander
impl Sync for MacroExpander
impl Unpin for MacroExpander
impl UnsafeUnpin for MacroExpander
impl UnwindSafe for MacroExpander
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