Writing a Lexer with Macros
summary
Describes implementing a lexer using Rust declarative macros: the talk examines whether Rust’s macro system (which is Turing-complete) can express a complex translator by building a lex-like language entirely with macros. It covers practical challenges, unavoidable compromises, and whether a workable solution can be achieved.
AI-written summary · about
chapters (31)
- 0:00Introduction
- 0:45Why write lexer manually
- 3:14Regex overview
- 5:04Regex type in Rust
- 6:07Testing regex
- 7:11Concatenation overloading
- 7:56Problems with manual lexer
- 8:38Goal: lexer with Rust macros
- 10:44Demo: token processing
- 12:12Lexer structure
- 13:16Inspiration from RPN
- 15:11Two-stack parsing
- 16:40Macros syntax
- 19:08Base macro for tokens
- 20:35Postfix unary ops
- 23:50Sequences and repetition
- 26:23Literals and predicates
- 27:52Alternation operator
- 28:36Parentheses handling
- 30:02Simpler parentheses
- 31:26Lexer rules
- 32:48Macro for rules
- 33:30Processing lexer defs
- 34:40String literals
- 35:44NFA
- 36:30Q&A: macro optimization
- 37:11Q&A: grammar redundancy
- 38:15Q&A: procedural vs declarative
- 40:05Q&A: macro recursion
- 41:08Q&A: hybrid parsing
- 42:11Closing remarks
