Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58045 - in branches/quickbook-1.5-spirit2: . detail test
From: daniel_james_at_[hidden]
Date: 2009-11-29 17:52:26


Author: danieljames
Date: 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
New Revision: 58045
URL: http://svn.boost.org/trac/boost/changeset/58045

Log:
Use synthesized attributes for images.
Added:
   branches/quickbook-1.5-spirit2/test/fail-image_1_5.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-1.5-spirit2/detail/actions.cpp | 48 +++++++++++++++++-------
   branches/quickbook-1.5-spirit2/detail/actions.hpp | 34 ++++-------------
   branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 6 --
   branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 4 --
   branches/quickbook-1.5-spirit2/phrase.hpp | 76 ++++++++++++++++++++++++---------------
   branches/quickbook-1.5-spirit2/test/Jamfile.v2 | 1
   6 files changed, 91 insertions(+), 78 deletions(-)

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-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -10,6 +10,8 @@
 =============================================================================*/
 #include <numeric>
 #include <functional>
+#include <algorithm>
+#include <iterator>
 #include <boost/filesystem/convenience.hpp>
 #include <boost/filesystem/fstream.hpp>
 #include <boost/lexical_cast.hpp>
@@ -395,21 +397,33 @@
         detail::print_char(*x.begin(), phrase.get());
     }
 
