Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57776 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2009-11-18 18:19:53


Author: danieljames
Date: 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
New Revision: 57776
URL: http://svn.boost.org/trac/boost/changeset/57776

Log:
Use spirit 2 for code snippets.
Text files modified:
   branches/quickbook-1.5-spirit2/code_snippet.hpp | 106 +++++++++++++++++++--------------------
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 28 +++++-----
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 13 ++--
   branches/quickbook-1.5-spirit2/detail/code_snippet.cpp | 10 +--
   branches/quickbook-1.5-spirit2/grammars.hpp | 51 ++++++------------
   5 files changed, 92 insertions(+), 116 deletions(-)

Modified: branches/quickbook-1.5-spirit2/code_snippet.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet.hpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet.hpp 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
@@ -9,39 +9,38 @@
 #if !defined(BOOST_SPIRIT_QUICKBOOK_CODE_SNIPPET_HPP)
 #define BOOST_SPIRIT_QUICKBOOK_CODE_SNIPPET_HPP
 
-#include <boost/spirit/include/classic_core.hpp>
-#include <boost/spirit/include/classic_actor.hpp>
+#include <boost/spirit/include/qi_core.hpp>
+#include <boost/spirit/include/qi_eol.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_bind.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
 #include "./grammars.hpp"
-#include "./detail/template_stack.hpp"
+#include "./parse_utils.hpp"
 #include "./detail/actions.hpp"
 
 namespace quickbook
 {
     namespace ph = boost::phoenix;
- using namespace ph::arg_names;
 
- template <typename Scanner>
- python_code_snippet_grammar::definition<Scanner>::definition(
- python_code_snippet_grammar const& self)
+ template <typename Iterator>
+ python_code_snippet_grammar<Iterator>::python_code_snippet_grammar(actions_type & actions)
+ : python_code_snippet_grammar::base_type(start_)
+ , actions(actions)
     {
- actions_type& actions = self.actions;
-
         start_ =
             +(
- snippet [ph::bind(&actions_type::compile, &actions, _1, _2)]
- | classic::anychar_p
+ qi::raw[snippet] [ph::bind(&actions_type::compile, &actions, qi::_1)]
+ | qi::char_
             )
             ;
 
         identifier =
- (classic::alpha_p | '_') >> *(classic::alnum_p | '_')
+ (qi::alpha | '_') >> *(qi::alnum | '_')
             ;
 
         snippet =
- "#[" >> *classic::space_p
- >> identifier [classic::assign_a(actions.id)]
+ "#[" >> *qi::space
+ >> identifier [ph::ref(actions.id) = qi::_1]
>> (*(code_elements - "#]"))
>> "#]"
             ;
@@ -49,58 +48,57 @@
         code_elements =
                 escaped_comment
             | ignore
- | (classic::anychar_p - "#]") [ph::bind(&actions_type::pass_thru, &actions, _1, _2)]
+ | (qi::char_ - "#]") [ph::bind(&actions_type::pass_thru, &actions, qi::_1)]
             ;
 
         ignore =
- *classic::blank_p >> "#<-"
- >> (*(classic::anychar_p - "#->"))
- >> "#->" >> *classic::blank_p >> classic::eol_p
+ *qi::blank >> "#<-"
+ >> (*(qi::char_ - "#->"))
+ >> "#->" >> *qi::blank >> qi::eol
             | "\"\"\"<-\"\"\""
- >> (*(classic::anychar_p - "\"\"\"->\"\"\""))
+ >> (*(qi::char_ - "\"\"\"->\"\"\""))
>> "\"\"\"->\"\"\""
             | "\"\"\"<-"
- >> (*(classic::anychar_p - "->\"\"\""))
+ >> (*(qi::char_ - "->\"\"\""))
>> "->\"\"\""
             ;
 
         escaped_comment =
- *classic::space_p >> "#`"
- >> ((*(classic::anychar_p - classic::eol_p))
- >> classic::eol_p) [ph::bind(&actions_type::escaped_comment, &actions, _1, _2)]
- | *classic::space_p >> "\"\"\"`"
- >> (*(classic::anychar_p - "\"\"\""))
- [ph::bind(&actions_type::escaped_comment, &actions, _1, _2)]
+ *qi::space >> "#`"
+ >> ((*(qi::char_ - qi::eol))
+ >> qi::eol) [ph::bind(&actions_type::escaped_comment, &actions, as_string(qi::_1))]
+ | *qi::space >> "\"\"\"`"
+ >> (*(qi::char_ - "\"\"\""))
+ [ph::bind(&actions_type::escaped_comment, &actions, as_string(qi::_1))]
>> "\"\"\""
             ;
     }
 
- template <typename Scanner>
- cpp_code_snippet_grammar::definition<Scanner>::definition(
- cpp_code_snippet_grammar const& self)
+ template <typename Iterator>
+ cpp_code_snippet_grammar<Iterator>::cpp_code_snippet_grammar(actions_type & actions)
+ : cpp_code_snippet_grammar::base_type(start_)
+ , actions(actions)
     {
- actions_type& actions = self.actions;
-
         start_ =
             +(
- snippet [ph::bind(&actions_type::compile, &actions, _1, _2)]
- | classic::anychar_p
+ qi::raw[snippet] [ph::bind(&actions_type::compile, &actions, qi::_1)]
+ | qi::char_
             )
             ;
 
         identifier =
- (classic::alpha_p | '_') >> *(classic::alnum_p | '_')
+ (qi::alpha | '_') >> *(qi::alnum | '_')
             ;
 
         snippet =
- "//[" >> *classic::space_p
- >> identifier [classic::assign_a(actions.id)]
+ "//[" >> *qi::space
+ >> identifier [ph::ref(actions.id) = qi::_1]
>> (*(code_elements - "//]"))
>> "//]"
             |
- "/*[" >> *classic::space_p
- >> identifier [classic::assign_a(actions.id)]
- >> *classic::space_p >> "*/"
+ "/*[" >> *qi::space
+ >> identifier [ph::ref(actions.id) = qi::_1]
+ >> *qi::space >> "*/"
>> (*(code_elements - "/*]*"))
>> "/*]*/"
             ;
@@ -110,42 +108,40 @@
             | ignore
             | line_callout
             | inline_callout
- | (classic::anychar_p - "//]" - "/*]*/")
- [ph::bind(&actions_type::pass_thru, &actions, _1, _2)]
+ | (qi::char_ - "//]" - "/*]*/") [ph::bind(&actions_type::pass_thru, &actions, qi::_1)]
             ;
 
         inline_callout =
             "/*<"
- >> (*(classic::anychar_p - ">*/")) [ph::bind(&actions_type::inline_callout, &actions, _1, _2)]
+ >> (*(qi::char_ - ">*/")) [ph::bind(&actions_type::inline_callout, &actions, as_string(qi::_1))]
>> ">*/"
             ;
 
         line_callout =
             "/*<<"
- >> (*(classic::anychar_p - ">>*/")) [ph::bind(&actions_type::line_callout, &actions, _1, _2)]
+ >> (*(qi::char_ - ">>*/")) [ph::bind(&actions_type::line_callout, &actions, as_string(qi::_1))]
>> ">>*/"
- >> *classic::space_p
+ >> *qi::space
             ;
 
         ignore =
- *classic::blank_p >> "//<-"
- >> (*(classic::anychar_p - "//->"))
- >> "//->" >> *classic::blank_p >> classic::eol_p
+ *qi::blank >> "//<-"
+ >> (*(qi::char_ - "//->"))
+ >> "//->" >> *qi::blank >> qi::eol
             | "/*<-*/"
- >> (*(classic::anychar_p - "/*->*/"))
+ >> (*(qi::char_ - "/*->*/"))
>> "/*->*/"
             | "/*<-"
- >> (*(classic::anychar_p - "->*/"))
+ >> (*(qi::char_ - "->*/"))
>> "->*/"
             ;
 
         escaped_comment =
- *classic::space_p >> "//`"
- >> ((*(classic::anychar_p - classic::eol_p))
- >> classic::eol_p) [ph::bind(&actions_type::escaped_comment, &actions, _1, _2)]
- | *classic::space_p >> "/*`"
- >> (*(classic::anychar_p - "*/"))
- [ph::bind(&actions_type::escaped_comment, &actions, _1, _2)]
+ *qi::space >> "//`"
+ >> ((*(qi::char_ - qi::eol))
+ >> qi::eol) [ph::bind(&actions_type::escaped_comment, &actions, as_string(qi::_1))]
+ | *qi::space >> "/*`"
+ >> (*(qi::char_ - "*/")) [ph::bind(&actions_type::escaped_comment, &actions, as_string(qi::_1))]
>> "*/"
             ;
     }

Modified: branches/quickbook-1.5-spirit2/detail/actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.cpp 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
@@ -1105,9 +1105,9 @@
         out << "\" />\n";
     }
 
