|
Boost Users : |
Subject: Re: [Boost-users] [spirit] parsing keyword or identifier
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2011-05-02 22:18:41
> I have what I think is a simple problem: I'm trying to parse IES files,
> and there is a line that can have three options:
>
> TILT=NONE
> -or-
> TILT=INCLUDE
> -or-
> TILT=<filename>
>
> The way I'm trying to parse this line is:
>
>
> // in the case of TILT=INCLUDE or TILT=<filename>
> int lampToLuminaireGeom;
> int numPairsWithMulFactors = 0;
>
> std::string tiltFileName;
>
> BOOST_AUTO(keywordSym, (qi::lit("NONE") | qi::lit("INCLUDE")));
> BOOST_AUTO(fileName, *char_ - keywordSym);
Spirit grammars are still C++ and still obey the default C++ operator
preferences. Use this instead:
BOOST_AUTO(fileName, *(char_ - keywordSym));
and it will work.
> BOOST_AUTO(initial, ( "TILT" >> char_('=') >>
> ( "NONE" |
> ( "INCLUDE" >>
> int_[ref(lampToLuminaireGeom) = _1] >>
> int_[ref(numPairsWithMulFactors) = _1] ) |
> fileName[ref(tiltFileName)] ) ) );
>
> if(!phrase_parse(first, last, initial, space)) {
> return IES_INVALID;
> }
>
> The code works with NONE or INCLUDE, but not with files. As far as I
> know, there are no real restrictions on the filenames. At this point, the
> code posted above can't even get simple file names, but really I think
> what is required is that I grab anything non-whitespace after the '='
> until it reaches an EOL.
>
> Can anyone provide some insight about what I may be doing wrong?
HTH
Regards Hartmut
---------------
http://boost-spirit.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net