Help me for spirit grammar definition! It is simple...

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

钱晓明 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
{ 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
participants (2)
-
Joel de Guzman
-
钱晓明