I may not be the first one to ask such question but I’m curious whether it is possible somehow to define a macro that could work on top of a preprocessor directive and behave syntactically exactly the same way.
Consider the following macro as an example:
macro myrept x*
{
local e
match =x , `x
\{
e equ 5
rept 0 \\{
\}
match ,
\{
e equ x
\}
rept e
}
It works just as native
rept if given a non-string expression but defaults to certain number of repetitions if a string literal is passed. This particular behaviour might be of little use but that’s just for expository purposes.
Now the macro works just fine when written this way:
myrept 'Something'
{
display '!'
}
But if we move the
{ character to the same line it will obviously fail:
myrept 'Something' {
display '!'
}
The reason is pretty straightforward:
{ token becomes part of the
x value. Now one might try to fix this by analysing separately the case when
x ends with
{. As you might guess, it fails. Say, this
match basically just gets ignored:
match { , {
{
display '!'
}
So, am I right that we can’t have a wrapper for preprocessor directives with syntactically equivalent behaviour? Or am I missing some possibility here?