pub struct MacroExpander<'a> {
pub lexer: Lexer<'a>,
pub mode: Mode,
/* private fields */
}Expand description
The MacroExpander (or “gullet”) manages macro expansion.
It sits between the Lexer (mouth) and the Parser (stomach). Tokens are read from the lexer, pushed onto an internal stack, and macros are expanded until only non-expandable tokens remain.
Modeled after KaTeX’s MacroExpander.ts.
Fields§
§lexer: Lexer<'a>§mode: ModeImplementations§
Source§impl<'a> MacroExpander<'a>
impl<'a> MacroExpander<'a>
pub fn new(input: &'a str, mode: Mode) -> Self
pub fn set_macro(&mut self, name: String, def: MacroDefinition)
pub fn set_macro_global(&mut self, name: String, def: MacroDefinition)
pub fn set_text_macro(&mut self, name: &str, text: &str)
pub fn get_macro(&self, name: &str) -> Option<&MacroDefinition>
Sourcepub fn expand_tokens(&mut self, tokens: Vec<Token>) -> ParseResult<Vec<Token>>
pub fn expand_tokens(&mut self, tokens: Vec<Token>) -> ParseResult<Vec<Token>>
Expand a list of tokens fully (for \edef/\xdef).
pub fn switch_mode(&mut self, new_mode: Mode)
pub fn begin_group(&mut self)
pub fn end_group(&mut self)
pub fn end_groups(&mut self)
Sourcepub fn future(&mut self) -> &Token
pub fn future(&mut self) -> &Token
Returns the topmost token on the stack, without expanding it.
Sourcepub fn set_top_text(&mut self, text: String)
pub fn set_top_text(&mut self, text: String)
Modify the top token’s text on the stack (for \global prefix handling).
Sourcepub fn push_token(&mut self, token: Token)
pub fn push_token(&mut self, token: Token)
Push a token onto the stack.
Sourcepub fn push_tokens(&mut self, tokens: Vec<Token>)
pub fn push_tokens(&mut self, tokens: Vec<Token>)
Push multiple tokens onto the stack.
Sourcepub fn consume_spaces(&mut self)
pub fn consume_spaces(&mut self)
Consume all following space tokens, without expansion.
Sourcepub fn expand_next_token(&mut self) -> ParseResult<Token>
pub fn expand_next_token(&mut self) -> ParseResult<Token>
Recursively expand the next token until a non-expandable token is found.
Sourcepub fn consume_arg(
&mut self,
delims: Option<&[&str]>,
) -> ParseResult<ConsumedArg>
pub fn consume_arg( &mut self, delims: Option<&[&str]>, ) -> ParseResult<ConsumedArg>
Consume a single argument from the token stream.
Sourcepub fn scan_argument(&mut self, is_optional: bool) -> ParseResult<Option<Token>>
pub fn scan_argument(&mut self, is_optional: bool) -> ParseResult<Option<Token>>
Scan a function argument (optional or mandatory). Pushes an EOF token to mark the end, then pushes the argument tokens.
Sourcepub fn is_defined(&self, name: &str) -> bool
pub fn is_defined(&self, name: &str) -> bool
Check if a command name is currently defined.
Sourcepub fn is_expandable(&self, name: &str) -> bool
pub fn is_expandable(&self, name: &str) -> bool
Check if a command is expandable.