Pascal Hertleif
2019-07-09
Just kidding!
This topic is way too large for this short a talk
I just don’t want to write the same code over and over again
I also like to make up abstract solution
This is a dangerous combination…
impl
A derive macro for a specialized Debug
Task: Find a pattern like fd fd ? ? df 1e
in a slice of bytes
Idea: Use regex!
But how do turn that pattern format into a valid regular expression?
With a macro of course! And so we dove into the world of macro_rules!
macros…
Problem: Can’t parse a string in pattern macros
Approach: Munch single tokens one after the other and concat to a string!
macro_rules!
Except that macros operate on Rust tokens…
error: expected at least one digit in exponent
--> src/main.rs:6:34
|
6 | byte_pattern!(fd fd ? ? df 1e)
| ^
Since function-like macros aren’t stable yet, we went for a derive
Crates that are proc-macro = true
are a bit special
For example: Adding nom as a dependency to a proc-macro crate with tests results in link error
’twas a fortnight ago, when I found myself in the peculiar situation of having written a rather complex PEG grammar, that I then had to parse into an AST of sorts…
Long story short:
pest-ast
on by reading the original grammarI’m Pascal and I want you to talk to me!
{twitter,github}.com/killercup
Slides: git.io/rust-macro-madness