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?