Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63161 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-20 16:29:56


Author: danieljames
Date: 2010-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
New Revision: 63161
URL: http://svn.boost.org/trac/boost/changeset/63161

Log:
Split up the grammars further.
Added:
   branches/quickbook-1.5-spirit2/code_grammar.cpp (contents, props changed)
   branches/quickbook-1.5-spirit2/template_grammar.cpp (contents, props changed)
Removed:
   branches/quickbook-1.5-spirit2/block_template_grammar.cpp
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 3
   branches/quickbook-1.5-spirit2/block_grammar.cpp | 27 +-----
   branches/quickbook-1.5-spirit2/grammar.cpp | 3
   branches/quickbook-1.5-spirit2/grammar_impl.hpp | 11 ++
   branches/quickbook-1.5-spirit2/phrase_grammar.cpp | 141 +++++++--------------------------------
   5 files changed, 46 insertions(+), 139 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-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -38,11 +38,12 @@
     phrase_image.cpp
     block_grammar.cpp
     block_markup_grammar.cpp
- block_template_grammar.cpp
     block_section_grammar.cpp
     block_table_grammar.cpp
     block_actions.cpp
     block_list.cpp
+ template_grammar.cpp
+ code_grammar.cpp
     doc_info_grammar.cpp
     doc_info_actions.cpp
     code_snippet_actions.cpp

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-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -15,9 +15,7 @@
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include "grammar_impl.hpp"
 #include "block.hpp"
-#include "template.hpp"
 #include "actions.hpp"
-#include "code.hpp"
 #include "misc_rules.hpp"
 #include "parse_utils.hpp"
 #include "state.hpp"
@@ -31,7 +29,6 @@
     {
         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();
         qi::rule<iterator, quickbook::hr()>& hr = store_.create();
         qi::rule<iterator>& paragraph = store_.create();
@@ -43,7 +40,7 @@
 
         blocks =
            +( block_markup
- | code [actions.process]
+ | indented_code [actions.process]
             | list [actions.process]
             | hr [actions.process]
             | block_separator [actions.process]
@@ -71,23 +68,7 @@
>> lazy(qi::_a)
                 ;
 
- // Blocks indicated by text layout (indentation, leading characters etc.)
-
- qi::rule<iterator>& code_line = store_.create();
-
- code =
- position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::flow, quickbook::code::block)]
- >> qi::raw[code_line >> *(*eol >> code_line)]
- [member_assign(&quickbook::code::content)]
- >> +eol
- ;
-
- code_line =
- qi::char_(" \t")
- >> *(qi::char_ - eol)
- >> eol
- ;
+ // List
 
         qi::rule<iterator, quickbook::list_item()>& list_item = store_.create();
         qi::rule<iterator, std::string()>& list_item_content = store_.create();
@@ -118,6 +99,8 @@
>> qi::eps[actions.phrase_pop]
             ;
 