- void code_snippet_actions::pass_thru(iterator first, iterator last)
+ void code_snippet_actions::pass_thru(char x)
     {
- code += *first;
+ code += x;
     }
 
     namespace detail
@@ -1115,7 +1115,7 @@
         int callout_id = 0;
     }
 
- void code_snippet_actions::callout(iterator first, iterator last, char const* role)
+ void code_snippet_actions::callout(std::string const& x, char const* role)
     {
         using detail::callout_id;
         code += "``'''";
@@ -1127,20 +1127,20 @@
         code += "</phrase>";
         code += "'''``";
 
- callouts.push_back(std::string(first, last));
+ callouts.push_back(x);
     }
 
- void code_snippet_actions::inline_callout(iterator first, iterator last)
+ void code_snippet_actions::inline_callout(std::string const& x)
     {
- callout(first, last, "callout_bug");
+ callout(x, "callout_bug");
     }
 
- void code_snippet_actions::line_callout(iterator first, iterator last)
+ void code_snippet_actions::line_callout(std::string const& x)
     {
- callout(first, last, "line_callout_bug");
+ callout(x, "line_callout_bug");
     }
 
- void code_snippet_actions::escaped_comment(iterator first, iterator last)
+ void code_snippet_actions::escaped_comment(std::string const& x)
     {
         if (!code.empty())
         {
@@ -1153,7 +1153,7 @@
                 code.clear();
             }
         }
