Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54713 - in trunk/libs/spirit/test: . lex
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-06 11:13:54


Author: hkaiser
Date: 2009-07-06 11:13:53 EDT (Mon, 06 Jul 2009)
New Revision: 54713
URL: http://svn.boost.org/trac/boost/changeset/54713

Log:
Spirit: added missing typedef, fixed iterator_range initialization
Added:
   trunk/libs/spirit/test/lex/set_token_value_phoenix.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/CMakeLists.txt | 4 +---
   trunk/libs/spirit/test/Jamfile | 1 +
   2 files changed, 2 insertions(+), 3 deletions(-)

Modified: trunk/libs/spirit/test/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/test/CMakeLists.txt (original)
+++ trunk/libs/spirit/test/CMakeLists.txt 2009-07-06 11:13:53 EDT (Mon, 06 Jul 2009)
@@ -104,6 +104,7 @@
 boost_test_run(lex_state_switcher lex/state_switcher_test.cpp COMPILE_FLAGS ${test_compile_flags})
 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_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})
@@ -114,6 +115,3 @@
 # [ run support/multi_pass_compile.cpp COMPILE_FLAGS ${test_compile_flags} : : : : ]
 # [ run support/multi_pass.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-06 11:13:53 EDT (Mon, 06 Jul 2009)
@@ -110,6 +110,7 @@
     [ run lex/state_switcher_test.cpp : : : : ]
     [ run lex/lexer_state_switcher.cpp : : : : ]
     [ run lex/set_token_value.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-06 11:13:53 EDT (Mon, 06 Jul 2009)
@@ -0,0 +1,88 @@
+// Copyright (c) 2009 Carl Barron
+// 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 <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;
+
+template <class Lexer>
+struct multi_tokens:lex::lexer<Lexer>
+{
+ int level;
+
+ multi_tokens() : level(0)
+ {
+ using lex::_state;
+ using lex::_start;
+ using lex::_end;
+ using lex::_pass;
+ using lex::pass_flags;
+
+ a = "A";
+ b = "B";
+ c = "C";
+ this->self =
+ a [ ++phoenix::ref(level) ]
+ | b
+ | c [
+ _state = "in_dedenting",
+ _end = _start,
+ _pass = pass_flags::pass_ignore
+ ]
+ ;
+
+ d = ".";
+ this->self("in_dedenting") =
+ d [
+ if_(--phoenix::ref(level))
+ [ _end = _start ]
+ .else_
+ [ _state = "INITIAL" ]
+ ]
+ ;
+ }
+
+ lex::token_def<> a, b, c, d;
+};
+
+struct dumper
+{
+ typedef bool result_type;
+
+ template <class Token>
+ bool operator () (Token const &t)
+ {
+ char x = (char)(t.id() - lex::min_token_id + 'a');
+ std::cout << x;
+ return true;
+ }
+};
+
+int main()
+{
+ std::string in("AAABBC");
+
+ typedef lex::lexertl::token<std::string::iterator,boost::mpl::vector0<> > token_type;
+ typedef lex::lexertl::actor_lexer<token_type> base_lexer_type;
+ typedef multi_tokens<base_lexer_type> lexer_type;
+ typedef lexer_type::iterator_type iterator;
+
+ lexer_type the_lexer;
+ std::string::iterator first(in.begin());
+ if(lex::tokenize(first, in.end(), the_lexer, dumper()))
+ {
+ std::cout << "\nlex worked\n";
+ }
+ else
+ {
+ std::cout << "lex failed\n";
+ }
+}
+


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