[ragel-users] Preprocessor System Proposal

Adrian Thurston thurs... at cs.queensu.ca
Wed May 28 21:14:01 UTC 2008


Hi Mitchell,

So I've been meaning to work on some kind of macro language for a long
time now, but haven't had the chance to sit down and do it. I'm hoping
in the latter part of 2008, by then I should be finished with my thesis.
I'm actually planning on using my thesis project to implement the macro
system, which is another reason I've been delaying on the macros.

The macro system needs to solve a whole lot of problems at once so I'm
expecting it to take quite a bit of research/work.

Using the C preprocessing language is attractive, but unfortunately
won't do since the general trend with ragel is language independence. We
do need something a lot like it though.

-Adrian

mitchell wrote:
> 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,
> -Mitchell;
> > 
> 



More information about the ragel-users mailing list