Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62842 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-12 09:03:17


Author: danieljames
Date: 2010-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
New Revision: 62842
URL: http://svn.boost.org/trac/boost/changeset/62842

Log:
Rearrange the grammars a bit so that the markup rules could be independent.
Text files modified:
   branches/quickbook-1.5-spirit2/block_grammar.cpp | 27 ++++++++++++
   branches/quickbook-1.5-spirit2/block_markup_grammar.cpp | 23 ----------
   branches/quickbook-1.5-spirit2/grammar_impl.hpp | 7 ++
   branches/quickbook-1.5-spirit2/phrase_grammar.cpp | 84 +++++++++++++++++++++++++++++++++++++++
   branches/quickbook-1.5-spirit2/phrase_markup_grammar.cpp | 85 ---------------------------------------
   5 files changed, 117 insertions(+), 109 deletions(-)

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-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
@@ -12,6 +12,7 @@
 #include <boost/spirit/include/qi_attr.hpp>
 #include <boost/spirit/include/qi_eps.hpp>
 #include <boost/spirit/include/qi_eol.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/fusion/include/adapt_struct.hpp>
 #include "grammar_impl.hpp"
 #include "block.hpp"
@@ -40,6 +41,7 @@
 
     void quickbook_grammar::impl::init_block()
     {
+ qi::rule<iterator>& block_markup = store_.create();
         qi::rule<iterator>& blocks = store_.create();
         qi::rule<iterator, quickbook::code()>& code = store_.create();
         qi::rule<iterator, quickbook::list()>& list = store_.create();
@@ -61,6 +63,25 @@
             )
             ;
 
+ // Block markup
+
+ qi::rule<iterator, qi::locals<qi::rule<iterator> > >& block_markup_impl = store_.create();
+
+ block_markup =
+ '[' >> space
+ >> block_markup_impl
+ >> ( (space >> ']' >> +eol)
+ | error
+ )
+ ;
+
+ block_markup_impl
+ = ( block_keyword_rules >> !(qi::alnum | '_')
+ | block_symbol_rules
+ ) [qi::_a = qi::_1]
+ >> lazy(qi::_a)
+ ;
+
         // Blocks indicated by text layout (indentation, leading characters etc.)
 
         qi::rule<iterator>& code_line = store_.create();
@@ -164,5 +185,11 @@
                 )
                 | qi::attr("")
             ;
+
+ // Error
+
+ error =
+ qi::raw[qi::eps] [actions.error];
+
     }
 }

Modified: branches/quickbook-1.5-spirit2/block_markup_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_markup_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_markup_grammar.cpp 2010-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
@@ -113,26 +113,6 @@
         qi::rule<iterator, std::string()>& phrase_attr = store_.create();
         qi::rule<iterator>& phrase_end = store_.create();
         qi::rule<iterator, boost::optional<raw_string>()>& element_id = store_.create();
- qi::rule<iterator>& error = store_.create();
-
- qi::rule<iterator, qi::locals<qi::rule<iterator> > >& block_markup_impl = store_.create();
- qi::symbols<char, qi::rule<iterator> >& block_keyword_rules = store_.create();
- qi::symbols<char, qi::rule<iterator> >& block_symbol_rules = store_.create();
-
- block_markup =
- '[' >> space
- >> block_markup_impl
- >> ( (space >> ']' >> +eol)
- | error
- )
- ;
-
- block_markup_impl
- = ( block_keyword_rules >> !(qi::alnum | '_')
- | block_symbol_rules
- ) [qi::_a = qi::_1]
- >> lazy(qi::_a)
- ;
 
         // Sections
 
@@ -452,8 +432,5 @@
 
         element_id_part = qi::raw[+(qi::alnum | qi::char_('_'))]
                                                 [qi::_val = qi::_1];
-
- error =
- qi::raw[qi::eps] [actions.error];
     }
 }
\ No newline at end of file