+ // Horizontol rule
+
         hr =
             qi::omit[
                 "----"
@@ -129,6 +112,8 @@
         qi::rule<iterator>& paragraph_end = store_.create();
         qi::symbols<>& paragraph_end_markups = store_.create();
 
+ // Paragraph
+
         paragraph =
                +( common
                 | (qi::char_ - // Make sure we don't go past

Deleted: branches/quickbook-1.5-spirit2/block_template_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_template_grammar.cpp 2010-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
+++ (empty file)
@@ -1,67 +0,0 @@
-/*=============================================================================
- 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 "grammar_impl.hpp"
-#include "template.hpp"
-#include "actions.hpp"
-#include "misc_rules.hpp"
-#include "parse_utils.hpp"
-
-namespace quickbook
-{
- namespace qi = boost::spirit::qi;
-
- void quickbook_grammar::impl::init_block_template()
- {
- // Define Template
-
- qi::rule<iterator, quickbook::define_template()>& define_template = store_.create();
- qi::rule<iterator, std::vector<std::string>()>& define_template_params = store_.create();
- qi::rule<iterator, quickbook::template_value()>& template_body = store_.create();
- qi::rule<iterator>& template_body_recurse = store_.create();
- qi::rule<iterator, std::string()>& template_id = store_.create();
-
- block_keyword_rules.add("template", define_template[actions.process]);
-
- define_template =
- space
- >> template_id [member_assign(&quickbook::define_template::id)]
- >> -define_template_params [member_assign(&quickbook::define_template::params)]
- >> template_body [member_assign(&quickbook::define_template::body)]
- ;
-
- define_template_params =
- space
- >> '['
- >> *(space >> template_id)
- >> space
- >> ']'
- ;
-
- template_body =
- position [member_assign(&quickbook::template_value::position)]
- >> qi::raw[template_body_recurse] [member_assign(&quickbook::template_value::content)]
- ;
-
- template_body_recurse =
- *( ('[' >> template_body_recurse >> ']')
- | (qi::char_ - ']')
- )
- >> space
- >> &qi::lit(']')
- ;
-
- template_id
- = (qi::alpha | '_') >> *(qi::alnum | '_')
- | qi::repeat(1)[qi::punct - qi::char_("[]")]
- ;
- }
-}
\ No newline at end of file

Added: branches/quickbook-1.5-spirit2/code_grammar.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/code_grammar.cpp 2010-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -0,0 +1,90 @@
+/*=============================================================================
+ 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_eol.hpp>
+#include "grammar_impl.hpp"
+#include "actions.hpp"
+#include "code.hpp"
+#include "misc_rules.hpp"
+#include "parse_utils.hpp"
+
+namespace quickbook
+{
+ namespace qi = boost::spirit::qi;
+ namespace ph = boost::phoenix;
+
+ void quickbook_grammar::impl::init_code()
+ {
+ // Indented code
+
+ qi::rule<iterator, quickbook::code()>& indented_code_impl = store_.create();
+ qi::rule<iterator>& code_line = store_.create();
+
+ indented_code = indented_code_impl [actions.process];
+
+ indented_code_impl =
+ position [member_assign(&quickbook::code::position)]
+ [member_assign(&quickbook::code::flow, quickbook::code::block)]
+ >> qi::raw[code_line >> *(*eol >> code_line)]
+ [member_assign(&quickbook::code::content)]
+ >> +eol
+ ;
+
+ code_line =
+ qi::char_(" \t")
+ >> *(qi::char_ - eol)
+ >> eol
+ ;
+
+ qi::rule<iterator, quickbook::code()>& code_block1 = store_.create();
+ qi::rule<iterator, quickbook::code()>& code_block2 = store_.create();
+
+ code_block = (code_block1 | code_block2) [actions.process];
+
+ code_block1
+ = "```"
+ >> position [member_assign(&quickbook::code::position)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
+ >> qi::raw[*(qi::char_ - "```")] [member_assign(&quickbook::code::content)]
+ >> "```"
+ ;
+
+ code_block2
+ = "``"
+ >> position [member_assign(&quickbook::code::position)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
+ >> qi::raw[*(qi::char_ - "``")] [member_assign(&quickbook::code::content)]
+ >> "``"
+ ;
+
+ qi::rule<iterator, quickbook::code()>& inline_code_impl = store_.create();
+ qi::rule<iterator, std::string()>& inline_code_block = store_.create();
+
+ inline_code = inline_code_impl [actions.process];
+
+ inline_code_impl =
+ '`'
+ >> position [member_assign(&quickbook::code::position)]
+ [member_assign(&quickbook::code::flow, quickbook::code::inline_)]
+ >> inline_code_block [member_assign(&quickbook::code::content)]
+ >> '`'
+ ;
+
+ inline_code_block =
+ qi::raw
+ [ *( ~qi::char_('`') -
+ (qi::eol >> *qi::blank >> qi::eol) // Make sure that we don't go
+ )
+ >> &qi::lit('`')
+ ]
+ ;
+ }
+}

Modified: branches/quickbook-1.5-spirit2/grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/grammar.cpp 2010-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -39,7 +39,8 @@
         init_block_markup();
         init_block_section();
         init_block_table();
- init_block_template();
+ init_template();
+ init_code();
         init_doc_info();
     }
 }

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-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -34,7 +34,8 @@
         qi::symbols<char, qi::rule<iterator> > phrase_keyword_rules;
         qi::symbols<char, qi::rule<iterator> > phrase_symbol_rules;
         qi::rule<iterator> phrase_end;
-
+ qi::rule<iterator> call_template;
+
         // block
         qi::rule<iterator> block_start;
         qi::rule<iterator> command_line_macro;
@@ -44,6 +45,11 @@
         qi::rule<iterator, std::string()> phrase_attr;
         qi::rule<iterator, std::string()> inside_paragraph;
         qi::rule<iterator, boost::optional<raw_string>()> element_id;
+
+ // code
+ qi::rule<iterator> indented_code;
+ qi::rule<iterator> code_block;
+ qi::rule<iterator> inline_code;
 
         // doc_info
         qi::rule<iterator, quickbook::doc_info()> doc_info_details;
@@ -59,7 +65,8 @@
         void init_block_markup();
         void init_block_section();
         void init_block_table();
- void init_block_template();
+ void init_template();
+ void init_code();
         void init_doc_info();
     };
 }

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-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -18,7 +18,6 @@
 #include "phrase.hpp"
 #include "code.hpp"
 #include "actions.hpp"
-#include "template.hpp"
 #include "misc_rules.hpp"
 #include "parse_utils.hpp"
 
@@ -31,12 +30,8 @@
     {
         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, std::string(char)>& simple_format_body = 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();
 
         simple_phrase =
@@ -76,7 +71,7 @@
         phrase_markup =
             ( '['
>> ( phrase_markup_impl
- | call_template [actions.process]
+ | call_template
                 | break_ [actions.process]
                 )
>> ']'
@@ -90,127 +85,45 @@
>> 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 [member_assign(&quickbook::call_template::position)]
- >> qi::matches['`'] [member_assign(&quickbook::call_template::escape)]
- >> ( // Lookup the template name
- (&qi::punct >> actions.templates.scope)
- | (actions.templates.scope >> hard_space)
- ) [member_assign(&quickbook::call_template::symbol)]
- >> template_args [member_assign(&quickbook::call_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 [member_assign(&quickbook::template_value::position)]
- >> qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
- [member_assign(&quickbook::template_value::content)]
- ;
-
- brackets_1_4 =
- '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
- ;
-
- template_arg_1_5 =
- position [member_assign(&quickbook::template_value::position)]
- >> qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
- [member_assign(&quickbook::template_value::content)]
- ;
-
- brackets_1_5 =
- '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
- ;
-
         break_ =
                 position [member_assign(&quickbook::break_::position)]
>> "br"
             ;
 
- qi::rule<iterator, std::string()>& code_block1 = store_.create();
- qi::rule<iterator, std::string()>& code_block2 = store_.create();
- qi::rule<iterator, std::string()>& inline_code_block = store_.create();
-
- code_block =
- (
- "```"
- >> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
- >> code_block1 [member_assign(&quickbook::code::content)]
- >> "```"
- )
- | (
- "``"
- >> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::flow, quickbook::code::inline_block)]
- >> code_block2 [member_assign(&quickbook::code::content)]
- >> "``"
- )
- ;
-
- code_block1 = qi::raw[*(qi::char_ - "```")];
- code_block2 = qi::raw[*(qi::char_ - "``")];
-
- inline_code =
- '`'
- >> position [member_assign(&quickbook::code::position)]
- [member_assign(&quickbook::code::flow, quickbook::code::inline_)]
- >> inline_code_block [member_assign(&quickbook::code::content)]
- >> '`'
- ;
-
- inline_code_block =
- qi::raw
- [ *( qi::char_ -
- ( '`'
- | (eol >> eol) // Make sure that we don't go
- ) // past a single block
- )
- >> &qi::lit('`')
- ]
- ;
-
         qi::rule<iterator>& simple_phrase_end = store_.create();
+ qi::rule<iterator, std::string(char)>& simple_format_body = store_.create();
+ qi::rule<iterator, void(char)>& simple_format_chars = store_.create();
+ qi::rule<iterator, void(char)>& simple_format_end = store_.create();
 
- simple_format =
- qi::char_("*/_=") [qi::_a = qi::_1]
+ simple_format
+ = qi::char_("*/_=") [qi::_a = qi::_1]
>> simple_format_body(qi::_a) [member_assign(&quickbook::simple_markup::raw_content)]
>> qi::char_(qi::_a) [member_assign(&quickbook::simple_markup::symbol)]
             ;
 
- simple_format_body =
- qi::raw
- [ ( ( qi::graph // A single char. e.g. *c*
- >> &( qi::char_(qi::_r1)
- >> (qi::space | qi::punct | qi::eoi)
- )
- )
- |
- ( qi::graph // qi::graph must follow qi::lit(qi::_r1)
- >> *( qi::char_ -
- ( (qi::graph >> qi::lit(qi::_r1))
- | simple_phrase_end // Make sure that we don't go
- ) // past a single block
- )
- >> qi::graph // qi::graph must precede qi::lit(qi::_r1)
- >> &( qi::char_(qi::_r1)
- >> (qi::space | qi::punct | qi::eoi)
- )
- )
+ simple_format_body
+ = qi::raw
+ [ qi::graph
+ >> ( &simple_format_end(qi::_r1)
+ | simple_format_chars(qi::_r1)
                     )
                 ]
- ;
+ ;
+
+ simple_format_multiple_char
+ = *( qi::char_ -
+ ( (qi::graph >> qi::lit(qi::_r1))
+ | simple_phrase_end // Make sure that we don't go
+ ) // past a single block
+ )
+ >> qi::graph // qi::graph must precede qi::lit(qi::_r1)
+ >> &simple_format_end(qi::_r1)
+ ;
+
+ simple_format_end
+ = qi::lit(qi::_r1)
+ >> (qi::space | qi::punct | qi::eoi)
+ ;
 
         simple_phrase_end = '[' | phrase_end;
 

Added: branches/quickbook-1.5-spirit2/template_grammar.cpp
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/template_grammar.cpp 2010-06-20 16:29:55 EDT (Sun, 20 Jun 2010)
@@ -0,0 +1,114 @@
+/*=============================================================================
+ 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 "grammar_impl.hpp"
+#include "template.hpp"
+#include "actions.hpp"
+#include "misc_rules.hpp"
+#include "parse_utils.hpp"
+
+namespace quickbook
+{
+ namespace qi = boost::spirit::qi;
+
+ void quickbook_grammar::impl::init_template()
+ {
+ // Define Template
+
+ qi::rule<iterator, quickbook::define_template()>& define_template = store_.create();
+ qi::rule<iterator, std::vector<std::string>()>& define_template_params = store_.create();
+ qi::rule<iterator, quickbook::template_value()>& template_body = store_.create();
+ qi::rule<iterator>& template_body_recurse = store_.create();
+ qi::rule<iterator, std::string()>& template_id = store_.create();
+
+ block_keyword_rules.add("template", define_template[actions.process]);
+
+ define_template =
+ space
+ >> template_id [member_assign(&quickbook::define_template::id)]
+ >> -define_template_params [member_assign(&quickbook::define_template::params)]
+ >> template_body [member_assign(&quickbook::define_template::body)]
+ ;
+
+ define_template_params =
+ space
+ >> '['
+ >> *(space >> template_id)
+ >> space
+ >> ']'
+ ;
+
+ template_body =
+ position [member_assign(&quickbook::template_value::position)]
+ >> qi::raw[template_body_recurse] [member_assign(&quickbook::template_value::content)]
+ ;
+
+ template_body_recurse =
+ *( ('[' >> template_body_recurse >> ']')
+ | (qi::char_ - ']')
+ )
+ >> space
+ >> &qi::lit(']')
+ ;
+
+ template_id
+ = (qi::alpha | '_') >> *(qi::alnum | '_')
+ | qi::repeat(1)[qi::punct - qi::char_("[]")]
+ ;
+
+ // Call Template
+
+ qi::rule<iterator, quickbook::call_template()>& call_template_impl = store_.create();
+ 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 = call_template_impl[actions.process];
+
+ call_template_impl =
+ position [member_assign(&quickbook::call_template::position)]
+ >> qi::matches['`'] [member_assign(&quickbook::call_template::escape)]
+ >> ( // Lookup the template name
+ (&qi::punct >> actions.templates.scope)
+ | (actions.templates.scope >> hard_space)
+ ) [member_assign(&quickbook::call_template::symbol)]
+ >> template_args [member_assign(&quickbook::call_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 [member_assign(&quickbook::template_value::position)]
+ >> qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
+ [member_assign(&quickbook::template_value::content)]
+ ;
+
+ brackets_1_4 =
+ '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
+ ;
+
+ template_arg_1_5 =
+ position [member_assign(&quickbook::template_value::position)]
+ >> qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
+ [member_assign(&quickbook::template_value::content)]
+ ;
+
+ brackets_1_5 =
+ '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
+ ;
+ }
+}


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