Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54680 - trunk/boost/spirit/home/lex/lexer/lexertl
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-05 15:00:58


Author: hkaiser
Date: 2009-07-05 15:00:57 EDT (Sun, 05 Jul 2009)
New Revision: 54680
URL: http://svn.boost.org/trac/boost/changeset/54680

Log:
Spirit: Added support for accessing the token value from a lexer semantic action
Text files modified:
   trunk/boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp | 43 +++++++++++++++++++++++++++++----------
   trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp | 3 -
   2 files changed, 33 insertions(+), 13 deletions(-)

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp 2009-07-05 15:00:57 EDT (Sun, 05 Jul 2009)
@@ -37,13 +37,14 @@
         }
 
         ///////////////////////////////////////////////////////////////////////
- template <typename Iterator, typename HasActors, typename HasState>
+ template <typename Iterator, typename HasActors, typename HasState
+ , typename TokenValue>
         struct static_data; // no default specialization
 
         ///////////////////////////////////////////////////////////////////////
         // doesn't support no state and no actors
- template <typename Iterator>
- struct static_data<Iterator, mpl::false_, mpl::false_>
+ template <typename Iterator, typename TokenValue>
+ struct static_data<Iterator, mpl::false_, mpl::false_, TokenValue>
         {
         protected:
             typedef typename
@@ -52,6 +53,7 @@
 
         public:
             typedef Iterator base_iterator_type;
+ typedef unused_type token_value_type;
             typedef std::size_t state_type;
             typedef char_type const* state_name_type;
             typedef unused_type semantic_actions_type;
@@ -164,6 +166,8 @@
             Iterator const& get_first() const { return first_; }
             Iterator const& get_last() const { return last_; }
 
+ unused_type value() const { return unused; }
+
         protected:
             Iterator& first_;
             Iterator last_;
@@ -174,16 +178,17 @@
 
         ///////////////////////////////////////////////////////////////////////
         // doesn't support no actors
- template <typename Iterator>
- struct static_data<Iterator, mpl::false_, mpl::true_>
- : static_data<Iterator, mpl::false_, mpl::false_>
+ template <typename Iterator, typename TokenValue>
+ struct static_data<Iterator, mpl::false_, mpl::true_, TokenValue>
+ : static_data<Iterator, mpl::false_, mpl::false_, TokenValue>
         {
         protected:
- typedef static_data<Iterator, mpl::false_, mpl::false_> base_type;
+ typedef static_data<Iterator, mpl::false_, mpl::false_, TokenValue> base_type;
             typedef typename base_type::char_type char_type;
 
         public:
             typedef Iterator base_iterator_type;
+ typedef unused_type token_value_type;
             typedef typename base_type::state_type state_type;
             typedef typename base_type::state_name_type state_name_type;
             typedef typename base_type::semantic_actions_type
@@ -242,22 +247,23 @@
 
         ///////////////////////////////////////////////////////////////////////
         // does support actors, but may have no state
- template <typename Iterator, typename HasState>
- struct static_data<Iterator, mpl::true_, HasState>
- : static_data<Iterator, mpl::false_, HasState>
+ template <typename Iterator, typename HasState, typename TokenValue>
+ struct static_data<Iterator, mpl::true_, HasState, TokenValue>
+ : static_data<Iterator, mpl::false_, HasState, TokenValue>
         {
         public:
             typedef semantic_actions<Iterator, HasState, static_data>
                 semantic_actions_type;
 
         protected:
- typedef static_data<Iterator, mpl::false_, HasState> base_type;
+ typedef static_data<Iterator, mpl::false_, HasState, TokenValue> base_type;
             typedef typename base_type::char_type char_type;
             typedef typename semantic_actions_type::functor_wrapper_type
                 functor_wrapper_type;
 
         public:
             typedef Iterator base_iterator_type;
+ typedef TokenValue token_value_type;
             typedef typename base_type::state_type state_type;
             typedef typename base_type::state_name_type state_name_type;
 
@@ -332,10 +338,25 @@
                 has_hold_ = true;
             }
 
+ TokenValue const& value() const
+ {
+ return value_;
+ }
+ TokenValue& value()
+ {
+ return value_;
+ }
+ template <typename Value>
+ void set_value(Value const& val)
+ {
+ value_ = val;
+ }
+
         protected:
             semantic_actions_type const& actions_;
             Iterator hold_; // iterator needed to support lex::more()
             bool has_hold_; // 'true' if hold_ is valid
+ TokenValue value_;
         };
     }
 

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp 2009-07-05 15:00:57 EDT (Sun, 05 Jul 2009)
@@ -167,8 +167,7 @@
     template <typename Token = token<>
       , typename LexerTables = static_::lexer
       , typename Iterator = typename Token::iterator_type
- , typename Functor
- = functor<Token, detail::static_data, Iterator, mpl::false_>
+ , typename Functor = functor<Token, detail::static_data, Iterator>
       , typename TokenSet
           = lex::token_set<static_token_set<Token, LexerTables, Iterator> > >
     class static_lexer


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