Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60136 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-03-03 18:30:32


Author: danieljames
Date: 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
New Revision: 60136
URL: http://svn.boost.org/trac/boost/changeset/60136

Log:
Move some common rules into their own file.
Added:
   branches/quickbook-1.5-spirit2/misc_rules.cpp (contents, props changed)
   branches/quickbook-1.5-spirit2/misc_rules.hpp (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 1
   branches/quickbook-1.5-spirit2/block_grammar.cpp | 37 -------------------------------
   branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp | 9 ------
   branches/quickbook-1.5-spirit2/doc_info_grammar.cpp | 14 -----------
   branches/quickbook-1.5-spirit2/phrase_grammar.cpp | 46 ++-------------------------------------
   branches/quickbook-1.5-spirit2/quickbook.cpp | 8 ++++++
   6 files changed, 15 insertions(+), 100 deletions(-)

Modified: branches/quickbook-1.5-spirit2/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/Jamfile.v2 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -42,6 +42,7 @@
     boostbook.cpp
     html.cpp
     encoder_impl.cpp
+ misc_rules.cpp
     /boost//program_options
     /boost//filesystem
     : #<define>QUICKBOOK_NO_DATES

Modified: branches/quickbook-1.5-spirit2/block_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_grammar.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -24,6 +24,7 @@
 #include "actions.hpp"
 #include "parse_utils.hpp"
 #include "code.hpp"
+#include "misc_rules.hpp"
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::paragraph,
@@ -160,13 +161,9 @@
         qi::rule<iterator, quickbook::formatted()> inside_paragraph2;
         qi::rule<iterator, std::string()> phrase_attr;
         qi::rule<iterator> phrase_end;
- qi::rule<iterator> comment, dummy_block;
         qi::rule<iterator, boost::optional<std::string>()> element_id;
         qi::rule<iterator, std::string()> element_id_part;
- qi::rule<iterator, std::string()> macro_identifier;
         qi::rule<iterator, std::string()> template_id;
- qi::rule<iterator> hard_space, space, blank, eol;
- qi::rule<iterator, file_position()> position;
         qi::rule<iterator> error;
     };
 
@@ -521,14 +518,6 @@
             ']' | qi::eps(ph::ref(no_eols)) >> eol >> eol
             ;
 
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
         // Identifiers
 
         element_id =
@@ -546,35 +535,11 @@
 
         element_id_part = +(qi::alnum | qi::char_('_'));
 
- macro_identifier =
- +(qi::char_ - (qi::space | ']'))
- ;
-
         template_id
             = (qi::alpha | '_') >> *(qi::alnum | '_')
             | qi::repeat(1)[qi::punct - qi::char_("[]")]
             ;
 
- // Used after an identifier that must not be immediately
- // followed by an alpha-numeric character or underscore.
- hard_space =
- !(qi::alnum | '_') >> space
- ;
-
- space =
- *(qi::space | comment)
- ;
-
- blank =
- *(qi::blank | comment)
- ;
-
- eol = blank >> qi::eol
- ;
-
- position =
- qi::raw[qi::eps] [get_position];
-
         error =
             qi::raw[qi::eps] [actions.error];
     }

Modified: branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/code_snippet_grammar.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -15,19 +15,12 @@
 #include "code_snippet_types.hpp"
 #include "grammars.hpp"
 #include "parse_utils.hpp"
