Preprocessor System Proposal
mitchell
mforal.n... at gmail.com
Wed May 28 16:30:46 UTC 2008
Adrian,
I just wanted to condense a couple of earlier topics I started into a
proposal for a kind of preprocessor system.
If you weren't already aware, I'm interning at Ohloh this summer for
Google summer of Code and we've been very impressed with Ragel over
the last few weeks. I've talked with the project leaders about the
problems I've run into (discussed in my topics here), and they're very
interested in a solution -- even offering incentives (though they
wouldn't divulge any details).
My first problem was the multiple inclusions of the same file. My
second problem was duplicate 'write' statements I want to perform
conditionally. I believe both can be solved by a preprocessor system.
I'm no expert with Ragel's source code, but I think I may have an idea
of how this can be implemented.
In rlscan.rl's 'section_parse' machine we can add some preprocessor
statements. All I was thinking of for now was 'define' and 'if'. Each
would have an "action" comprised of C code that is executed. 'define'
would have nothing after the "action", so something like:
define { int foo = 1; };
would suffice.
The 'if' statement would be slightly more complicated. There are two
ideas I had on structure:
Idea #1:
if { foo } {
include 'some_file.rl';
write 'something';
# do other things conditionally
}
So this 'if' acts like the 'when' conditional, but the block of
Ragel *after* the "action" is parsed if "action" evaluates to true.
Idea #2:
{
include 'some_file.rl';
write 'something';
# do other things conditionally
} when { foo };
In this case we don't need an 'if', but use the existing 'when'
keyword. This might be easier to implement, but could be a strange
read to developers browsing Ragel code.
Either way we will need to parse the Ragel inside the { }'s using the
'main' machine which will be modified to contain this preprocessor
system.
Overall I think this system using the embedded C statements would be
much easier than keeping a list of defines in the Ragel source code
and writing your own preprocessor executor for an 'if' statement. I
think it will also provide for more flexibility.
Thanks for your time,
More information about the ragel-users
mailing list