[spirit2] Trivial parser crashes

Hello, Playing with spirit-2 (boost 1.36 release) I got the following code to ASSERT when compiled on Visual Studio 2008/SP1. Any ideas what's wrong? ---------------------------------------------------------- #include #include #include #include #include #include #include #include #include using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names; namespace phoenix = boost::phoenix; using phoenix::at_c; struct key_val { std::string key; std::string value; }; BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) ) template struct my_grammar : grammar { my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; } rule key; rule quoted_string; rule value; rule start; }; int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" "; citerator iter = str.begin(); citerator end = str.end(); my_grammar my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs return 0; } -------------------------------------------------------------------------- thanks -- View this message in context: http://www.nabble.com/-spirit2--Trivial-parser-crashes-tp19624910p19624910.h... Sent from the Boost - Users mailing list archive at Nabble.com.

sm4 wrote:
Hello, Playing with spirit-2 (boost 1.36 release) I got the following code to ASSERT when compiled on Visual Studio 2008/SP1. Any ideas what's wrong? ---------------------------------------------------------- #include #include #include #include #include #include #include #include #include using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names; namespace phoenix = boost::phoenix; using phoenix::at_c; struct key_val { std::string key; std::string value; }; BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) ) template struct my_grammar : grammar { my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; } rule key; rule quoted_string; rule value; rule start; }; int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" "; citerator iter = str.begin(); citerator end = str.end(); my_grammar my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs return 0; }
Wow, care to repost that code? Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

Oops - seems formatting got in the way.
Hope this is better:
-----------------------------------------------------------------------------------------
#include
sm4 wrote:
Hello, Playing with spirit-2 (boost 1.36 release) I got the following code to ASSERT when compiled on Visual Studio 2008/SP1. Any ideas what's wrong? ---------------------------------------------------------- #include #include #include #include #include #include #include #include #include using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names; namespace phoenix = boost::phoenix; using phoenix::at_c; struct key_val { std::string key; std::string value; }; BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) ) template struct my_grammar : grammar { my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; } rule key; rule quoted_string; rule value; rule start; }; int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" "; citerator iter = str.begin(); citerator end = str.end(); my_grammar my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs return 0; }
Wow, care to repost that code?
Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/-spirit2--Trivial-parser-crashes-tp19624910p19651253.h... Sent from the Boost - Users mailing list archive at Nabble.com.

Hello, Way behind the times here but I'm having 2 problems with directory iterator while upgrading from 1_33_0 to 1_34_1 and VC6 to VC8: Std::string pathToDelete( "c:\\dir" ); boost::filesystem::directory_iterator it( pathToDelete ); std::for_each( boost::filesystem::directory_iterator(*it), boost::filesystem::directory_iterator(), boost::filesystem::remove ); gives the error error C2914: 'std::for_each' : cannot deduce template argument as function argument is ambiguous Also the following no longer exists: boost::filesystem::directory_iterator it( pathToDelete ); it->native_directory_string(); Is the replacement: It->path().native_directory_string(); Thanks, Patrick ****************************************************************************** "This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you." Interactive Transaction Solutions Ltd (2473364 England) Registered Office: Systems House, Station Approach Emsworth PO10 7PW ********************************************************************** Ce message �lectronique contient des informations confidentielles � l'usage unique des destinataires indiqu�s, personnes physiques ou morales. Si vous n'�tes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez re�u ce message �lectronique par erreur, nous vous remercions d'en avertir son exp�diteur imm�diatement par email et de d�truire ce message ainsi que les �l�ments attach�s. Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877) Si�ge social : Parc Saint Christophe, 10, Avenue de l�Entreprise 95865 Cergy-Pontoise Cedex ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________

Std::string pathToDelete( "c:\\dir" ); boost::filesystem::directory_iterator it( pathToDelete ); std::for_each( boost::filesystem::directory_iterator(*it), boost::filesystem::directory_iterator(), boost::filesystem::remove );
I guess the answer would be to use boost::filesystem::remove_all()! Sorry for wasting your time but if someone can just confirm both these are good replacements I'd be very grateful.
Also the following no longer exists: boost::filesystem::directory_iterator it( pathToDelete ); it->native_directory_string();
Is the replacement: It->path().native_directory_string();
Thanks once again, Patrick ****************************************************************************** "This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you." Interactive Transaction Solutions Ltd (2473364 England) Registered Office: Systems House, Station Approach Emsworth PO10 7PW ********************************************************************** Ce message �lectronique contient des informations confidentielles � l'usage unique des destinataires indiqu�s, personnes physiques ou morales. Si vous n'�tes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez re�u ce message �lectronique par erreur, nous vous remercions d'en avertir son exp�diteur imm�diatement par email et de d�truire ce message ainsi que les �l�ments attach�s. Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877) Si�ge social : Parc Saint Christophe, 10, Avenue de l�Entreprise 95865 Cergy-Pontoise Cedex ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________

