Anyone interested in a Spirit for D?

Bill Baxter wbaxter at gmail.com
Wed Oct 18 13:51:27 PDT 2006


Walter Bright wrote:
> I think it would be worth looking at again. The C# version of it doesn't 
> use operator overloading or even templates.

Huh.  Very interesting.  Here's the example:

// spirit:
num_p >> *( ch_p(',') >> num_p)

// C#
Ops.Seq( Prims.Digit, Ops.Start( Ops.Seq(Prims.Ch(','), Prims.Digit)))

Though it's definitely not as easy to read, I think I might actually 
prefer the C# version.  Part of the annoyance with Boost super-clever 
use of operator-overloading is that it can be a real pain to discover 
things because they don't have real names.

I bet the C# version could be compacted with some aliases or imports 
(assuming C# has these):
   Seq( Digit, Start( Seq(Ch(','), Digit)))

That doesn't look too bad to me.

Still it would rock the world if you could just do:
   parser("digit (',' digit)*");
and have the grammar be verified at compile-time.

> I think it would be a complete rewrite.
> 
> The reason I'm interested in it for D is that:
> 
> 1) it's a pretty cool library
> 2) it's one of Boost's most popular ones
> 3) it's been touted as a reason why D is no good and C++ roolz
> 4) it's popular enough to have been a driving force behind improvements 
> in C++ compilers
> 5) it would surely improve D
> 6) and last, and most importantly, it's very useful

Excellent reasons.

--bb



More information about the Digitalmars-d mailing list