|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r86640 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2013-11-12 04:14:08
Author: danieljames
Date: 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013)
New Revision: 86640
URL: http://svn.boost.org/trac/boost/changeset/86640
Log:
Store source mode as tag rather than string.
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 19 ++++++++++---------
trunk/tools/quickbook/src/actions.hpp | 2 +-
trunk/tools/quickbook/src/doc_info_grammar.cpp | 11 +++--------
trunk/tools/quickbook/src/document_state_impl.hpp | 1 +
trunk/tools/quickbook/src/fwd.hpp | 1 +
trunk/tools/quickbook/src/grammar_impl.hpp | 3 +++
trunk/tools/quickbook/src/main_grammar.cpp | 16 ++++++++--------
trunk/tools/quickbook/src/phrase_element_grammar.cpp | 17 ++++++++---------
trunk/tools/quickbook/src/state.cpp | 4 +++-
trunk/tools/quickbook/src/state.hpp | 5 +++--
trunk/tools/quickbook/src/state_save.hpp | 2 +-
trunk/tools/quickbook/src/syntax_highlight.cpp | 38 ++++++++++++++++++++------------------
12 files changed, 62 insertions(+), 57 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -41,12 +41,12 @@
{
// TODO: This works but is a bit of an odd place to put it.
// Might need to redefine the purpose of this function.
- if (!state.source_mode_next.empty()) {
- detail::outwarn(state.source_mode_next.get_file(),
- state.source_mode_next.get_position())
+ if (state.source_mode_next) {
+ detail::outwarn(state.source_mode_next_pos.get_file(),
+ state.source_mode_next_pos.get_position())
<< "Temporary source mode unsupported here."
<< std::endl;
- state.source_mode_next = value();
+ state.source_mode_next = 0;
}
for(quickbook::state::string_list::iterator
@@ -703,13 +703,14 @@
void source_mode_action(quickbook::state& state, value source_mode)
{
- state.source_mode = source_mode_tags::name(source_mode.get_tag());
+ state.source_mode = source_mode.get_tag();
}
void next_source_mode_action(quickbook::state& state, value source_mode)
{
value_consumer values = source_mode;
- state.source_mode_next = values.consume();
+ state.source_mode_next_pos = values.consume();
+ state.source_mode_next = values.consume().get_int();
values.finish();
}
@@ -725,9 +726,9 @@
(code_tag == code_tags::inline_code_block && qbk_version_n < 106u);
bool block = code_tag != code_tags::inline_code;
- std::string source_mode = state.source_mode_next.empty() ?
- state.source_mode : detail::to_s(state.source_mode_next.get_quickbook());
- state.source_mode_next = value();
+ source_mode_type source_mode = state.source_mode_next ?
+ state.source_mode_next : state.source_mode;
+ state.source_mode_next = 0;
if (inline_code) {
write_anchors(state, state.phrase);
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/actions.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -49,7 +49,7 @@
void syntax_highlight(
parse_iterator first, parse_iterator last,
quickbook::state& state,
- std::string const& source_mode,
+ source_mode_type source_mode,
bool is_block);
struct xinclude_path {
Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -11,7 +11,6 @@
#include <map>
#include <boost/foreach.hpp>
#include <boost/spirit/include/classic_core.hpp>
-#include <boost/spirit/include/classic_actor.hpp>
#include <boost/spirit/include/classic_loops.hpp>
#include <boost/spirit/include/classic_symbols.hpp>
#include <boost/spirit/include/classic_chset.hpp>
@@ -149,7 +148,7 @@
]
>> space
>> !(qbk_ver(106u) >> cl::eps_p(ph::var(local.source_mode_unset))
- [cl::assign_a(state.source_mode, "c++")]
+ [ph::var(state.source_mode) = source_mode_tags::cpp]
)
>> ( *( ( local.doc_info_attribute
| local.doc_info_escaped_attributes
@@ -222,12 +221,8 @@
local.attribute_rules[doc_attributes::compatibility_mode] = &local.doc_compatibility_mode;
- local.doc_source_mode =
- (
- cl::str_p("c++")
- | "python"
- | "teletype"
- ) [cl::assign_a(state.source_mode)]
+ local.doc_source_mode = source_modes
+ [ph::var(state.source_mode) = ph::arg1]
[ph::var(local.source_mode_unset) = false]
;
Modified: trunk/tools/quickbook/src/document_state_impl.hpp
==============================================================================
--- trunk/tools/quickbook/src/document_state_impl.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/document_state_impl.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -10,6 +10,7 @@
#define BOOST_QUICKBOOK_DOCUMENT_STATE_IMPL_HPP
#include "document_state.hpp"
+#include "phrase_tags.hpp"
#include "utils.hpp"
#include <boost/utility/string_ref.hpp>
#include <boost/shared_ptr.hpp>
Modified: trunk/tools/quickbook/src/fwd.hpp
==============================================================================
--- trunk/tools/quickbook/src/fwd.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/fwd.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -25,6 +25,7 @@
struct file;
struct template_symbol;
typedef boost::intrusive_ptr<file> file_ptr;
+ typedef unsigned source_mode_type;
typedef boost::string_ref::const_iterator string_iterator;
typedef lookback_iterator<string_iterator> parse_iterator;
Modified: trunk/tools/quickbook/src/grammar_impl.hpp
==============================================================================
--- trunk/tools/quickbook/src/grammar_impl.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/grammar_impl.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -146,6 +146,9 @@
// Element Symbols
cl::symbols<element_info> elements;
+
+ // Source mode
+ cl::symbols<source_mode_type> source_modes;
// Doc Info
cl::rule<scanner> doc_info_details;
Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -152,7 +152,7 @@
struct process_element_impl : scoped_action_base {
process_element_impl(main_grammar_local& l)
- : l(l), element_context_error_(false) {}
+ : l(l), saved_source_mode_(0), element_context_error_(false) {}
bool start()
{
@@ -182,12 +182,12 @@
assert(l.state_.values.builder.empty());
- if (!l.state_.source_mode_next.empty() &&
+ if (l.state_.source_mode_next &&
info_.type != element_info::maybe_block)
{
- l.state_.source_mode.swap(saved_source_mode_);
- l.state_.source_mode = detail::to_s(l.state_.source_mode_next.get_quickbook());
- l.state_.source_mode_next = value();
+ boost::swap(l.state_.source_mode, saved_source_mode_);
+ l.state_.source_mode = l.state_.source_mode_next;
+ l.state_.source_mode_next = 0;
}
return true;
@@ -223,13 +223,13 @@
void failure() { l.element_type = element_info::nothing; }
void cleanup() {
- if (!saved_source_mode_.empty())
- l.state_.source_mode.swap(saved_source_mode_);
+ if (saved_source_mode_)
+ boost::swap(l.state_.source_mode, saved_source_mode_);
}
main_grammar_local& l;
element_info info_;
- std::string saved_source_mode_;
+ source_mode_type saved_source_mode_;
bool element_context_error_;
};
Modified: trunk/tools/quickbook/src/phrase_element_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/phrase_element_grammar.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/phrase_element_grammar.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -19,6 +19,7 @@
#include <boost/spirit/include/classic_if.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
#include <boost/spirit/include/phoenix1_casts.hpp>
+#include <boost/foreach.hpp>
namespace quickbook
{
@@ -171,16 +172,14 @@
;
local.source_mode =
- ( cl::str_p("c++")
- | "python"
- | "teletype"
- ) [state.values.entry(ph::arg1, ph::arg2)];
+ cl::eps_p [state.values.entry(ph::arg1, ph::arg2)]
+ >> source_modes [state.values.entry(ph::arg1)];
- elements.add
- ("c++", element_info(element_info::phrase, &local.empty, source_mode_tags::cpp))
- ("python", element_info(element_info::phrase, &local.empty, source_mode_tags::python))
- ("teletype", element_info(element_info::phrase, &local.empty, source_mode_tags::teletype))
- ;
+ BOOST_FOREACH(int tag, source_mode_tags::tags()) {
+ source_modes.add(source_mode_tags::name(tag), tag);
+ elements.add(source_mode_tags::name(tag),
+ element_info(element_info::phrase, &local.empty, tag));
+ }
elements.add
("role", element_info(element_info::phrase, &local.role, phrase_tags::role, 106u))
Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/state.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -14,6 +14,7 @@
#include "grammar.hpp"
#include "input_path.hpp"
#include "utils.hpp"
+#include "phrase_tags.hpp"
#if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
#pragma warning(disable:4355)
@@ -45,8 +46,9 @@
, imported(false)
, macro()
- , source_mode("c++")
+ , source_mode(source_mode_tags::cpp)
, source_mode_next()
+ , source_mode_next_pos()
, current_file(0)
, filename_relative(filein_.filename())
Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/state.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -57,8 +57,9 @@
// state saved for files and templates.
bool imported;
string_symbols macro;
- std::string source_mode;
- value source_mode_next;
+ source_mode_type source_mode;
+ source_mode_type source_mode_next;
+ value source_mode_next_pos;
file_ptr current_file;
fs::path filename_relative; // for the __FILENAME__ macro.
// (relative to the original file
Modified: trunk/tools/quickbook/src/state_save.hpp
==============================================================================
--- trunk/tools/quickbook/src/state_save.hpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/state_save.hpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -40,7 +40,7 @@
file_ptr current_file;
fs::path filename_relative;
fs::path xinclude_base;
- std::string source_mode;
+ source_mode_type source_mode;
string_symbols macro;
int template_depth;
int min_section_level;
Modified: trunk/tools/quickbook/src/syntax_highlight.cpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.cpp Tue Nov 12 04:13:35 2013 (r86639)
+++ trunk/tools/quickbook/src/syntax_highlight.cpp 2013-11-12 04:14:07 EST (Tue, 12 Nov 2013) (r86640)
@@ -18,6 +18,7 @@
#include "utils.hpp"
#include "files.hpp"
#include "input_path.hpp"
+#include "phrase_tags.hpp"
namespace quickbook
{
@@ -564,30 +565,31 @@
parse_iterator first,
parse_iterator last,
quickbook::state& state,
- std::string const& source_mode,
+ source_mode_type source_mode,
bool is_block)
{
syntax_highlight_actions syn_actions(state, is_block);
// print the code with syntax coloring
- if (source_mode == "c++")
+ switch(source_mode)
{
- cpp_highlight cpp_p(syn_actions);
- boost::spirit::classic::parse(first, last, cpp_p);
- }
- else if (source_mode == "python")
- {
- python_highlight python_p(syn_actions);
- boost::spirit::classic::parse(first, last, python_p);
- }
- else if (source_mode == "teletype")
- {
- teletype_highlight teletype_p(syn_actions);
- boost::spirit::classic::parse(first, last, teletype_p);
- }
- else
- {
- BOOST_ASSERT(0);
+ case source_mode_tags::cpp: {
+ cpp_highlight cpp_p(syn_actions);
+ boost::spirit::classic::parse(first, last, cpp_p);
+ break;
+ }
+ case source_mode_tags::python: {
+ python_highlight python_p(syn_actions);
+ boost::spirit::classic::parse(first, last, python_p);
+ break;
+ }
+ case source_mode_tags::teletype: {
+ teletype_highlight teletype_p(syn_actions);
+ boost::spirit::classic::parse(first, last, teletype_p);
+ break;
+ }
+ default:
+ BOOST_ASSERT(0);
}
}
}
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