- std::string temp(first, last);
+ std::string temp(x);
         detail::unindent(temp); // remove all indents
         if (temp.size() != 0)
         {
@@ -1161,7 +1161,7 @@
         }
     }
 
- void code_snippet_actions::compile(iterator first, iterator last)
+ void code_snippet_actions::compile(boost::iterator_range<iterator> x)
     {
         using detail::callout_id;
         if (!code.empty())
@@ -1197,7 +1197,7 @@
         std::vector<std::string> tinfo;
         tinfo.push_back(id);
         tinfo.push_back(snippet);
- storage.push_back(template_symbol(tinfo, first.get_position()));
+ storage.push_back(template_symbol(tinfo, x.begin().get_position()));
 
         callout_id += callouts.size();
         callouts.clear();
@@ -1228,10 +1228,10 @@
         code_snippet_actions a(storage, doc_id, is_python ? "[python]" : "[c++]");
         // TODO: Should I check that parse succeeded?
         if(is_python) {
- boost::spirit::classic::parse(first, last, python_code_snippet_grammar(a));
+ boost::spirit::qi::parse(first, last, python_code_snippet_grammar<iterator>(a));
         }
         else {
- boost::spirit::classic::parse(first, last, cpp_code_snippet_grammar(a));
+ boost::spirit::qi::parse(first, last, cpp_code_snippet_grammar<iterator>(a));
         }
 
         return 0;

Modified: branches/quickbook-1.5-spirit2/detail/actions.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions.hpp 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
@@ -17,6 +17,7 @@
 #include <stack>
 #include <algorithm>
 #include <boost/spirit/include/classic_iterator.hpp>
+#include <boost/spirit/include/qi_core.hpp>
 #include <boost/filesystem/operations.hpp>
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
@@ -797,12 +798,12 @@
             , source_type(source_type)
         {}
 
- void pass_thru(iterator first, iterator last);
- void escaped_comment(iterator first, iterator last);
- void compile(iterator first, iterator last);
- void callout(iterator first, iterator last, char const* role);
- void inline_callout(iterator first, iterator last);
- void line_callout(iterator first, iterator last);
+ void pass_thru(char);
+ void escaped_comment(std::string const&);
+ void compile(boost::iterator_range<iterator>);
+ void callout(std::string const&, char const* role);
+ void inline_callout(std::string const&);
+ void line_callout(std::string const&);
 
         std::string code;
         std::string snippet;

Modified: branches/quickbook-1.5-spirit2/detail/code_snippet.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/code_snippet.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/code_snippet.cpp 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
@@ -2,13 +2,9 @@
 
 namespace quickbook
 {
- typedef boost::spirit::classic::scanner<iterator> scanner;
-
- void instantiate_code_snippet(
- python_code_snippet_grammar& python,
- cpp_code_snippet_grammar& cpp)
+ void instantiate_code_snippet(code_snippet_actions& actions)
     {
- python_code_snippet_grammar::definition<scanner> python_definition(python);
- cpp_code_snippet_grammar::definition<scanner> cpp_definition(cpp);
+ python_code_snippet_grammar<iterator> python(actions);
+ cpp_code_snippet_grammar<iterator> cpp(actions);
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/grammars.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammars.hpp (original)
+++ branches/quickbook-1.5-spirit2/grammars.hpp 2009-11-18 18:19:52 EST (Wed, 18 Nov 2009)
@@ -14,6 +14,7 @@
 #include <boost/spirit/include/classic_symbols.hpp>
 #include <boost/spirit/include/classic_numerics.hpp>
 #include <boost/spirit/include/classic_iterator.hpp>
+#include <boost/spirit/include/qi_core.hpp>
 
 namespace quickbook
 {
@@ -149,54 +150,36 @@
     
     struct code_snippet_actions;
 
+ template <typename Iterator>
     struct python_code_snippet_grammar
- : classic::grammar<python_code_snippet_grammar>
+ : qi::grammar<Iterator>
     {
         typedef code_snippet_actions actions_type;
   
- python_code_snippet_grammar(actions_type & actions)
- : actions(actions)
- {}
+ python_code_snippet_grammar(actions_type & actions);
 
- template <typename Scanner>
- struct definition
- {
- typedef code_snippet_actions actions_type;
-
- definition(python_code_snippet_grammar const& self);
-
- classic::rule<Scanner>
- start_, snippet, identifier, code_elements, escaped_comment,
- inline_callout, line_callout, ignore;
-
- classic::rule<Scanner> const&
- start() const { return start_; }
- };
+ qi::rule<Iterator>
+ start_, snippet, code_elements, escaped_comment,
+ inline_callout, line_callout, ignore;
+ qi::rule<Iterator, std::string()>
+ identifier;
 
         actions_type& actions;
     };
 
+ template <typename Iterator>
     struct cpp_code_snippet_grammar
- : classic::grammar<cpp_code_snippet_grammar>
+ : qi::grammar<Iterator>
     {
         typedef code_snippet_actions actions_type;
   
- cpp_code_snippet_grammar(actions_type & actions)
- : actions(actions)
- {}
+ cpp_code_snippet_grammar(actions_type & actions);
 
- template <typename Scanner>
- struct definition
- {
- definition(cpp_code_snippet_grammar const& self);
-
- classic::rule<Scanner>
- start_, snippet, identifier, code_elements, escaped_comment,
- inline_callout, line_callout, ignore;
-
- classic::rule<Scanner> const&
- start() const { return start_; }
- };
+ qi::rule<Iterator>
+ start_, snippet, code_elements, escaped_comment,
+ inline_callout, line_callout, ignore;
+ qi::rule<Iterator, std::string()>
+ identifier;
 
         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