Understand the Rust source analysis pipeline
mainThe process of analyzing Rust source code follows a specific sequence of stages:
- Tokenization: The source text is converted into a sequence of indivisible lexical units called tokens.
- Token Trees: Tokens are organized into a hierarchical structure of token trees based on grouping symbols.
- Parsing: The token stream is transformed into an Abstract Syntax Tree (AST), which represents the syntactic structure of the program.
- Macro Expansion: Macros are processed after the AST has been constructed (unlike C/C++, where macros are processed during tokenization).
Understanding the distinction between these stages is critical, especially when writing macros, as you must interact with both token trees and the AST.