From: Dan Nuffer (dnuffer_at_[hidden])
Date: 2002-01-16 13:18:41
Schoenborn, Oliver wrote:
>>From: David Abrahams [mailto:david.abrahams_at_[hidden]]
>>Sent: Tuesday, January 15, 2002 11:54 AM
>>Subject: Re: [boost] Any interest for a parser class?
>>Will you submit spirit to boost? I want to see it here; I
>>strongly believe everyone will benefit.
> Seems to me Spirit is targetted at a very special group of programmers.
Nope. Spirit is targetted at any C++ programmer who needs to do
parsing, which is most of them. Even more so now in the age of the
internet and all it's protocols which need to be parsed.
> Spirit is an impressive piece of work. So impressive, actually, that I
> don't want to use it because:
> - I need to know EBNF notation (or an approximation of it, if only to
> understand the concepts); do I really want to learn a new notation just for
> command line parsing, or even file parsing?
If a programmer doesn't know EBNF, then they are missing an important
piece of knowledge, since it's the standard for computer langauge
> - All I need is a toaster to *toast my bread*; not to also make it, tag it,
> bag it and deliver it in my plate and gauge the toasting level to the bread
> ingredients for the particular slice in the toaster.
Spirit is aimed to be a general parsing framework. It is not aimed to
be a simple command line parser. A command line parser would only
require a small portion of spirit's capabilities. And, the library is
structured in such a way, that you only pay for what you use.
I don't think that anyone is saying that having a simple to use command
line parser is a bad idea, because people should parse their own command
lines using spirit. While this is certainly possible, it makes more
sense (to me anyway) to use spirit internally for the command line
parser implementation. But, that still restricts the user to whatever
option format(s) the command line parser supports.
> In other words, perhaps for really special applications that need super
> advanced grammar (like building a compiler), Spirit would be worth the
> effort for me to learn. But frankly, a simple line parser based on
> token-parameters with error reporting is sufficient in 99% of cases, fast to
> build, extendable, robust, easy for everyone on the team to understand, even
> someone who knows little about parsing. It can't deal with grammar as
> complex what Spirit can, but so can't the average programmer.
Learning how to use spirit is no different than learning a new API or
library. Spirit makes parsing incredibly easy. Say, for instance you
had to write a function that would parse a complex number of the form:
real, (real), or (real,imaginary) and store the real and imaginary parts
in 2 doubles:
bool parse_complex(char const* str, double& real, double& imaginary);
Writing this by hand would probably take 20 lines of code or so. With
spirit, it's a one liner:
>> !(',' >> real_p[ref(imaginary)])
Well, maybe more than one line if you want it too look nice, but that's
one statement :-)