Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62841 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-12 09:02:55


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

Log:
Use the Nabialek trick.
Text files modified:
   branches/quickbook-1.5-spirit2/block_markup_grammar.cpp | 173 +++++++++++++++++++++++----------------
   branches/quickbook-1.5-spirit2/phrase_markup_grammar.cpp | 150 +++++++++++++++++++--------------
   2 files changed, 186 insertions(+), 137 deletions(-)

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:02:54 EDT (Sat, 12 Jun 2010)
@@ -108,19 +108,6 @@
 
     void quickbook_grammar::impl::init_block_markup()
     {
- qi::rule<iterator, quickbook::begin_section()>& begin_section = store_.create();
- qi::rule<iterator, quickbook::end_section()>& end_section = store_.create();
- qi::rule<iterator, quickbook::heading()>& heading = store_.create();
- qi::rule<iterator, quickbook::formatted()>& paragraph_block = store_.create();
- qi::rule<iterator, quickbook::formatted()>& blockquote = store_.create();
- qi::rule<iterator, quickbook::formatted()>& preformatted = store_.create();
- qi::rule<iterator, quickbook::def_macro()>& def_macro = store_.create();
- qi::rule<iterator, quickbook::table()>& table = store_.create();
- qi::rule<iterator, quickbook::variablelist()>& variablelist = store_.create();
- qi::rule<iterator, quickbook::xinclude()>& xinclude = store_.create();
- qi::rule<iterator, quickbook::include()>& include = store_.create();
- qi::rule<iterator, quickbook::import()>& import = store_.create();
- qi::rule<iterator, quickbook::define_template()>& define_template = store_.create();
         qi::rule<iterator, quickbook::title()>& title_phrase = store_.create();
         qi::rule<iterator, std::string()>& inside_paragraph = store_.create();
         qi::rule<iterator, std::string()>& phrase_attr = store_.create();
@@ -128,98 +115,118 @@
         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
- >> ( begin_section
- | end_section
- | heading
- | paragraph_block
- | blockquote
- | preformatted
- | def_macro
- | table
- | variablelist
- | xinclude
- | include
- | import
- | define_template
- ) [actions.process]
+ >> 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
+
+ qi::rule<iterator, quickbook::begin_section()>& begin_section = store_.create();
+ qi::rule<iterator, quickbook::end_section()>& end_section = store_.create();
+ block_keyword_rules.add("section", begin_section[actions.process]);
+ block_keyword_rules.add("endsect", end_section[actions.process]);
+
         begin_section =
- "section"
- >> hard_space
+ space
>> element_id
>> title_phrase
             ;
 
         end_section =
- position
- >> "endsect"
+ space
+ >> position
>> qi::attr(nothing())
             ;
 
- qi::symbols<char, int>& heading_symbol = store_.create();
- heading = heading_symbol >> hard_space >> title_phrase;
+ // Headings
 
- heading_symbol.add
- ("h1", 1)
- ("h2", 2)
- ("h3", 3)
- ("h4", 4)
- ("h5", 5)
- ("h6", 6)
- ("heading", -1);
+ qi::rule<iterator, quickbook::heading(int)>& heading = store_.create();
 
- qi::symbols<char, quickbook::formatted_type>& paragraph_blocks = store_.create();
+ block_keyword_rules.add
+ ("h1", heading(1) [actions.process])
+ ("h2", heading(2) [actions.process])
+ ("h3", heading(3) [actions.process])
+ ("h4", heading(4) [actions.process])
+ ("h5", heading(5) [actions.process])
+ ("h6", heading(6) [actions.process])
+ ("heading", heading(-1) [actions.process]);
 
- paragraph_block =
- paragraph_blocks >> hard_space >> inside_paragraph
+ heading = qi::attr(qi::_r1) >> space >> title_phrase;
+
+ // Paragraph Blocks
+
+ qi::rule<iterator, quickbook::formatted(formatted_type)>& paragraph_block = store_.create();
+
+ block_keyword_rules.add
+ ("blurb", paragraph_block(formatted_type("blurb")) [actions.process])
+ ("warning", paragraph_block(formatted_type("warning")) [actions.process])
+ ("caution", paragraph_block(formatted_type("caution")) [actions.process])
+ ("important", paragraph_block(formatted_type("important")) [actions.process])
+ ("note", paragraph_block(formatted_type("note")) [actions.process])
+ ("tip", paragraph_block(formatted_type("tip")) [actions.process])
             ;
 
- paragraph_blocks.add
- ("blurb", formatted_type("blurb"))
- ("warning", formatted_type("warning"))
- ("caution", formatted_type("caution"))
- ("important", formatted_type("important"))
- ("note", formatted_type("note"))
- ("tip", formatted_type("tip"))
+ block_symbol_rules.add
+ (":", paragraph_block(formatted_type("blockquote")) [actions.process])
             ;
 
- blockquote =
- ':'
- >> blank
- >> qi::attr(formatted_type("blockquote"))
- >> inside_paragraph
+ paragraph_block =
+ qi::attr(qi::_r1) >> space >> inside_paragraph
             ;
 
+ // Preformatted
+
+ qi::rule<iterator, quickbook::formatted()>& preformatted = store_.create();
+
+ block_keyword_rules.add("pre", preformatted [actions.process]);
+
         preformatted %=
- "pre"
- >> hard_space [ph::ref(no_eols) = false]
+ space [ph::ref(no_eols) = false]
>> -eol
>> qi::attr(formatted_type("preformatted"))
>> phrase_attr
>> qi::eps [ph::ref(no_eols) = true]
             ;
 
+ // Define Macro
+
+ qi::rule<iterator, quickbook::def_macro()>& def_macro = store_.create();
+
+ block_keyword_rules.add("def", def_macro[actions.process]);
+
         def_macro =
- "def"
- >> hard_space
+ space
>> macro_identifier
>> blank
>> phrase_attr
             ;
 
+ // Table
+
+ qi::rule<iterator, quickbook::table()>& table = store_.create();
         qi::rule<iterator, quickbook::table_row()>& table_row = store_.create();
         qi::rule<iterator, quickbook::table_cell()>& table_cell = store_.create();
         qi::rule<iterator, quickbook::formatted()>& table_cell_body = store_.create();
+
+ block_keyword_rules.add("table", table[actions.process]);
 
         table =
- "table"
- >> (&(*qi::blank >> qi::eol) | hard_space)
+ (&(*qi::blank >> qi::eol) | space)
>> ((qi::eps(qbk_since(105u)) >> element_id) | qi::eps)
>> (&(*qi::blank >> qi::eol) | space)
>> *(qi::char_ - eol)
@@ -248,15 +255,17 @@
>> inside_paragraph
             ;
 
+ qi::rule<iterator, quickbook::variablelist()>& variablelist = store_.create();
         qi::rule<iterator, quickbook::varlistentry()>& varlistentry = store_.create();
         qi::rule<iterator, quickbook::formatted()>& varlistterm = store_.create();
         qi::rule<iterator, quickbook::formatted()>& varlistterm_body = store_.create();
         qi::rule<iterator, quickbook::formatted()>& varlistitem = store_.create();
         qi::rule<iterator, quickbook::formatted()>& varlistitem_body = store_.create();
+
+ block_keyword_rules.add("variablelist", variablelist[actions.process]);
 
         variablelist =
- "variablelist"
- >> (&(*qi::blank >> qi::eol) | hard_space)
+ (&(*qi::blank >> qi::eol) | space)
>> *(qi::char_ - eol)
>> +eol
>> *varlistentry
@@ -299,19 +308,28 @@
>> inside_paragraph
             ;
 
+ // xinclude
+
+ qi::rule<iterator, quickbook::xinclude()>& xinclude = store_.create();
+
+ block_keyword_rules.add("xinclude", xinclude[actions.process]);
+
         // TODO: Why do these use phrase_end? It doesn't make any sense.
         xinclude =
- "xinclude"
- >> hard_space
+ space
>> *(qi::char_ - phrase_end)
>> qi::attr(nothing())
             ;
 
+ qi::rule<iterator, quickbook::include()>& include = store_.create();
         qi::rule<iterator, raw_string()>& include_id = store_.create();
+
+ block_keyword_rules.add("include", include[actions.process]);
+
+ // Include
 
         include =
- "include"
- >> hard_space
+ space
>> -(
                     ':'
>> include_id
@@ -323,20 +341,29 @@
         include_id = qi::raw[*((qi::alnum | '_') - qi::space)]
                                             [qi::_val = qi::_1];
 
+ // Import
+
+ qi::rule<iterator, quickbook::import()>& import = store_.create();
+
+ block_keyword_rules.add("import", import[actions.process]);
+
         import =
- "import"
- >> hard_space
+ space
>> *(qi::char_ - phrase_end)
>> qi::attr(nothing())
             ;
 
+ // Define Template
+
+ qi::rule<iterator, quickbook::define_template()>& define_template = 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 =
- "template"
- >> hard_space
+ space
>> template_id
>> -(
                     space

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:02:54 EDT (Sat, 12 Jun 2010)
@@ -12,6 +12,7 @@
 #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"
@@ -70,53 +71,60 @@
 
     void quickbook_grammar::impl::init_phrase_markup()
     {
- qi::rule<iterator, quickbook::callout_link()>& callout_link = store_.create();
- qi::rule<iterator, quickbook::cond_phrase()>& cond_phrase = store_.create();
- qi::rule<iterator, quickbook::image()>& image = store_.create();
- qi::rule<iterator, quickbook::link()>& url = store_.create();
- qi::rule<iterator, quickbook::link()>& link = store_.create();
- qi::rule<iterator, quickbook::anchor()>& anchor = store_.create();
- qi::symbols<char, quickbook::source_mode>& source_mode = store_.create();
- qi::rule<iterator, quickbook::formatted()>& formatted = store_.create();
- qi::rule<iterator, quickbook::formatted()>& footnote = 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();
 
+ 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 =
             ( '['
- >> ( callout_link
- | cond_phrase
- | image
- | url
- | link
- | anchor
- | source_mode
- | formatted
- | footnote
- | call_template
- | break_
+ >> ( phrase_markup_impl
+ | call_template [actions.process]
+ | break_ [actions.process]
                 )
>> ']'
- ) [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.
+ qi::rule<iterator, quickbook::callout_link()>& callout_link = store_.create();
+
+ phrase_symbol_rules.add("[callout]", callout_link [actions.process]);
+
         callout_link =
- "[callout]"
- >> *~qi::char_(' ')
+ *~qi::char_(' ')
>> ' '
>> *~qi::char_(']')
>> qi::attr(nothing())
             ;
 
+ // Conditional Phrase
+
+ qi::rule<iterator, quickbook::cond_phrase()>& cond_phrase = store_.create();
+
+ phrase_symbol_rules.add("?", cond_phrase [actions.process]);
+
         cond_phrase =
- '?'
- >> blank
+ blank
>> macro_identifier
>> -phrase
             ;
 
+ // Images
+
+ qi::rule<iterator, quickbook::image()>& image = store_.create();
         qi::rule<iterator, quickbook::image()>& image_1_4 = store_.create();
         qi::rule<iterator, quickbook::image()>& image_1_5 = store_.create();
         qi::rule<iterator, std::string()>& image_filename = store_.create();
@@ -124,6 +132,8 @@
         qi::rule<iterator, std::pair<std::string, std::string>()>& image_attribute = store_.create();
         qi::rule<iterator, std::string()>& image_attribute_key = store_.create();
         qi::rule<iterator, std::string()>& image_attribute_value = store_.create();
+
+ phrase_symbol_rules.add("$", image [actions.process]);
 
         image =
             (qi::eps(qbk_since(105u)) >> image_1_5) |
@@ -131,7 +141,6 @@
         
         image_1_4 =
                 position
- >> '$'
>> blank
>> *(qi::char_ - phrase_end)
>> &qi::lit(']')
@@ -139,7 +148,6 @@
         
         image_1_5 =
                 position
- >> '$'
>> blank
>> image_filename
>> hard_space
@@ -167,9 +175,13 @@
         image_attribute_key = *(qi::alnum | '_');
         image_attribute_value = *(qi::char_ - (phrase_end | '['));
 
- url =
- '@'
- >> qi::attr("url")
+ // URL
+
+ qi::rule<iterator, quickbook::link()>& url = store_.create();
+
+ phrase_symbol_rules.add("@", url [actions.process]);
+
+ url = qi::attr("url")
>> *(qi::char_ - (']' | qi::space))
>> ( &qi::lit(']')
                 | (hard_space >> phrase)
@@ -178,61 +190,71 @@
 
         qi::symbols<char, formatted_type>& link_symbol = store_.create();
 
+ // Link
+
+ qi::rule<iterator, quickbook::link(formatted_type)>& link = store_.create();
+
+ phrase_keyword_rules.add
+ ("link", link(formatted_type("link")) [actions.process])
+ ("funcref", link(formatted_type("funcref")) [actions.process])
+ ("classref", link(formatted_type("classref")) [actions.process])
+ ("memberref", link(formatted_type("memberref")) [actions.process])
+ ("enumref", link(formatted_type("enumref")) [actions.process])
+ ("macroref", link(formatted_type("macroref")) [actions.process])
+ ("headerref", link(formatted_type("headerref")) [actions.process])
+ ("conceptref", link(formatted_type("conceptref")) [actions.process])
+ ("globalref", link(formatted_type("globalref")) [actions.process])
+ ;
+
         link =
- link_symbol
- >> hard_space
+ qi::attr(qi::_r1)
+ >> space
>> *(qi::char_ - (']' | qi::space))
>> ( &qi::lit(']')
                 | (hard_space >> phrase)
                 )
             ;
 
- link_symbol.add
- ("link", formatted_type("link"))
- ("funcref", formatted_type("funcref"))
- ("classref", formatted_type("classref"))
- ("memberref", formatted_type("memberref"))
- ("enumref", formatted_type("enumref"))
- ("macroref", formatted_type("macroref"))
- ("headerref", formatted_type("headerref"))
- ("conceptref", formatted_type("conceptref"))
- ("globalref", formatted_type("globalref"))
- ;
+ // Anchor
+
+ qi::rule<iterator, quickbook::anchor()>& anchor = store_.create();
+
+ phrase_symbol_rules.add("#", anchor [actions.process]);
 
         anchor =
- '#'
- >> blank
+ blank
>> *(qi::char_ - phrase_end)
>> qi::attr(nothing())
             ;
 
- source_mode.add
- ("c++", quickbook::source_mode("c++"))
- ("python", quickbook::source_mode("python"))
- ("teletype", quickbook::source_mode("teletype"))
+ // Source Mode
+
+ phrase_keyword_rules.add
+ ("c++", qi::attr(quickbook::source_mode("c++")) [actions.process])
+ ("python", qi::attr(quickbook::source_mode("python")) [actions.process])
+ ("teletype", qi::attr(quickbook::source_mode("teletype")) [actions.process])
             ;
 
- qi::symbols<char, formatted_type>& format_symbol = store_.create();
+ // Formatted
 
- formatted = format_symbol >> blank >> phrase;
+ qi::rule<iterator, quickbook::formatted(formatted_type)>& formatted = store_.create();
 
- format_symbol.add
- ("*", "bold")
- ("'", "italic")
- ("_", "underline")
- ("^", "teletype")
- ("-", "strikethrough")
- ("\"", "quote")
- ("~", "replaceable")
+ phrase_symbol_rules.add
+ ("*", formatted(formatted_type("bold")) [actions.process])
+ ("'", formatted(formatted_type("italic")) [actions.process])
+ ("_", formatted(formatted_type("underline")) [actions.process])
+ ("^", formatted(formatted_type("teletype")) [actions.process])
+ ("-", formatted(formatted_type("strikethrough")) [actions.process])
+ ("\"", formatted(formatted_type("quote")) [actions.process])
+ ("~", formatted(formatted_type("replaceable")) [actions.process])
             ;
 
- footnote =
- "footnote"
- >> qi::attr("footnote")
- >> blank
- >> phrase
+ phrase_keyword_rules.add
+ ("footnote", formatted(formatted_type("footnote")) [actions.process])
             ;
 
+ formatted = qi::attr(qi::_r1) >> blank >> phrase;
+
         // Template call
 
         qi::rule<iterator, std::vector<quickbook::template_value>()>& template_args = store_.create();


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