X3 employee example with semantic actions

Maarten Verhage <[email protected]> Wed, 30 May 2018 15:16:17 +0000
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <AM5P192MB0131BD63AE3BDAE23078F84FBA6C0@AM5P192MB0131.EURP192.PROD.OUTLOOK.COM>
Dear people,



What would help me in understanding Spirit better is when I can clearly see 
how the parsed attributes are stored into the data structure. So, I’m aiming 
for semantic actions to do the work.



I was dealing with the employee example code in Spirit 2. But I realized 
that the type of an compound attribute can grow pretty complex. For example 
if I want the quotes themselves stored as well. See:





quoted_string = lexeme[char_('"') >> +(char_ - '"') >> char_('"')]

  [phoenix::bind( &assign_quoted_str, phoenix::ref(qi::_val), ::_1 ) ];





And the function:



void assign_quoted_str(

  std::string& val,

  const boost::fusion::vector<

  boost::fusion::vector< char, std::vector<char>, char >>& fvc )

{

  val = boost::fusion::at_c<0>( boost::fusion::at_c<0>( fvc ) );



  const std::vector<char>& vc =

    boost::fusion::at_c<1>( boost::fusion::at_c<0>( fvc ) );

  val.append( vc.begin(), vc.end() );



  val += boost::fusion::at_c<2>( boost::fusion::at_c<0>( fvc ) );

}



So, I thought how nice it would have been to get a pair of iterators into 
the “parsed” result once Spirit determined the rule to match. But I couldn’t 
found this facility in Spirit 2. But Spirit X3 has the Context object to be 
able to call the _where member function to get this right? And then just 
copy it to a memory area that will become my new file. For the file contents 
I do not want to modify this would be a pretty efficient way right?



The obstacle I’m facing right now (and hope a list member here would be able 
to help me on) is this: As I do want manually store stuff using semantic 
actions how do I need to modify the Spirit X3 employee example code to 1) 
Prevent spirit to automatically store it. And 2) How do I need to provide 
the empty employee object to this client::parser namespace area as this is 
not a class anymore.



I hope I did explain my situation clearly. I’m certainly willing to explain 
something differently if I made some parts ambiguous. Let me know in that 
case.



Best regards,

Maarten Verhage 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general