Open tchebb opened 6 years ago
So you would do something like:
remake! {
let digit = \d
let block = repeat(digit, 3)
sep(repeat(block, 4), '.')
}
And it would return a RegExp AST?
I don't know much about proc macros, but assuming the remake tokens are a subset of Rust's tokens I think this should be as simple as putting them through a translation shim to emit some src/lex.rs:Token
s.
@tekknolagi, I can think of four possible return types Result<Remake, remake::Error>
, Result<Regex, remake::Error>
, Remake
, and Regex
. If we didn't return Results
we would want to just cause the build to fail with a nice error message. I think that use case might be common enough that it would be worth doing and just saying to use the Remake::new
constructor if you want more control.
I think returning a Remake
or failing build is reasonable. There's no point deferring checks to run-time in a language that can do them at compile-time.
Here is an example: https://maud.lambda.xyz/
Cool! If you want to start looking into the proc macro API, this could be a good feature to sink your teeth into. I think you would mostly just have to take the token stream that rust gives you and translate it into something that impls Iterator<Item=Spanned<Token<'input>, usize, InternalError>>
just like src/lex.rs:Lexer
Would allow the syntax tree to be parsed at compile-time and make the DSL a bit more ergonomic.
#zerocostabstractions