Boost logo

Boost :

From: HartmutKaiser_at_[hidden]
Date: 2002-01-17 13:27:19


Vladimir Prus wrote:

> "-bar" can be interpreted, depending on the styles user wants
> as either:
> 1) Three short options
> 2) Short option followed by parameter
> 3) Long option
> Can you give an *example* of how this can be handled with Spirit.

   char const *option_to_parse = "-your_option_here";
   char const *end_of_option = option_to_parse+strlen(option_to_parse);

// 1) Three short options
   char const *options = "abcdefg"; // your allowed short option
letters here
   ('-' >> +chset<>(options)).parse(option_to_parse, end_of_option);

i.e. a dash followed by one or more characters (see the '+') from the
given character set

// 2) Short option followed by parameter
   ('-' >> chset<>(options) >> *(anychar -
space)).parse(option_to_parse, end_of_option);

i.e. a dash followed by one character from the given set and 0 or more
arbitrary characters (all but space, see the '*' == Kleene star)

// 3) Long option
   symbol<> long_opt;
   long_opt = "foo", "bar", "etc", "your_long_options_here";
   ('-' >> long_opt).parse(option_to_parse, end_of_option);

i.e. a dash followd by a character sequence from the given symbol set

:-)
Regards Hartmut


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk