Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57724 - trunk/libs/spirit/example/qi
From: joel_at_[hidden]
Date: 2009-11-17 08:32:37


Author: djowel
Date: 2009-11-17 08:32:36 EST (Tue, 17 Nov 2009)
New Revision: 57724
URL: http://svn.boost.org/trac/boost/changeset/57724

Log:
typeof example
Added:
   trunk/libs/spirit/example/qi/typeof.cpp (contents, props changed)

Added: trunk/libs/spirit/example/qi/typeof.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/typeof.cpp 2009-11-17 08:32:36 EST (Tue, 17 Nov 2009)
@@ -0,0 +1,49 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <iostream>
+#include <string>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using boost::spirit::ascii::space;
+ using boost::spirit::ascii::char_;
+ using boost::spirit::qi::parse;
+ typedef std::string::const_iterator iterator_type;
+
+ BOOST_AUTO(comment, "/*" >> *(char_ - "*/") >> "*/");
+
+ std::string str = "/*This is a comment*/";
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ bool r = parse(iter, end, comment);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "-------------------------\n";
+ }
+ else
+ {
+ std::string rest(iter, end);
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "stopped at: \": " << rest << "\"\n";
+ std::cout << "-------------------------\n";
+ }
+
+ return 0;
+}
+
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk