|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60981 - trunk/tools/quickbook/detail
From: daniel_james_at_[hidden]
Date: 2010-03-31 17:40:46
Author: danieljames
Date: 2010-03-31 17:40:45 EDT (Wed, 31 Mar 2010)
New Revision: 60981
URL: http://svn.boost.org/trac/boost/changeset/60981
Log:
Command line macros. Needs error checking.
Text files modified:
trunk/tools/quickbook/detail/actions.hpp | 1
trunk/tools/quickbook/detail/quickbook.cpp | 83 +++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 1 deletions(-)
Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2010-03-31 17:40:45 EDT (Wed, 31 Mar 2010)
@@ -43,6 +43,7 @@
extern tm* current_gm_time; // the current UTC time
extern bool debug_mode;
extern std::vector<std::string> include_path;
+ extern std::vector<std::string> preset_defines;
// forward declarations
struct actions;
Modified: trunk/tools/quickbook/detail/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/detail/quickbook.cpp (original)
+++ trunk/tools/quickbook/detail/quickbook.cpp 2010-03-31 17:40:45 EDT (Wed, 31 Mar 2010)
@@ -43,6 +43,79 @@
unsigned qbk_version_n = 0; // qbk_major_version * 100 + qbk_minor_version
bool ms_errors = false; // output errors/warnings as if for VS
std::vector<std::string> include_path;
+ std::vector<std::string> preset_defines;
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Parse the macros passed as command line parameters
+ //
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Actions>
+ struct command_line_grammar
+ : public grammar<command_line_grammar<Actions> >
+ {
+ command_line_grammar(Actions& actions)
+ : actions(actions) {}
+
+ template <typename Scanner>
+ struct definition
+ {
+ definition(command_line_grammar const& self)
+ : unused(false), common(self.actions, unused)
+ {
+ Actions& actions = self.actions;
+
+ macro =
+ *space_p
+ >> macro_identifier [actions.macro_identifier]
+ >> *space_p
+ >> ( '='
+ >> *space_p
+ >> phrase [actions.macro_definition]
+ >> *space_p
+ )
+ | eps_p [actions.macro_definition]
+ ;
+
+ macro_identifier =
+ +(anychar_p - (space_p | ']'))
+ ;
+
+ phrase =
+ *( common
+ | (anychar_p - ']') [actions.plain_char]
+ )
+ ;
+ }
+
+ bool unused;
+ rule<Scanner> macro, macro_identifier, phrase;
+ phrase_grammar<Actions> common;
+
+ rule<Scanner> const&
+ start() const { return macro; }
+ };
+
+ Actions& actions;
+ };
+
+ static void set_macros(actions& actor)
+ {
+ quickbook::command_line_grammar<actions> grammar(actor);
+
+ for(std::vector<std::string>::const_iterator
+ it = preset_defines.begin(),
+ end = preset_defines.end();
+ it != end; ++it)
+ {
+ typedef position_iterator<std::string::const_iterator> iterator_type;
+ iterator_type first(it->begin(), it->end(), "command line parameter");
+ iterator_type last(it->end(), it->end());
+
+ parse(first, last, grammar);
+ // TODO: Check result?
+ }
+ }
///////////////////////////////////////////////////////////////////////////
//
@@ -103,6 +176,7 @@
parse(char const* filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false)
{
actions actor(filein_, outdir, out);
+ set_macros(actor);
bool r = parse(filein_, actor);
if (actor.section_level != 0)
detail::outwarn(filein_)
@@ -177,6 +251,7 @@
("debug", "debug mode (for developers)")
("ms-errors", "use Microsoft Visual Studio style error & warn message format")
("include-path,I", value< std::vector<quickbook::detail::input_path> >(), "include path")
+ ("define,D", value< std::vector<std::string> >(), "define macro")
;
positional_options_description p;
@@ -247,6 +322,12 @@
= std::vector<std::string>(paths.begin(), paths.end());
}
+ if (vm.count("define"))
+ {
+ quickbook::preset_defines
+ = vm["define"].as<std::vector<std::string> >();
+ }
+
if (vm.count("input-file"))
{
std::string filein
@@ -274,7 +355,7 @@
quickbook::detail::outerr("") << "Error: No filename given\n\n"
<< desc << std::endl;
return 1;
- }
+ }
}
catch(std::exception& e)
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