Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-04-11 17:02:21


钱晓明 wrote:
> I want to use spirit parsing some text file. The very basic element in
> those files is string, float and int. For example:
> 123L
> "hello"
> 987.4343
> I wrote my grammar class:
> struct pm_parser : public grammar<pm_parser>
> {
> template <typename ScannerT>
> struct definition
> {
> definition(pm_parser const& self)
> {
> factor =
> int_p[show_int()]>>"L"
> | '"'>> *((~ch_p('"'))[show_char()]) >>'"'
> | real_p[show_double()]
> ;
> }
> rule<ScannerT> factor;
> rule<ScannerT> const& start() const { return factor; }
> };
> };
> show_int, show_char, show_double are structs used to show int, char and
> double value. When I parse 1L, it works. But when I parse 1, it is
> parsed twice(int_p and real_p are all works).
> How can I define grammar struct to parse text above without errors?

Please post to the spirit mailing list:
https://lists.sourceforge.net/lists/listinfo/spirit-general
Thanks!

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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