|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55546 - trunk/libs/spirit/example/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-08-12 09:40:53
Author: hkaiser
Date: 2009-08-12 09:40:48 EDT (Wed, 12 Aug 2009)
New Revision: 55546
URL: http://svn.boost.org/trac/boost/changeset/55546
Log:
Spirit: added the Karma example classify_char
Added:
trunk/libs/spirit/example/karma/classify_char.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/example/karma/CMakeLists.txt | 11 ++++++-----
trunk/libs/spirit/example/karma/Jamfile | 25 ++++++++++++-------------
2 files changed, 18 insertions(+), 18 deletions(-)
Modified: trunk/libs/spirit/example/karma/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/example/karma/CMakeLists.txt (original)
+++ trunk/libs/spirit/example/karma/CMakeLists.txt 2009-08-12 09:40:48 EDT (Wed, 12 Aug 2009)
@@ -1,21 +1,22 @@
#==============================================================================
-# Copyright (c) 2001-2009 Joel de Guzman
# Copyright (c) 2001-2009 Hartmut Kaiser
+# 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)
#==============================================================================
-boost_add_executable(quick_start1)
-boost_add_executable(karma_num_list1 num_list1.cpp)
-boost_add_executable(karma_complex_number complex_number.cpp)
boost_add_executable(actions)
boost_add_executable(basic_facilities DEPENDS boost_date_time)
boost_add_executable(calc2_ast_dump)
boost_add_executable(calc2_ast_rpn)
boost_add_executable(calc2_ast_vm)
-boost_add_executable(mini_xml_karma)
+boost_add_executable(classify_char)
+boost_add_executable(karma_num_list1 num_list1.cpp)
+boost_add_executable(karma_complex_number complex_number.cpp)
boost_add_executable(key_value_sequence)
+boost_add_executable(mini_xml_karma)
+boost_add_executable(quick_start1)
Modified: trunk/libs/spirit/example/karma/Jamfile
==============================================================================
--- trunk/libs/spirit/example/karma/Jamfile (original)
+++ trunk/libs/spirit/example/karma/Jamfile 2009-08-12 09:40:48 EDT (Wed, 12 Aug 2009)
@@ -1,23 +1,22 @@
#==============================================================================
-# Copyright (c) 2001-2009 Joel de Guzman
# Copyright (c) 2001-2009 Hartmut Kaiser
+# 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-karma-example ;
-exe quick_start1 : quick_start1.cpp ;
-exe num_list1 : num_list1.cpp ;
-exe complex_number : complex_number.cpp ;
-exe actions_example : actions.cpp ;
-exe basic_facilities : basic_facilities.cpp /boost//date_time ;
-exe calc2_ast_dump : calc2_ast_dump.cpp ;
-exe calc2_ast_rpn : calc2_ast_rpn.cpp ;
-exe calc2_ast_vm : calc2_ast_vm.cpp ;
-exe mini_xml_karma : mini_xml_karma.cpp ;
-exe key_value_sequence : key_value_sequence.cpp ;
+exe actions_example : actions.cpp ;
+exe basic_facilities : basic_facilities.cpp /boost//date_time ;
+exe calc2_ast_dump : calc2_ast_dump.cpp ;
+exe calc2_ast_rpn : calc2_ast_rpn.cpp ;
+exe calc2_ast_vm : calc2_ast_vm.cpp ;
+exe classify_char : classify_char.cpp ;
+exe karma_complex_number : complex_number.cpp ;
+exe karma_num_list1 : num_list1.cpp ;
+exe key_value_sequence : key_value_sequence.cpp ;
+exe mini_xml_karma : mini_xml_karma.cpp ;
+exe quick_start1 : quick_start1.cpp ;
-# not ported yet:
-# exe functor_facilities : functor_facilities.cpp ;
Added: trunk/libs/spirit/example/karma/classify_char.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/karma/classify_char.cpp 2009-08-12 09:40:48 EDT (Wed, 12 Aug 2009)
@@ -0,0 +1,103 @@
+// 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)
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// A character classification example
+//
+// [ HK August 12, 2009 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/karma.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/fusion/include/std_pair.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Our character classification generator
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_karma_complex_number
+ template <typename OutputIterator>
+ bool classify_character(OutputIterator sink, char c)
+ {
+ using boost::spirit::ascii::char_;
+ using boost::spirit::ascii::digit;
+ using boost::spirit::ascii::xdigit;
+ using boost::spirit::ascii::alpha;
+ using boost::spirit::ascii::punct;
+ using boost::spirit::ascii::space;
+ using boost::spirit::ascii::cntrl;
+ using boost::spirit::karma::omit;
+ using boost::spirit::karma::generate;
+
+ if (!boost::spirit::char_encoding::ascii::isascii_(c))
+ return false;
+
+ return generate(sink,
+ // Begin grammar
+ (
+ "The character '" << char_ << "' is "
+ << ( &digit << "a digit"
+ | &xdigit << "a xdigit"
+ | &alpha << "a alpha"
+ | &punct << "a punct"
+ | &space << "a space"
+ | &cntrl << "a cntrl"
+ | omit[char_] << "of unknown type"
+ )
+ ),
+ // End grammar
+ c, c
+ );
+ }
+ //]
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA character classification micro generator for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a character to classify\n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty())
+ break;
+
+ std::string generated;
+ std::back_insert_iterator<std::string> sink(generated);
+ if (!client::classify_character(sink, str[0]))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Generating failed\n";
+ std::cout << "-------------------------\n";
+ }
+ else
+ {
+ std::cout << generated << "\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\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