- void attribute_action::operator()(iterator_range x, unused_type, unused_type) const
+ void image_action::operator()(iterator position, std::string image_fileref,
+ std::multimap<std::string, std::string> input_attributes) const
     {
- boost::spirit::classic::file_position const pos = x.begin().get_position();
-
- if (!attributes.insert(
- attribute_map::value_type(attribute_name, std::string(x.begin(), x.end()))
- ).second)
- {
- detail::outerr(pos.file,pos.line)
- << "Repeated attribute: " << attribute_name << ".\n";
+ std::map<std::string, std::string> attributes(
+ input_attributes.begin(), input_attributes.end());
+
+ if(attributes.size() != input_attributes.size()) {
+ boost::spirit::classic::file_position const pos = position.get_position();
+
+ std::map<std::string, std::string> duplicates;
+ std::set_difference(
+ input_attributes.begin(), input_attributes.end(),
+ attributes.begin(), attributes.end(),
+ std::inserter(duplicates, duplicates.end()));
+
+ for(std::map<std::string, std::string>::iterator
+ begin = duplicates.begin(), end = duplicates.end();
+ begin != end; ++begin)
+ {
+ detail::outerr(pos.file,pos.line)
+ << "Duplicate image attribute: "
+ << begin->first
+ << std::endl;
+ ++error_count;
+ }
         }
- }
-
- void image_action::operator()(unused_type, unused_type, unused_type) const
- {
+
         fs::path const img_path(image_fileref);
         
         attribute_map::iterator it = attributes.find("alt");
@@ -434,6 +448,8 @@
            attributes.insert(attribute_map::value_type("format", "SVG"));
            //
            // Image paths are relative to the html subdirectory:
+ // TODO: This only works when you're running in the correct directory.
+ // Support 'boost:' directories? Include paths?
            //
            fs::path img;
            if(img_path.root_path().empty())
@@ -1218,10 +1234,12 @@
         code_snippet_actions a(storage, doc_id, is_python ? "[python]" : "[c++]");
         // TODO: Should I check that parse succeeded?
         if(is_python) {
- boost::spirit::qi::parse(first, last, python_code_snippet_grammar<iterator>(a));
+ python_code_snippet_grammar<iterator> g(a);
+ boost::spirit::qi::parse(first, last, g);
         }
         else {
- boost::spirit::qi::parse(first, last, cpp_code_snippet_grammar<iterator>(a));
+ cpp_code_snippet_grammar<iterator> g(a);
+ boost::spirit::qi::parse(first, last, g);
         }
 
         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-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -373,39 +373,23 @@
         collector& phrase;
     };
     
- struct attribute_action
- {
- // Handle image attributes
-
- attribute_action(
- attribute_map& attributes
- , std::string& attribute_name)
- : attributes(attributes)
- , attribute_name(attribute_name) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- attribute_map& attributes;
- std::string& attribute_name;
- };
-
     struct image_action
     {
+ template <typename Arg1, typename Arg2, typename Arg3 = void>
+ struct result {typedef void type; };
+
         // Handles inline images
 
- image_action(
- collector& phrase
- , attribute_map& attributes
- , std::string& image_fileref)
+ image_action(collector& phrase, int& error_count)
         : phrase(phrase)
- , attributes(attributes)
- , image_fileref(image_fileref) {}
+ , error_count(error_count) {}
 
- void operator()(unused_type, unused_type, unused_type) const;
+ void operator()(iterator, std::string,
+ std::multimap<std::string, std::string>
+ = std::multimap<std::string, std::string>()) const;
 
         collector& phrase;
- attribute_map& attributes;
- std::string& image_fileref;
+ int& error_count;
     };
 
     struct markup_action

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.cpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.cpp 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -62,9 +62,6 @@
         , template_escape(false)
         , templates()
         , error_count(0)
- , image_fileref()
- , attribute_name()
- , attributes()
 
     // actions
         , error(error_count)
@@ -95,8 +92,7 @@
         , tip(out, temp_para, tip_pre, tip_post)
         , plain_char(phrase)
         , raw_char(phrase)
- , attribute(attributes, attribute_name)
- , image(phrase, attributes, image_fileref)
+ , image(phrase, error_count)
         , cond_phrase_pre(phrase, conditions, macro)
         , cond_phrase_post(phrase, conditions, macro)
 

Modified: branches/quickbook-1.5-spirit2/detail/actions_class.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/detail/actions_class.hpp (original)
+++ branches/quickbook-1.5-spirit2/detail/actions_class.hpp 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -90,9 +90,6 @@
         bool template_escape;
         template_stack templates;
         int error_count;
- std::string image_fileref;
- std::string attribute_name;
- attribute_map attributes;
 
     // push/pop the states and the streams
         void push();
@@ -118,7 +115,6 @@
         phrase_action warning, caution, important, note, tip;
         plain_char_action plain_char;
         raw_char_action raw_char;
- attribute_action attribute;
         image_action image;
         cond_phrase_action_pre cond_phrase_pre;
         cond_phrase_action_post cond_phrase_post;

Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -14,6 +14,7 @@
 #include "./detail/quickbook.hpp"
 #include "./detail/utils.hpp"
 #include "./parse_utils.hpp"
+#include <map>
 #include <boost/spirit/include/qi_core.hpp>
 #include <boost/spirit/include/qi_auxiliary.hpp>
 #include <boost/spirit/repository/include/qi_confix.hpp>
@@ -22,7 +23,8 @@
 #include <boost/spirit/include/phoenix_container.hpp>
 #include <boost/spirit/include/phoenix_fusion.hpp>
 #include <boost/spirit/include/phoenix_bind.hpp>
-#include <boost/fusion/include/make_fused.hpp>
+#include <boost/spirit/include/phoenix_function.hpp>
+#include <boost/fusion/include/std_pair.hpp>
 
 namespace quickbook
 {
@@ -72,7 +74,7 @@
         bool& no_eols;
 
         qi::rule<Iterator>
- space, blank, comment, phrase, phrase_markup, image,
+ space, blank, comment, phrase, phrase_markup,
                         phrase_end, bold, italic, underline, teletype,
                         strikethrough, escape, url, common, funcref, classref,
                         memberref, enumref, macroref, headerref, conceptref, globalref,
@@ -84,8 +86,13 @@
                         brackets_1_4, template_inner_arg_1_5, brackets_1_5
                         ;
 
- qi::rule<Iterator, std::string()> image_filename, template_arg_1_4, template_arg_1_5;
+ qi::rule<Iterator, std::string()> template_arg_1_4, template_arg_1_5;
         qi::rule<Iterator, std::vector<std::string>() > template_args;
+
+ qi::rule<Iterator> image, image_1_4, image_1_5;
+ qi::rule<Iterator, std::string()> image_filename, image_attribute_key, image_attribute_value;
+ qi::rule<Iterator, std::multimap<std::string, std::string>()> image_attributes;
+ qi::rule<Iterator, std::pair<std::string, std::string>()> image_attribute;
     };
 
     template <typename Iterator, typename Actions>
@@ -294,35 +301,46 @@
             ;
 
         image =
- '$' >> blank [ph::clear(ph::ref(actions.attributes))]
- >> (
- qi::eps(qbk_since(105u)) >> (
- image_filename [ph::ref(actions.image_fileref) = qi::_1]
- >> hard_space
- >> *(
- '['
- >> qi::raw[*(qi::alnum | '_')]
- [ph::ref(actions.attribute_name) = as_string(qi::_1)]
- >> space
- >> qi::raw[*(qi::char_ - (phrase_end | '['))]
- [actions.attribute]
- >> ']'
- >> space
- )
- ) |
- qi::eps(qbk_before(105u)) >> (
- (*(qi::char_ -
- phrase_end)) [ph::ref(actions.image_fileref) = as_string(qi::_1)]
- )
- )
- >> &qi::lit(']') [actions.image]
+ (qi::eps(qbk_since(105u)) >> image_1_5) |
+ (qi::eps(qbk_before(105u)) >> image_1_4);
+
+ image_1_4 = (
+ qi::raw['$']
+ >> blank
+ >> *(qi::char_ - phrase_end)
+ >> &qi::lit(']')
+ ) [ph::bind(actions.image, ph::begin(qi::_1), as_string(qi::_2))]
+ ;
+
+ image_1_5 = (
+ qi::raw['$']
+ >> blank
+ >> image_filename
+ >> hard_space
+ >> image_attributes
+ >> &qi::lit(']')
+ ) [ph::bind(actions.image, ph::begin(qi::_1), qi::_2, qi::_3)]
             ;
 
         image_filename = qi::raw[
- +(
- *qi::space
- >> +(qi::char_ - (qi::space | phrase_end | '['))
- )];
+ +(qi::char_ - (qi::space | phrase_end | '['))
+ >> *(
+ +qi::space
+ >> +(qi::char_ - (qi::space | phrase_end | '['))
+ )];
+
+ image_attributes = *(image_attribute >> space);
+
+ image_attribute =
+ '['
+ >> image_attribute_key
+ >> space
+ >> image_attribute_value
+ >> ']'
+ ;
+
+ image_attribute_key = *(qi::alnum | '_');
+ image_attribute_value = *(qi::char_ - (phrase_end | '['));
 
         url =
                 '@'

Modified: branches/quickbook-1.5-spirit2/test/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/test/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/test/Jamfile.v2 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -41,6 +41,7 @@
     [ quickbook-fail-test fail-parse-error1 ]
     [ quickbook-fail-test fail-parse-error2 ]
     [ quickbook-fail-test fail-template-lookup1 ]
+ [ quickbook-fail-test fail-image_1_5 ]
     ;
 
 

Added: branches/quickbook-1.5-spirit2/test/fail-image_1_5.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-1.5-spirit2/test/fail-image_1_5.quickbook 2009-11-29 17:52:25 EST (Sun, 29 Nov 2009)
@@ -0,0 +1,5 @@
+[article Images 1.5
+ [quickbook 1.5]
+]
+
+[$test.gif [width 10cm] [height 10cm] [width 10cm]]


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