Re: Design/structure X3 parser more like Qi parser
Larry Evans <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 12/13/2016 11:56 AM, Seth wrote:
[snip]
> The resultant X3 neatly expresses why I don't think modularity of X3 is
> any problem. It employs only one or two tricks, which **exploit** the
> fact that X3 is actually /just c++ code/ and behaves as such:
>
> namespace csv {
> template <typename Sep>
> auto make_csv_parser(Sep fieldSep) {
> using namespace boost::spirit::x3;
>
> using R = rule<struct _, CsvString>;
>
> auto unescaped = R{"raw"} = *(~char_("\"\r\n") - fieldSep);
> auto escaped = R{"quoted"} = *(~char_('"') | '"' >>
> char_('"'));
> auto lineBreak = eol;
>
> auto field = R{"field"} =
> (*lit(' ') >> ('"' > escaped > '"') >> *lit(' '))
> | unescaped; // the order is important because unescaped
> can consume zero characters
>
> auto record = rule<struct _, CsvRecordInformation>{ "record" } =
> field % fieldSep;
>
> auto file = rule<struct _, CsvFileInformation>{ "file" } =
> ((!eoi > record) % lineBreak) > -lineBreak > eoi;
>
> return file;
> };
> }
>
[snip]
This doesn't use BOOST_SPIRIT_DEFINE, and I don't think it can
because that would generate one or more parse_rule's template functions
within the make_csv_parser function. Is that right?
If so, then wouldn't that make this method slower to compile than if
BOOST_SPIRIT_DEFINE could be used?
-regards,
Larry
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot