Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54772 - in trunk/libs/spirit/test: . lex
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-07 11:40:02


Author: hkaiser
Date: 2009-07-07 11:40:01 EDT (Tue, 07 Jul 2009)
New Revision: 54772
URL: http://svn.boost.org/trac/boost/changeset/54772

Log:
Spirit: fixed lexer placeholders to correctly integrate with nested Phoenix expressions (added test)
Added:
   trunk/libs/spirit/test/lex/set_token_value_phoenix.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/CMakeLists.txt | 1 +
   trunk/libs/spirit/test/Jamfile | 1 +
   2 files changed, 2 insertions(+), 0 deletions(-)

Modified: trunk/libs/spirit/test/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/test/CMakeLists.txt (original)
+++ trunk/libs/spirit/test/CMakeLists.txt 2009-07-07 11:40:01 EDT (Tue, 07 Jul 2009)
@@ -105,6 +105,7 @@
 boost_test_run(lex_lexer_state_switcher lex/lexer_state_switcher.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(lex_set_token_value lex/set_token_value.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(lex_dedent_handling_phoenix lex/dedent_handling_phoenix.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(lex_set_token_value_phoenix lex/set_token_value_phoenix.cpp COMPILE_FLAGS ${test_compile_flags})
 
 boost_test_run(lex_regression001 lex/regression001.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(lex_regression002 lex/regression002.cpp COMPILE_FLAGS ${test_compile_flags})

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2009-07-07 11:40:01 EDT (Tue, 07 Jul 2009)
@@ -111,6 +111,7 @@
     [ run lex/lexer_state_switcher.cpp : : : : ]
     [ run lex/set_token_value.cpp : : : : ]
     [ run lex/dedent_handling_phoenix.cpp : : : : ]
+ [ run lex/set_token_value_phoenix.cpp : : : : ]
 
     [ run lex/regression001.cpp : : : : lex_regression001 ]
     [ run lex/regression002.cpp : : : : lex_regression002 ]

Added: trunk/libs/spirit/test/lex/set_token_value_phoenix.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/lex/set_token_value_phoenix.cpp 2009-07-07 11:40:01 EDT (Tue, 07 Jul 2009)
@@ -0,0 +1,67 @@
+// Copyright (c) 2009 Carl Barron
+//
+// 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 <string>
+#include <iostream>
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/lex.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
+#include <boost/spirit/include/phoenix.hpp>
+
+namespace lex = boost::spirit::lex;
+namespace phoenix = boost::phoenix;
+
+///////////////////////////////////////////////////////////////////////////////
+struct square_impl
+{
+ template <class>
+ struct result { typedef int type; };
+
+ template <class A>
+ int operator () (const A &x) const
+ { return (x) * (x); }
+};
+
+phoenix::function<square_impl> const square = square_impl();
+
+///////////////////////////////////////////////////////////////////////////////
+template <class Lexer>
+struct test_tokens : lex::lexer<Lexer>
+{
+ test_tokens()
+ {
+ a = "a";
+ this->self = a [lex::_val = square(*lex::_start)];
+ }
+
+ lex::token_def<int> a;
+};
+
+struct catch_result
+{
+ template <class Token>
+ bool operator() (Token const& x) const
+ {
+ BOOST_TEST(x.value().which() == 1);
+ BOOST_TEST(boost::get<int>(x.value()) == 9409); // 9409 == 'a' * 'a'
+ return true;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ typedef lex::lexertl::token<std::string::iterator
+ , boost::mpl::vector<int> > token_type;
+
+ std::string in = "a";
+ std::string::iterator first(in.begin());
+
+ test_tokens<lex::lexertl::actor_lexer<token_type> > the_lexer;
+ BOOST_TEST(lex::tokenize(first, in.end(), the_lexer, catch_result()));
+
+ return boost::report_errors();
+}


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