mirror of
https://github.com/boostorg/spirit.git
synced 2026-01-19 04:42:11 +00:00
Spirit: Added a new Qi example
[SVN r59375]
This commit is contained in:
@@ -32,6 +32,7 @@ exe key_value_sequence_empty_value : key_value_sequence_empty_value.cpp ;
|
||||
|
||||
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 ;
|
||||
|
||||
22
example/qi/display_attribute_type.cpp
Normal file
22
example/qi/display_attribute_type.cpp
Normal file
@@ -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;
|
||||
}
|
||||
49
example/qi/display_attribute_type.hpp
Normal file
49
example/qi/display_attribute_type.hpp
Normal file
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user