Boost logo

Boost Users :

Subject: Re: [Boost-users] How to handle blank space in parsing??
From: Marsh Ray (marsh_at_[hidden])
Date: 2011-04-24 11:45:21

On 03/07/2011 10:52 AM, Ramon F Herrera wrote:
> Boost::regex [...]
> My only problem is spaces. I design typical mini computer language
> syntaxes, for example:
> Table[1, 4] = Value AND Array[8, 4]
> My initial approach was to get rid of all spaces before parsing (I
> recall being taught ages ago that the FORTRAN compiler does just that).

Most of the world seems to prefer languages with C-like syntax.

> Such strategy works in some cases, but the above line would become:
> Table[1,4]=ValueANDArray[8,4]
> Which is obviously bad news. I solved this particular case with this
> syntax:
> Table[1, 4] = Value && Array[8, 4]
> My latest "language" looks like this and has the same problem described
> above:
> Table rows [1758, 1904, 2053, 2201, 2345, 2497]
> Table cols [372, 880, 1336, 1756, 2083, 2439]
> I guess I could insert a colon or something between the first two words,
> but I am sure there has to be a better way.

I usually just use \w+ in the pattern where there needs to be a space
and \w* in the pattern where space is optional.

E.g. "\\w*Table\\w+rows\\w*"

If you still want to continue throwing away spaces you could match for
the merged identifier possibilities:

     "Table(rows|cols)" or

- Marsh

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at