Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54904 - trunk/libs/spirit/example/support
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-11 23:27:44


Author: hkaiser
Date: 2009-07-11 23:27:42 EDT (Sat, 11 Jul 2009)
New Revision: 54904
URL: http://svn.boost.org/trac/boost/changeset/54904

Log:
Spirit: added multi_pass example
Added:
   trunk/libs/spirit/example/support/
   trunk/libs/spirit/example/support/CMakeLists.txt (contents, props changed)
   trunk/libs/spirit/example/support/Jamfile (contents, props changed)
   trunk/libs/spirit/example/support/multi_pass.cpp (contents, props changed)
   trunk/libs/spirit/example/support/multi_pass.txt (contents, props changed)

Added: trunk/libs/spirit/example/support/CMakeLists.txt
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/support/CMakeLists.txt 2009-07-11 23:27:42 EDT (Sat, 11 Jul 2009)
@@ -0,0 +1,15 @@
+#==============================================================================
+# Copyright (c) 2001-2009 Joel de Guzman
+# 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)
+#==============================================================================
+
+# project spirit-support-example
+# : requirements <toolset>gcc:<c++-template-depth>300
+# :
+# :
+# ;
+
+boost_add_executable(multi_pass.cpp)

Added: trunk/libs/spirit/example/support/Jamfile
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/support/Jamfile 2009-07-11 23:27:42 EDT (Sat, 11 Jul 2009)
@@ -0,0 +1,14 @@
+#==============================================================================
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 Hartmut Kaiser
+#
+# 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)
+#==============================================================================
+project spirit-support-example
+ : requirements <toolset>gcc:<c++-template-depth>300
+ :
+ :
+ ;
+
+exe multi_pass : multi_pass.cpp ;

Added: trunk/libs/spirit/example/support/multi_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/support/multi_pass.cpp 2009-07-11 23:27:42 EDT (Sat, 11 Jul 2009)
@@ -0,0 +1,50 @@
+// Copyright (c) 2001-2009 Hartmut Kaiser
+//
+// 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 <iostream>
+#include <fstream>
+#include <vector>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+//[tutorial_multi_pass
+int main()
+{
+ namespace spirit = boost::spirit;
+ using spirit::ascii::space;
+ using spirit::ascii::char_;
+ using spirit::qi::double_;
+ using spirit::qi::eol;
+
+ std::ifstream in("multi_pass.txt"); // we get our input from this file
+ if (!in.is_open()) {
+ std::cout << "Could not open input file: 'multi_pass.txt'" << std::endl;
+ return -1;
+ }
+
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ spirit::multi_pass<base_iterator_type> first =
+ spirit::make_default_multi_pass(base_iterator_type(in));
+
+ std::vector<double> v;
+ bool result = spirit::qi::phrase_parse(first
+ , spirit::make_default_multi_pass(base_iterator_type())
+ , double_ >> *(',' >> double_) // recognize list of doubles
+ , space | '#' >> *(char_ - eol) >> eol // comment skipper
+ , v); // data read from file
+
+ if (!result) {
+ std::cout << "Failed parsing input file!" << std::endl;
+ return -2;
+ }
+
+ std::cout << "Successfully parsed input file!" << std::endl;
+ return 0;
+}
+//]

Added: trunk/libs/spirit/example/support/multi_pass.txt
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/support/multi_pass.txt 2009-07-11 23:27:42 EDT (Sat, 11 Jul 2009)
@@ -0,0 +1,6 @@
+# Copyright (c) 2001-2009 Hartmut Kaiser
+#
+# 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)
+
+1.0,2.0,3.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