Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61128 - in trunk/boost/spirit/home/lex/lexer: . lexertl
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-07 11:49:21


Author: hkaiser
Date: 2010-04-07 11:49:20 EDT (Wed, 07 Apr 2010)
New Revision: 61128
URL: http://svn.boost.org/trac/boost/changeset/61128

Log:
Spirit: generated lexer tables are not minimzed by default anymore
Text files modified:
   trunk/boost/spirit/home/lex/lexer/lexer.hpp | 13 ++++++++++++-
   trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp | 2 +-
   trunk/boost/spirit/home/lex/lexer/lexertl/lexer.hpp | 19 +++++++++++++++----
   trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp | 2 +-
   4 files changed, 29 insertions(+), 7 deletions(-)

Modified: trunk/boost/spirit/home/lex/lexer/lexer.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexer.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexer.hpp 2010-04-07 11:49:20 EDT (Wed, 07 Apr 2010)
@@ -166,6 +166,17 @@
                     return *this;
                 }
 
+// template <typename F>
+// adder const& operator()(char_type c, id_type token_id, F act) const
+// {
+// if (id_type() == token_id)
+// token_id = def.def.get_next_id();
+// std::size_t unique_id =
+// def.def.add_token (def.state.c_str(), s, token_id);
+// def.def.add_action(unique_id, def.state.c_str(), act);
+// return *this;
+// }
+
                 lexer_def_& def;
 
             private:
@@ -356,4 +367,4 @@
 
 }}}
 
-#endif
+#endif
\ No newline at end of file

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp 2010-04-07 11:49:20 EDT (Wed, 07 Apr 2010)
@@ -917,7 +917,7 @@
     generate_static(Lexer const& lexer, std::ostream& os
       , char const* name_suffix, F f)
     {
- if (!lexer.init_dfa())
+ if (!lexer.init_dfa(true)) // always minimize DFA for static lexers
             return false;
         return detail::generate_cpp(lexer.state_machine_, lexer.rules_, os
           , name_suffix, f);

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/lexer.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/lexer.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/lexer.hpp 2010-04-07 11:49:20 EDT (Wed, 07 Apr 2010)
@@ -190,7 +190,7 @@
         iterator_type begin(Iterator& first, Iterator const& last
           , char_type const* initial_state = 0) const
         {
- if (!init_dfa())
+ if (!init_dfa()) // never minimize DFA for dynamic lexers
                 return iterator_type();
 
             iterator_data_type iterator_data(state_machine_, rules_, actions_);
@@ -268,14 +268,25 @@
             typedef typename Functor::wrap_action_type wrapper_type;
             actions_.add_action(unique_id, state, wrapper_type::call(act));
         }
-
- bool init_dfa() const
+// template <typename F>
+// void add_action(id_type unique_id, char_type const* state, F act)
+// {
+// typedef typename Functor::wrap_action_type wrapper_type;
+// actions_.add_action(unique_id, add_state(state), wrapper_type::call(act));
+// }
+
+ // We do not minimize the state machine by default anymore because
+ // Ben said: "If you can afford to generate a lexer at runtime, there
+ // is little point in calling minimise."
+ // Go figure.
+ bool init_dfa(bool minimize = false) const
         {
             if (!initialized_dfa_) {
                 state_machine_.clear();
                 typedef boost::lexer::basic_generator<char_type> generator;
                 generator::build (rules_, state_machine_);
- generator::minimise (state_machine_);
+ if (minimize)
+ generator::minimise (state_machine_);
 
 #if defined(BOOST_SPIRIT_LEXERTL_DEBUG)
                 boost::lexer::debug::dump(state_machine_, std::cerr);

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 2010-04-07 11:49:20 EDT (Wed, 07 Apr 2010)
@@ -229,7 +229,7 @@
             actions_.add_action(unique_id, state, wrapper_type::call(act));
         }
 
- bool init_dfa() const { return true; }
+ bool init_dfa(bool minimize = false) const { return true; }
 
     private:
         typename Functor::semantic_actions_type actions_;


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