Anyone interested in a Spirit for D?

Kristian kjkilpi at gmail.com
Thu Oct 19 03:00:09 PDT 2006


On Thu, 19 Oct 2006 00:12:41 +0300, Walter Bright  
<newshound at digitalmars.com> wrote:

> Bill Baxter wrote:
>> But given Don's experiments with compile-time text parsing in D, it's  
>> conceivable that in D the above parser could just be created with:
>>     r = make_parser("real_number (',' real_number)*");
>>  I.e. use the EBNF version directly in a string literal that gets  
>> parsed at compile time.
>> That would be pretty cool.
>
> Yes, it would be. But there's a catastrophic problem with it. Spirit  
> enables code snippets to be attached to terminals by overloading the []  
> operator. If the EBNF was all in a string literal, this would be  
> impossible.
>

Well, couldn't one use arrays to define actions? For example:

     r = make_parser("real_number[0] (',' real_number[1])*");

     array[] = {&firstAction,   //[0]
                &generalAction  //[1]
                };
     r.attach(array);


You could also give string ids for actions:

     r = make_parser("real_number[myaction] (',' real_number[real])*");

     array[] = {"myaction", &firstAction,
                "real", &generalAction
                };
     r.attach(array);



More information about the Digitalmars-d mailing list