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/20/2016 03:02 AM, Sandro Pirkwieser wrote:
[snip]
 >> Hence, Sandro, could you provide some use-case for this feature?
 >

 > The main topic (aside the more recent performance
 > analysis) was the question to "better" (at least in my
 > view) encapsulate an X3 parser than with namespaces,
 > i.e. more in the style of a Qi parser. There a larger,
 > more complex parser can be built by incorporating several
 > smaller ones as class members, yet retaining a nice
 > encapsulation. Something that does not seem possible with
 > X3.

 > An alternative, using parsers defined in functions (as for
 > make_csv_parser), is not always an option though, as such
 > parsers cannot be recursive (rule A is defined via rule B
 > and vice versa).

 > Your prototype allows using BOOST_SPIRIT_DEFINE inside a
 > struct, hence would definitely come closer to the Qi like
 > encapsulation.

Hi, Sandro.

The code:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/x3_crtp.hpp

implements the csv_parser pretty much as encapsulated as the
qi versiion at:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/qi.hpp

Unfortunately, the runtime suffers the same slowdown as the
x3 version.  The timings here:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/means.out

where produced by:

   make -k USE_MACRO_INCLUDE=1 means

Those timings, and looking at the code, indicates the
slowdown is due to the attribute transforms done by:

https://github.com/cppljevans/spirit/blob/get_rhs/include/boost/spirit/home/x3/nonterminal/detail/rule.hpp#L310

That's because, as shown here:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/means.out#L5

and here:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/means.out#L7

the time is *less* than the time for the qi method here:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/means.out#L1

OTOH, the lines where XRULE0 occurs (meaning the attribute
transform is done within the rule_definition::parse
function), the times are more than the qi method.

 > I haven't tried it yet, but is it also possible to use
 > parameters, like the field separator fort the CSV parser?
 > As it can't be given at the time of construction, as for
 > make_csv_parser(), one could probably use x3::with<>.

This is done here:

https://github.com/cppljevans/spirit/blob/get_rhs/workbench/x3/csv_parser/x3_crtp.hpp#L28

 > Best regards,
 > Sandro
 >
HTH.

-regards,
Larry



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.