Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59375 - trunk/libs/spirit/example/qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-01-30 20:29:03


Author: hkaiser
Date: 2010-01-30 20:29:02 EST (Sat, 30 Jan 2010)
New Revision: 59375
URL: http://svn.boost.org/trac/boost/changeset/59375

Log:
Spirit: Added a new Qi example
Added:
   trunk/libs/spirit/example/qi/display_attribute_type.cpp (contents, props changed)
   trunk/libs/spirit/example/qi/display_attribute_type.hpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/example/qi/Jamfile | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/example/qi/Jamfile
==============================================================================
--- trunk/libs/spirit/example/qi/Jamfile (original)
+++ trunk/libs/spirit/example/qi/Jamfile 2010-01-30 20:29:02 EST (Sat, 30 Jan 2010)
@@ -32,6 +32,7 @@
 
 exe iter_pos_parser : iter_pos_parser.cpp ;
 exe boost_array : boost_array.cpp ;
+exe display_attribute_type : display_attribute_type.cpp ;
 
 exe calculator1 : calc1.cpp ;
 exe calculator2 : calc2.cpp ;

Added: trunk/libs/spirit/example/qi/display_attribute_type.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/display_attribute_type.cpp 2010-01-30 20:29:02 EST (Sat, 30 Jan 2010)
@@ -0,0 +1,22 @@
+// Copyright (c) 2001-2010 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)
+
+// This example implements a simple utility allowing to print the attribute
+// type as it is exposed by an arbitrary Qi parser expression. Just insert
+// your expression below, compile and run this example to see what Qi is
+// seeing!
+
+#include "display_attribute_type.hpp"
+
+namespace qi = boost::spirit::qi;
+
+int main()
+{
+ tools::display_attribute_of_parser(
+ std::cerr, // put the required output stream here
+ qi::int_ >> qi::double_ // put your parser expression here
+ );
+ return 0;
+}

Added: trunk/libs/spirit/example/qi/display_attribute_type.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/display_attribute_type.hpp 2010-01-30 20:29:02 EST (Sat, 30 Jan 2010)
@@ -0,0 +1,49 @@
+// Copyright (c) 2001-2010 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)
+
+// This example implements a simple utility allowing to print the attribute
+// type as it is exposed by an arbitrary Qi parser expression. Just insert
+// your expression below, compile and run this example to see what Qi is
+// seeing!
+
+#if !defined (DISPLAY_ATTRIBUTE_OF_PARSER_JAN_2010_30_0722PM)
+#define DISPLAY_ATTRIBUTE_OF_PARSER_JAN_2010_30_0722PM
+
+#include <iostream>
+#include <boost/spirit/include/qi.hpp>
+
+namespace tools
+{
+ namespace spirit = boost::spirit;
+
+ template <typename Expr, typename Iterator = spirit::unused_type>
+ struct attribute_of_parser
+ {
+ typedef typename spirit::result_of::compile<
+ spirit::qi::domain, Expr
+ >::type parser_expression_type;
+
+ typedef typename spirit::traits::attribute_of<
+ parser_expression_type, spirit::unused_type, Iterator
+ >::type type;
+ };
+
+ template <typename T>
+ void display_attribute_of_parser(T const &)
+ {
+ typedef typename attribute_of_parser<T>::type type;
+ std::cout << typeid(type).name() << std::endl;
+ }
+
+ template <typename T>
+ void display_attribute_of_parser(std::ostream& os, T const &)
+ {
+ typedef typename attribute_of_parser<T>::type type;
+ std::cout << typeid(type).name() << std::endl;
+ }
+}
+
+#endif
+


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