Closed MysteryBlokHed closed 3 years ago
I don't think the way I've gone about implementing this is this PR is the best way. I think I'll try to do something more typical to other languages, like this:
# a macro with no args
!def some_macro()
say A macro with no args
!end
# a macro with one arg
!def another_macro($arg)
say Hello, $arg!
!end
Support for string literal tokenization would also be needed, though I doubt I'll support escaping things like \n
immediately. I'll probably support multiline strings by default, without really trying to.
Macro calls could look like this:
?some_macro()
?another_macro("World")
Another idea would be to add a specific kind of file that lets you define project-wide macros. That way people could make libraries for Databind that give you macros to help development. Something like a .macros
or .m.databind
file extension could work for this.
The text replacement definitions can be useful, but adding Rust-like macros could also be useful. If you want to make a pack that lets users define their own functions to add functionality but you don't want to make them copy+paste a bunch of boilerplate, then you could use a macro to do it for them. Something like this could work:
The above could be used as something like:
The macro call would be converted to the following Databind code:
The syntax is just an idea, so there might be better ways to implement it. If this issue is closed,
!def
definitions should be removed.