Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68889 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-02-14 19:25:40


Author: danieljames
Date: 2011-02-14 19:25:38 EST (Mon, 14 Feb 2011)
New Revision: 68889
URL: http://svn.boost.org/trac/boost/changeset/68889

Log:
Better error message for incorrect doc info attributes.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 17 +++++++++++++++++
   branches/quickbook-filenames/tools/quickbook/src/actions.hpp | 20 ++++++++++++++++++++
   branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp | 28 ++++++++++++++++++++++++++--
   3 files changed, 63 insertions(+), 2 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-02-14 19:25:38 EST (Mon, 14 Feb 2011)
@@ -14,6 +14,8 @@
 #include <boost/filesystem/v3/convenience.hpp>
 #include <boost/filesystem/v3/fstream.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/range/distance.hpp>
+#include <boost/algorithm/string/replace.hpp>
 #include "quickbook.hpp"
 #include "actions.hpp"
 #include "utils.hpp"
@@ -73,6 +75,21 @@
         phrase << break_mark;
     }
 
+ void error_message_action::operator()(iterator first, iterator last) const
+ {
+ file_position const pos = first.get_position();
+
+ std::string value(first, last);
+ std::string formatted_message = message;
+ boost::replace_all(formatted_message, "%s", value);
+ boost::replace_all(formatted_message, "%c",
+ boost::lexical_cast<std::string>(pos.column));
+
+ detail::outerr(actions.filename, pos.line)
+ << formatted_message << std::endl;
+ ++actions.error_count;
+ }
+
     void error_action::operator()(iterator first, iterator /*last*/) const
     {
         file_position const pos = first.get_position();

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.hpp 2011-02-14 19:25:38 EST (Mon, 14 Feb 2011)
@@ -80,6 +80,21 @@
         void failure() {}
     };
 
+ struct error_message_action
+ {
+ // Prints an error message to std::cerr
+
+ error_message_action(quickbook::actions& actions, std::string const& m)
+ : actions(actions)
+ , message(m)
+ {}
+
+ void operator()(iterator, iterator) const;
+
+ quickbook::actions& actions;
+ std::string message;
+ };
+
     struct error_action
     {
         // Prints an error message to std::cerr
@@ -89,6 +104,11 @@
 
         void operator()(iterator first, iterator /*last*/) const;
 
+ error_message_action operator()(std::string const& message)
+ {
+ return error_message_action(actions, message);
+ }
+
         quickbook::actions& actions;
     };
 

Modified: branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/doc_info_grammar.cpp 2011-02-14 19:25:38 EST (Mon, 14 Feb 2011)
@@ -46,8 +46,21 @@
             doc_info_grammar_local& l;
         };
         
+ struct fallback_attribute_type
+ {
+ fallback_attribute_type(doc_info_grammar_local& l)
+ : l(l)
+ {}
+
+ void operator()(iterator, iterator) const {
+ l.attribute_rule = l.doc_fallback;
+ }
+
+ doc_info_grammar_local& l;
+ };
+
         cl::rule<scanner>
- doc_title, doc_simple, doc_phrase,
+ doc_title, doc_simple, doc_phrase, doc_fallback,
                         doc_copyright, doc_authors, doc_author,
                         doc_source_mode, doc_biblioid,
                         quickbook_version, char_;
@@ -56,9 +69,11 @@
         std::map<value::tag_type, cl::rule<scanner>* > attribute_rules;
         cl::rule<scanner> attribute_rule;
         assign_attribute_type assign_attribute;
+ fallback_attribute_type fallback_attribute;
         
         doc_info_grammar_local()
             : assign_attribute(*this)
+ , fallback_attribute(*this)
         {}
     };
 
@@ -96,9 +111,14 @@
>> *(
                     space
>> '['
- >> local.doc_attributes
+ >> space
+ >> ( local.doc_attributes
                                             [local.assign_attribute]
                                             [actions.values.tag]
+ | (+(cl::alnum_p | '_' | '-'))
+ [local.fallback_attribute]
+ [actions.error("Unrecognized document attribute: '%s'.")]
+ )
>> hard_space
>> local.attribute_rule
>> space
@@ -118,6 +138,10 @@
                 )
             ;
 
+ // TODO: Clear phrase afterwards?
+
+ local.doc_fallback = (*(~cl::eps_p(']') >> local.char_));
+
         // TODO: Restrictions on doc_id and doc_dirname?
 
         local.doc_simple = (*(~cl::eps_p(']') >> local.char_)) [actions.docinfo_value];


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