sm4 wrote:
Oops - seems formatting got in the way.
Hope this is better:
Ooops, I missed your reply. Its better to post spirit related questions to spirit's mailing list. I'm re-posting this there.
----------------------------------------------------------------------------------------- #include
#include #include #include #include #include #include #include <iostream> #include <string>
using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names;
namespace phoenix = boost::phoenix;
using phoenix::at_c;
struct key_val { std::string key; std::string value; };
BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) )
template <typename Iterator> struct my_grammar : grammar
{ my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; }
rule
key; rule quoted_string; rule value; rule
start; };
int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" ";
citerator iter = str.begin(); citerator end = str.end();
my_grammar<citerator> my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs
return 0; }
-----------------------------------------------------------------------------------------
-- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

Joel de Guzman wrote:
sm4 wrote:
Oops - seems formatting got in the way.
Hope this is better:
Ooops, I missed your reply. Its better to post spirit related questions to spirit's mailing list. I'm re-posting this there.
Ok, this looks like a bug in handling aliases of the form: r1 %= r2; where r1 and r2 are rules with the same type. A quick workaround is to copy the rhs rule: r1 %= r2.copy(); Thus: key %= quoted_string.copy(); value %= quoted_string.copy(); Take note that this is not a problem with Spirit2x I am working on right now which should replace the current version hopefully soon. I'll get back to you for a quick fix. Anyway, in case you don't know, here's spirit's mailing list: https://lists.sourceforge.net/lists/listinfo/spirit-general Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

Joel de Guzman wrote:
Joel de Guzman wrote:
sm4 wrote:
Oops - seems formatting got in the way.
Hope this is better:
Ooops, I missed your reply. Its better to post spirit related questions to spirit's mailing list. I'm re-posting this there.
Ok, this looks like a bug in handling aliases of the form:
r1 %= r2;
where r1 and r2 are rules with the same type. A quick workaround is to copy the rhs rule:
r1 %= r2.copy();
Eric, It seems to be a problem with Spirit2's usage of proto extends. Here's what's happening: 1) Rule uses proto::extends 2) Rule implements operator %= On expressions: r %= some-expression; The rule's operator%= kicks in. However, on expressions: r %= r2; // r and r2 has the same type Then proto %= kicks in leaving it as a no-op. Nothing happens. Hence, the rhs is never "auto-assigned" to the lhs. I'm not sure how to deal with this. Do you have a hint? I place the original test code here. Tracing the code, the first %= works as expected while the second and third becomes no-ops calling proto operator %=.
-----------------------------------------------------------------------------------------
#include
#include #include #include #include #include #include #include <iostream> #include <string>
using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names;
namespace phoenix = boost::phoenix;
using phoenix::at_c;
struct key_val { std::string key; std::string value; };
BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) )
template <typename Iterator> struct my_grammar : grammar
{ my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; }
rule
key; rule quoted_string; rule value; rule
start; };
int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" ";
citerator iter = str.begin(); citerator end = str.end();
my_grammar<citerator> my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs
return 0; }
----------------------------------------------------------------------------------------- Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net

Joel de Guzman wrote:
On expressions:
r %= some-expression;
The rule's operator%= kicks in. However, on expressions:
r %= r2; // r and r2 has the same type
Then proto %= kicks in leaving it as a no-op. Nothing happens. Hence, the rhs is never "auto-assigned" to the lhs.
I'm not sure how to deal with this. Do you have a hint? I place the original test code here. Tracing the code, the first %= works as expected while the second and third becomes no-ops calling proto operator %=.
You can disable proto's operator%= by specifying a domain with a grammar to proto::extends as described in the docs. You could also try defining a rule::operator%=(rule) member and see if that one gets picked up. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Joel de Guzman wrote:
I'm not sure how to deal with this. Do you have a hint? I place the original test code here. Tracing the code, the first %= works as expected while the second and third becomes no-ops calling proto operator %=.
I checked and you just need to define an operator%= that takes a
non-const RHS. Patch attached. Karma might need a similar patch.
--
Eric Niebler
BoostPro Computing
http://www.boostpro.com
Index: rule.hpp
===================================================================
--- rule.hpp (revision 49819)
+++ rule.hpp (working copy)
@@ -90,6 +90,23 @@
}
template <typename Expr>
+ friend rule& operator%=(rule& r, Expr& xpr)
+ {
+ typedef spirit::traits::is_component
participants (5)
-
Eric Niebler
-
Eric Niebler
-
Joel de Guzman
-
Patrick Loney
-
sm4