+#include "misc_rules.hpp"
 
 namespace quickbook
 {
     namespace qi = boost::spirit::qi;
 
- namespace
- {
- // Shared rules
-
- qi::rule<iterator, file_position()>
- position = qi::raw[qi::eps] [get_position];
- }
-
     struct python_code_snippet_grammar::rules
     {
         typedef code_snippet_actions actions_type;

Modified: branches/quickbook-1.5-spirit2/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/doc_info_grammar.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -13,6 +13,7 @@
 #include "actions.hpp"
 #include "state.hpp"
 #include "parse_utils.hpp"
+#include "misc_rules.hpp"
 #include <boost/spirit/include/qi_core.hpp>
 #include <boost/spirit/include/qi_uint.hpp>
 #include <boost/spirit/include/qi_eol.hpp>
@@ -60,7 +61,6 @@
         phrase_grammar common;
         qi::symbols<char> doc_types;
         qi::rule<iterator, doc_info()> doc_info_details;
- qi::rule<iterator> comment, space, hard_space;
         qi::rule<iterator, std::pair<unsigned, unsigned>()> quickbook_version;
         qi::rule<iterator, std::string()> phrase, doc_version, doc_id, doc_dirname, doc_category, doc_last_revision, doc_source_mode, doc_purpose, doc_license;
         qi::rule<iterator, std::pair<std::vector<unsigned int>, std::string>()> doc_copyright;
@@ -181,18 +181,6 @@
                 )
             ;
 
- comment =
- "[/" >> *(qi::char_ - ']') >> ']'
- ;
-
- space =
- *(qi::space | comment)
- ;
-
- hard_space =
- !(qi::alnum | '_') >> space // must not be preceded by
- ; // alpha-numeric or underscore
-
         phrase =
                 qi::eps [actions.phrase_push]
>> *( common

Added: branches/quickbook-1.5-spirit2/misc_rules.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/misc_rules.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -0,0 +1,64 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to 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 <boost/spirit/include/qi_core.hpp>
+#include <boost/spirit/include/qi_eps.hpp>
+#include <boost/spirit/include/qi_eol.hpp>
+#include "misc_rules.hpp"
+#include "parse_utils.hpp"
+
+namespace quickbook
+{
+ namespace qi = boost::spirit::qi;
+
+ qi::rule<iterator, std::string()> macro_identifier;
+ qi::rule<iterator> dummy_block;
+ qi::rule<iterator> comment;
+ qi::rule<iterator> hard_space;
+ qi::rule<iterator> space;
+ qi::rule<iterator> blank;
+ qi::rule<iterator> eol;
+ qi::rule<iterator, file_position()> position;
+
+ void init_misc_rules() {
+ macro_identifier =
+ +(qi::char_ - (qi::space | ']'))
+ ;
+
+ dummy_block =
+ '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
+ ;
+
+ comment =
+ "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
+ ;
+
+ // Used after an identifier that must not be immediately
+ // followed by an alpha-numeric character or underscore.
+ hard_space =
+ !(qi::alnum | '_') >> space
+ ;
+
+ space =
+ *(qi::space | comment)
+ ;
+
+ blank =
+ *(qi::blank | comment)
+ ;
+
+ eol =
+ blank >> qi::eol
+ ;
+
+ position =
+ qi::raw[qi::eps] [get_position];
+ }
+}

Added: branches/quickbook-1.5-spirit2/misc_rules.hpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/misc_rules.hpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -0,0 +1,29 @@
+/*=============================================================================
+ Copyright (c) 2002 2004 2006 Joel de Guzman
+ Copyright (c) 2004 Eric Niebler
+ http://spirit.sourceforge.net/
+
+ Use, modification and distribution is subject to 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)
+=============================================================================*/
+#if !defined(BOOST_SPIRIT_QUICKBOOK_MISC_RULES_HPP)
+#define BOOST_SPIRIT_QUICKBOOK_MISC_RULES_HPP
+
+#include <boost/spirit/include/qi_core.hpp>
+#include "fwd.hpp"
+
+// Just a few stateless parser rules that are used in a lot of places.
+
+namespace quickbook
+{
+ extern boost::spirit::qi::rule<iterator, std::string()> macro_identifier;
+ extern boost::spirit::qi::rule<iterator> comment;
+ extern boost::spirit::qi::rule<iterator> eol;
+ extern boost::spirit::qi::rule<iterator> hard_space;
+ extern boost::spirit::qi::rule<iterator> space;
+ extern boost::spirit::qi::rule<iterator> blank;
+ extern boost::spirit::qi::rule<iterator, file_position()> position;
+}
+
+#endif
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/phrase_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_grammar.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -26,6 +26,7 @@
 #include "actions.hpp"
 #include "template.hpp"
 #include "parse_utils.hpp"
+#include "misc_rules.hpp"
 
 BOOST_FUSION_ADAPT_STRUCT(
     quickbook::anchor,
@@ -113,11 +114,8 @@
         qi::rule<iterator, quickbook::formatted()> escape_punct;
         qi::rule<iterator, quickbook::formatted()> escape_markup;
         qi::rule<iterator, quickbook::unicode_char()> escape_unicode;
- qi::rule<iterator> comment;
- qi::rule<iterator> dummy_block;
         qi::rule<iterator, quickbook::callout_link()> callout_link;
         qi::rule<iterator, quickbook::cond_phrase()> cond_phrase;
- qi::rule<iterator, std::string()> macro_identifier;
         qi::rule<iterator, quickbook::image()> image, image_1_4, image_1_5;
         qi::rule<iterator, std::string()> image_filename;
         qi::rule<iterator, quickbook::image::attribute_map()> image_attributes;
@@ -138,8 +136,7 @@
         qi::rule<iterator, quickbook::template_value()> template_arg_1_5;
         qi::rule<iterator> brackets_1_5;
         qi::rule<iterator, quickbook::break_()> break_;
- qi::rule<iterator> space, blank, eol, phrase_end, hard_space;
- qi::rule<iterator, file_position()> position;
+ qi::rule<iterator> phrase_end;
         
     };
 
@@ -291,14 +288,6 @@
>> qi::attr(nothing())
             ;
 
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
         // Don't use this, it's meant to be private.
         callout_link =
                 "[callout]"
@@ -315,10 +304,6 @@
>> -phrase
             ;
 
- macro_identifier =
- +(qi::char_ - (qi::space | ']'))
- ;
-
         image =
             (qi::eps(qbk_since(105u)) >> image_1_5) |
             (qi::eps(qbk_before(105u)) >> image_1_4);
@@ -464,29 +449,12 @@
>> qi::attr(nothing())
             ;
 
- space =
- *(qi::space | comment)
- ;
-
- blank =
- *(qi::blank | comment)
- ;
-
- eol = blank >> qi::eol
- ;
-
         phrase_end =
             ']' |
             qi::eps(ph::ref(no_eols)) >>
                 eol >> eol // Make sure that we don't go
             ; // past a single block, except
                                                 // when preformatted.
-
- hard_space =
- !(qi::alnum | '_') >> space
- ; // must not be preceded by
- // alpha-numeric or underscore
- position = qi::raw[qi::eps] [get_position];
     }
 
     struct simple_phrase_grammar::rules
@@ -496,7 +464,7 @@
         quickbook::actions& actions;
         bool unused;
         phrase_grammar common;
- qi::rule<iterator> phrase, comment, dummy_block;
+ qi::rule<iterator> phrase;
     };
 
     simple_phrase_grammar::simple_phrase_grammar(quickbook::actions& actions)
@@ -515,13 +483,5 @@
             | (qi::char_ - ']') [actions.process]
             )
             ;
-
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
     }
 }

Modified: branches/quickbook-1.5-spirit2/quickbook.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/quickbook.cpp (original)
+++ branches/quickbook-1.5-spirit2/quickbook.cpp 2010-03-03 18:30:31 EST (Wed, 03 Mar 2010)
@@ -158,9 +158,17 @@
 // Main program
 //
 ///////////////////////////////////////////////////////////////////////////
+
+namespace quickbook
+{
+ void init_misc_rules();
+}
+
 int
 main(int argc, char* argv[])
 {
+ quickbook::init_misc_rules();
+
     try
     {
         using boost::program_options::options_description;


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