Modified: branches/quickbook-1.5-spirit2/grammar_impl.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammar_impl.hpp (original)
+++ branches/quickbook-1.5-spirit2/grammar_impl.hpp 2010-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
@@ -31,12 +31,15 @@
         qi::rule<iterator> common;
         qi::rule<iterator> simple_phrase;
         qi::rule<iterator, std::string()> phrase;
- qi::rule<iterator> phrase_markup;
+ qi::symbols<char, qi::rule<iterator> > phrase_keyword_rules;
+ qi::symbols<char, qi::rule<iterator> > phrase_symbol_rules;
         
         // block
         qi::rule<iterator> block_start;
- qi::rule<iterator> block_markup;
         qi::rule<iterator> command_line_macro;
+ qi::symbols<char, qi::rule<iterator> > block_keyword_rules;
+ qi::symbols<char, qi::rule<iterator> > block_symbol_rules;
+ qi::rule<iterator> error;
 
         // doc_info
         qi::rule<iterator, quickbook::doc_info()> doc_info_details;

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-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
@@ -18,6 +18,7 @@
 #include "phrase_grammar.hpp"
 #include "code.hpp"
 #include "actions.hpp"
+#include "template.hpp"
 #include "misc_rules.hpp"
 
 BOOST_FUSION_ADAPT_STRUCT(
@@ -31,6 +32,20 @@
     (std::string, value)
 )
 
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::call_template,
+ (quickbook::file_position, position)
+ (bool, escape)
+ (quickbook::template_symbol const*, symbol)
+ (std::vector<quickbook::template_value>, args)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::template_value,
+ (quickbook::file_position, position)
+ (std::string, content)
+)
+
 namespace quickbook
 {
     namespace qi = boost::spirit::qi;
@@ -39,10 +54,13 @@
     void quickbook_grammar::impl::init_phrase()
     {
         qi::rule<iterator>& macro = store_.create();
+ qi::rule<iterator>& phrase_markup = store_.create();
         qi::rule<iterator, quickbook::code()>& code_block = store_.create();
         qi::rule<iterator, quickbook::code()>& inline_code = store_.create();
         qi::rule<iterator, quickbook::simple_markup(), qi::locals<char> >& simple_format = store_.create();
         qi::rule<iterator>& escape = store_.create();
+ qi::rule<iterator, quickbook::call_template()>& call_template = store_.create();
+ qi::rule<iterator, quickbook::break_()>& break_ = store_.create();
         qi::rule<iterator>& phrase_end = store_.create();
 
         simple_phrase =
@@ -77,6 +95,72 @@
             ) [actions.process]
             ;
 
+ qi::rule<iterator, qi::locals<qi::rule<iterator> > >& phrase_markup_impl = store_.create();
+
+ phrase_markup =
+ ( '['
+ >> ( phrase_markup_impl
+ | call_template [actions.process]
+ | break_ [actions.process]
+ )
+ >> ']'
+ )
+ ;
+
+ phrase_markup_impl
+ = ( phrase_keyword_rules >> !(qi::alnum | '_')
+ | phrase_symbol_rules
+ ) [qi::_a = qi::_1]
+ >> lazy(qi::_a)
+ ;
+
+ // Template call
+
+ qi::rule<iterator, std::vector<quickbook::template_value>()>& template_args = store_.create();
+ qi::rule<iterator, quickbook::template_value()>& template_arg_1_4 = store_.create();
+ qi::rule<iterator>& brackets_1_4 = store_.create();
+ qi::rule<iterator, quickbook::template_value()>& template_arg_1_5 = store_.create();
+ qi::rule<iterator>& brackets_1_5 = store_.create();
+
+ call_template =
+ position
+ >> qi::matches['`']
+ >> ( // Lookup the template name
+ (&qi::punct >> actions.templates.scope)
+ | (actions.templates.scope >> hard_space)
+ )
+ >> template_args
+ >> &qi::lit(']')
+ ;
+
+ template_args =
+ qi::eps(qbk_before(105u)) >> -(template_arg_1_4 % "..") |
+ qi::eps(qbk_since(105u)) >> -(template_arg_1_5 % "..");
+
+ template_arg_1_4 =
+ position >>
+ qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
+ ;
+
+ brackets_1_4 =
+ '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
+ ;
+
+ template_arg_1_5 =
+ position >>
+ qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
+ ;
+
+ brackets_1_5 =
+ '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
+ ;
+
+ break_ =
+ position
+ >> "br"
+ >> qi::attr(nothing())
+ ;
+
         code_block =
                 (
                     "```"

Modified: branches/quickbook-1.5-spirit2/phrase_markup_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_markup_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_markup_grammar.cpp 2010-06-12 09:03:16 EDT (Sat, 12 Jun 2010)
@@ -12,7 +12,6 @@
 #include <boost/spirit/include/qi_symbols.hpp>
 #include <boost/spirit/include/qi_attr.hpp>
 #include <boost/spirit/include/qi_eps.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/fusion/include/std_pair.hpp>
 #include "phrase_grammar.hpp"
 #include "actions.hpp"
@@ -45,20 +44,6 @@
 )
 
 BOOST_FUSION_ADAPT_STRUCT(
- quickbook::call_template,
- (quickbook::file_position, position)
- (bool, escape)
- (quickbook::template_symbol const*, symbol)
- (std::vector<quickbook::template_value>, args)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::template_value,
- (quickbook::file_position, position)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
     quickbook::callout_link,
     (std::string, role)
     (std::string, identifier)
@@ -71,31 +56,8 @@
 
     void quickbook_grammar::impl::init_phrase_markup()
     {
- qi::rule<iterator, quickbook::call_template()>& call_template = store_.create();
- qi::rule<iterator, quickbook::break_()>& break_ = store_.create();
         qi::rule<iterator>& phrase_end = store_.create();
 
- qi::rule<iterator, qi::locals<qi::rule<iterator> > >& phrase_markup_impl = store_.create();
- qi::symbols<char, qi::rule<iterator> >& phrase_keyword_rules = store_.create();
- qi::symbols<char, qi::rule<iterator> >& phrase_symbol_rules = store_.create();
-
- phrase_markup =
- ( '['
- >> ( phrase_markup_impl
- | call_template [actions.process]
- | break_ [actions.process]
- )
- >> ']'
- )
- ;
-
- phrase_markup_impl
- = ( phrase_keyword_rules >> !(qi::alnum | '_')
- | phrase_symbol_rules
- ) [qi::_a = qi::_1]
- >> lazy(qi::_a)
- ;
-
         // Callouts
 
         // Don't use this, it's meant to be private.
@@ -255,52 +217,7 @@
 
         formatted = qi::attr(qi::_r1) >> blank >> phrase;
 
- // Template call
-
- qi::rule<iterator, std::vector<quickbook::template_value>()>& template_args = store_.create();
- qi::rule<iterator, quickbook::template_value()>& template_arg_1_4 = store_.create();
- qi::rule<iterator>& brackets_1_4 = store_.create();
- qi::rule<iterator, quickbook::template_value()>& template_arg_1_5 = store_.create();
- qi::rule<iterator>& brackets_1_5 = store_.create();
-
- call_template =
- position
- >> qi::matches['`']
- >> ( // Lookup the template name
- (&qi::punct >> actions.templates.scope)
- | (actions.templates.scope >> hard_space)
- )
- >> template_args
- >> &qi::lit(']')
- ;
-
- template_args =
- qi::eps(qbk_before(105u)) >> -(template_arg_1_4 % "..") |
- qi::eps(qbk_since(105u)) >> -(template_arg_1_5 % "..");
-
- template_arg_1_4 =
- position >>
- qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
- ;
-
- brackets_1_4 =
- '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
- ;
-
- template_arg_1_5 =
- position >>
- qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
- ;
-
- brackets_1_5 =
- '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
- ;
-
- break_ =
- position
- >> "br"
- >> qi::attr(nothing())
- ;
+ // phrase_end
 
         phrase_end =
             ']' |


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