|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59297 - in branches/quickbook-1.5-spirit2: . detail
From: daniel_james_at_[hidden]
Date: 2010-01-27 17:01:22
Author: danieljames
Date: 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
New Revision: 59297
URL: http://svn.boost.org/trac/boost/changeset/59297
Log:
Formatted text, conditional phrases, anchors, line breaks.
Text files modified:
branches/quickbook-1.5-spirit2/detail/actions.cpp | 43 ----------
branches/quickbook-1.5-spirit2/detail/actions.hpp | 62 ---------------
branches/quickbook-1.5-spirit2/detail/actions_class.cpp | 21 -----
branches/quickbook-1.5-spirit2/detail/actions_class.hpp | 22 -----
branches/quickbook-1.5-spirit2/phrase.cpp | 157 ++++++++++++++++++++++-----------------
branches/quickbook-1.5-spirit2/phrase.hpp | 38 +++++++-
branches/quickbook-1.5-spirit2/phrase_actions.cpp | 27 ++++++
7 files changed, 148 insertions(+), 222 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 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -46,15 +46,6 @@
}
}
- // Handles line-breaks (DEPRECATED!!!)
- void break_action::operator()(iterator_range x, unused_type, unused_type) const
- {
- boost::spirit::classic::file_position const pos = x.begin().get_position();
- detail::outwarn(pos.file,pos.line) << "in column:" << pos.column << ", "
- << "[br] and \\n are deprecated" << ".\n";
- phrase << break_mark;
- }
-
void error_action::operator()(iterator_range x, unused_type, unused_type) const
{
boost::spirit::classic::file_position const pos = x.begin().get_position();
@@ -138,31 +129,6 @@
out << post;
}
- void cond_phrase_action_pre::operator()(iterator_range x, unused_type, unused_type) const
- {
- std::string str(x.begin(), x.end());
- conditions.push_back(macro.find(str.c_str()));
- out.push(); // save the stream
- }
-
- void cond_phrase_action_post::operator()(iterator_range x, unused_type, unused_type) const
- {
- bool symbol_found = conditions.back();
- conditions.pop_back();
-
- if (x.begin() == x.end() || !symbol_found)
- {
- out.pop(); // restore the stream
- }
- else
- {
- std::string save;
- out.swap(save);
- out.pop(); // restore the stream
- out << save; // print the body
- }
- }
-
void list_action::operator()(unused_type, unused_type, unused_type) const
{
BOOST_ASSERT(!list_marks.empty()); // there must be at least one item in the stack
@@ -281,15 +247,6 @@
out << "</phrase>";
}
- void anchor_action::operator()(iterator_range x, unused_type, unused_type) const
- {
- iterator first = x.begin(), last = x.end();
- out << "<anchor id=\"";
- while (first != last)
- detail::print_char(*first++, out.get());
- out << "\" />\n";
- }
-
void do_macro_action::operator()(std::string const& str, unused_type, unused_type) const
{
if (str == quickbook_get_date)
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 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -173,44 +173,6 @@
string_symbols const& macro;
};
- struct cond_phrase_action_pre
- {
- // Handles conditional phrases
-
- cond_phrase_action_pre(
- collector& out
- , std::vector<bool>& conditions
- , string_symbols const& macro)
- : out(out)
- , conditions(conditions)
- , macro(macro) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& out;
- std::vector<bool>& conditions;
- string_symbols const& macro;
- };
-
- struct cond_phrase_action_post
- {
- // Handles conditional phrases
-
- cond_phrase_action_post(
- collector& out
- , std::vector<bool>& conditions
- , string_symbols const& macro)
- : out(out)
- , conditions(conditions)
- , macro(macro) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& out;
- std::vector<bool>& conditions;
- string_symbols const& macro;
- };
-
struct list_action
{
// Handles lists
@@ -282,18 +244,6 @@
collector& out;
};
- struct anchor_action
- {
- // Handles anchors
-
- anchor_action(collector& out)
- : out(out) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& out;
- };
-
extern char const* quickbook_get_date;
extern char const* quickbook_get_time;
@@ -482,18 +432,6 @@
collector& temp_para;
};
- struct break_action
- {
- // Handles line-breaks (DEPRECATED!!!)
-
- break_action(collector& phrase)
- : phrase(phrase) {}
-
- void operator()(iterator_range, unused_type, unused_type) const;
-
- collector& phrase;
- };
-
struct macro_identifier_action
{
// Handles macro identifiers
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 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -94,30 +94,11 @@
, tip(out, temp_para, tip_pre, tip_post)
, plain_char(phrase)
, raw_char(phrase)
- , cond_phrase_pre(phrase, conditions, macro)
- , cond_phrase_post(phrase, conditions, macro)
, list(out, list_buffer, list_indent, list_marks)
, list_format(list_buffer, list_indent, list_marks, error_count)
, list_item(list_buffer, phrase, list_item_pre, list_item_post)
- , bold_pre(phrase, bold_pre_)
- , bold_post(phrase, bold_post_)
- , italic_pre(phrase, italic_pre_)
- , italic_post(phrase, italic_post_)
- , underline_pre(phrase, underline_pre_)
- , underline_post(phrase, underline_post_)
- , teletype_pre(phrase, teletype_pre_)
- , teletype_post(phrase, teletype_post_)
- , strikethrough_pre(phrase, strikethrough_pre_)
- , strikethrough_post(phrase, strikethrough_post_)
- , quote_pre(phrase, quote_pre_)
- , quote_post(phrase, quote_post_)
- , replaceable_pre(phrase, replaceable_pre_)
- , replaceable_post(phrase, replaceable_post_)
- , footnote_pre(phrase, footnote_pre_)
- , footnote_post(phrase, footnote_post_)
-
, simple_bold(phrase, bold_pre_, bold_post_, macro)
, simple_italic(phrase, italic_pre_, italic_post_, macro)
, simple_underline(phrase, underline_pre_, underline_post_, macro)
@@ -132,7 +113,6 @@
, start_varlistitem(phrase)
, end_varlistitem(phrase, temp_para)
- , break_(phrase)
, macro_identifier(*this)
, macro_definition(*this)
, do_macro(phrase)
@@ -147,7 +127,6 @@
, end_row(phrase, end_row_)
, start_cell(phrase, table_span)
, end_cell(phrase, temp_para)
- , anchor(out)
, begin_section(out, phrase, doc_id, section_id, section_level, qualified_section_id)
, end_section(out, section_level, qualified_section_id, error_count)
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 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -83,7 +83,6 @@
std::string macro_id;
std::stack<mark_type> list_marks;
int list_indent;
- std::vector<bool> conditions;
string_list template_info;
int template_depth;
bool template_escape;
@@ -117,30 +116,11 @@
phrase_action warning, caution, important, note, tip;
plain_char_action plain_char;
raw_char_action raw_char;
- cond_phrase_action_pre cond_phrase_pre;
- cond_phrase_action_post cond_phrase_post;
list_action list;
list_format_action list_format;
phrase_action list_item;
- markup_action bold_pre;
- markup_action bold_post;
- markup_action italic_pre;
- markup_action italic_post;
- markup_action underline_pre;
- markup_action underline_post;
- markup_action teletype_pre;
- markup_action teletype_post;
- markup_action strikethrough_pre;
- markup_action strikethrough_post;
- markup_action quote_pre;
- markup_action quote_post;
- markup_action replaceable_pre;
- markup_action replaceable_post;
- markup_action footnote_pre;
- markup_action footnote_post;
-
simple_phrase_action simple_bold;
simple_phrase_action simple_italic;
simple_phrase_action simple_underline;
@@ -155,7 +135,6 @@
start_varlistitem_action start_varlistitem;
end_varlistitem_action end_varlistitem;
- break_action break_;
macro_identifier_action macro_identifier;
macro_definition_action macro_definition;
do_macro_action do_macro;
@@ -170,7 +149,6 @@
markup_action end_row;
start_col_action start_cell;
end_col_action end_cell;
- anchor_action anchor;
begin_section_action begin_section;
end_section_action end_section;
Modified: branches/quickbook-1.5-spirit2/phrase.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.cpp 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -31,19 +31,44 @@
#include <boost/fusion/include/adapt_struct.hpp>
BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::anchor,
+ (std::string, id)
+ (char const*, dummy)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
quickbook::link,
- (quickbook::link_type, type)
+ (quickbook::markup, type)
(std::string, destination)
(std::string, content)
)
BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::formatted,
+ (quickbook::markup, type)
+ (std::string, content)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::break_,
+ (quickbook::file_position, position)
+ (char const*, dummy)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
quickbook::image,
(quickbook::file_position, position)
(std::string, image_filename)
(quickbook::image::attribute_map, attributes)
)
+BOOST_FUSION_ADAPT_STRUCT(
+ quickbook::cond_phrase,
+ (std::string, macro_id)
+ (std::string, content)
+)
+
namespace quickbook
{
namespace qi = boost::spirit::qi;
@@ -66,12 +91,12 @@
qi::rule<iterator>
space, blank, comment, phrase, phrase_markup,
- phrase_end, bold, italic, underline, teletype,
- strikethrough, escape, common,
- anchor, hard_space, eol, inline_code, simple_format,
+ phrase_end,
+ escape, common,
+ hard_space, eol, inline_code, simple_format,
template_,
- quote, code_block, footnote, replaceable, macro,
- dummy_block, cond_phrase, macro_identifier,
+ code_block, replaceable, macro,
+ dummy_block,
brackets_1_4, template_inner_arg_1_5, brackets_1_5
;
@@ -81,6 +106,11 @@
qi::rule<iterator, std::vector<std::string>() > template_args;
qi::rule<iterator, std::string()> phrase_attr;
+
+ qi::rule<iterator, quickbook::break_()> break_, escape_break;
+
+ qi::rule<iterator, std::string()> macro_identifier;
+ qi::rule<iterator, quickbook::cond_phrase()> cond_phrase;
qi::rule<iterator, quickbook::image()> image, image_1_4, image_1_5;
qi::rule<iterator, std::string()> image_filename, image_attribute_key, image_attribute_value;
@@ -88,8 +118,14 @@
qi::rule<iterator, std::pair<std::string, std::string>()> image_attribute;
qi::rule<iterator, boost::iterator_range<iterator>(char)> simple_markup;
- qi::symbols<char, link_type> link_symbol;
+
+ qi::rule<iterator, quickbook::anchor()> anchor;
+
+ qi::symbols<char, markup> link_symbol;
qi::rule<iterator, quickbook::link()> link, url;
+
+ qi::symbols<char, markup> format_symbol;
+ qi::rule<iterator, quickbook::formatted()> formatted, footnote;
qi::symbols<char, quickbook::source_mode> source_mode;
};
@@ -270,28 +306,28 @@
phrase_markup =
'['
- >> ( cond_phrase
+ >> ( cond_phrase [actions.process]
| image [actions.process]
| url [actions.process]
| link [actions.process]
- | anchor
+ | anchor [actions.process]
| source_mode [actions.process]
- | bold
- | italic
- | underline
- | teletype
- | strikethrough
- | quote
- | replaceable
- | footnote
+ | formatted [actions.process]
+ | footnote [actions.process]
| template_
- | qi::raw["br"] [actions.break_]
+ | break_ [actions.process]
)
>> ']'
;
+ break_ =
+ position
+ >> "br"
+ >> qi::attr("dummy")
+ ;
+
escape =
- qi::raw["\\n"] [actions.break_]
+ escape_break [actions.process]
| "\\ " // ignore an escaped char
| '\\' >> qi::punct [actions.raw_char]
| (
@@ -300,15 +336,22 @@
>> qi::lit("'''") [actions.escape_post]
)
;
+
+ escape_break =
+ position
+ >> "\\n"
+ >> qi::attr("dummy")
+ ;
macro_identifier =
+(qi::char_ - (qi::space | ']'))
;
cond_phrase =
- '?' >> blank
- >> qi::raw[macro_identifier] [actions.cond_phrase_pre]
- >> qi::raw[-phrase] [actions.cond_phrase_post]
+ '?'
+ >> blank
+ >> macro_identifier
+ >> -phrase_attr
;
image =
@@ -356,19 +399,20 @@
anchor =
'#'
>> blank
- >> qi::raw[*(qi::char_ - phrase_end)] [actions.anchor]
+ >> *(qi::char_ - phrase_end)
+ >> qi::attr("dummy")
;
link_symbol.add
- ("link", link_type(link_pre_, link_post_))
- ("funcref", link_type(funcref_pre_, funcref_post_))
- ("classref", link_type(classref_pre_, classref_post_))
- ("memberref", link_type(memberref_pre_, memberref_post_))
- ("enumref", link_type(enumref_pre_, enumref_post_))
- ("macroref", link_type(macroref_pre_, macroref_post_))
- ("headerref", link_type(headerref_pre_, headerref_post_))
- ("conceptref", link_type(conceptref_pre_, conceptref_post_))
- ("globalref", link_type(globalref_pre_, globalref_post_))
+ ("link", markup(link_pre_, link_post_))
+ ("funcref", markup(funcref_pre_, funcref_post_))
+ ("classref", markup(classref_pre_, classref_post_))
+ ("memberref", markup(memberref_pre_, memberref_post_))
+ ("enumref", markup(enumref_pre_, enumref_post_))
+ ("macroref", markup(macroref_pre_, macroref_post_))
+ ("headerref", markup(headerref_pre_, headerref_post_))
+ ("conceptref", markup(conceptref_pre_, conceptref_post_))
+ ("globalref", markup(globalref_pre_, globalref_post_))
;
link =
@@ -382,47 +426,24 @@
url =
'@'
- >> qi::attr(link_type(url_pre_, url_post_))
+ >> qi::attr(markup(url_pre_, url_post_))
>> *(qi::char_ - (']' | qi::space))
>> ( &qi::lit(']')
| (hard_space >> phrase_attr)
)
;
- bold =
- qi::char_('*') [actions.bold_pre]
- >> blank >> phrase [actions.bold_post]
- ;
-
- italic =
- qi::char_('\'') [actions.italic_pre]
- >> blank >> phrase [actions.italic_post]
+ format_symbol.add
+ ("*", markup(bold_pre_, bold_post_))
+ ("'", markup(italic_pre_, italic_post_))
+ ("_", markup(underline_pre_, underline_post_))
+ ("^", markup(teletype_pre_, teletype_post_))
+ ("-", markup(strikethrough_pre_, strikethrough_post_))
+ ("\"", markup(quote_pre_, quote_post_))
+ ("~", markup(replaceable_pre_, replaceable_post_))
;
- underline =
- qi::char_('_') [actions.underline_pre]
- >> blank >> phrase [actions.underline_post]
- ;
-
- teletype =
- qi::char_('^') [actions.teletype_pre]
- >> blank >> phrase [actions.teletype_post]
- ;
-
- strikethrough =
- qi::char_('-') [actions.strikethrough_pre]
- >> blank >> phrase [actions.strikethrough_post]
- ;
-
- quote =
- qi::char_('"') [actions.quote_pre]
- >> blank >> phrase [actions.quote_post]
- ;
-
- replaceable =
- qi::char_('~') [actions.replaceable_pre]
- >> blank >> phrase [actions.replaceable_post]
- ;
+ formatted = format_symbol >> blank >> phrase_attr;
source_mode.add
("c++", quickbook::source_mode("c++"))
@@ -431,8 +452,10 @@
;
footnote =
- qi::lit("footnote") [actions.footnote_pre]
- >> blank >> phrase [actions.footnote_post]
+ "footnote"
+ >> qi::attr(markup(footnote_pre_, footnote_post_))
+ >> blank
+ >> phrase_attr
;
position = qi::raw[qi::eps] [get_position];
Modified: branches/quickbook-1.5-spirit2/phrase.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.hpp (original)
+++ branches/quickbook-1.5-spirit2/phrase.hpp 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -27,22 +27,42 @@
std::string mode;
};
- struct link_type {
- link_type()
+ struct markup {
+ markup()
: pre(""), post("") {}
- link_type(char const* pre, char const* post)
+ markup(char const* pre, char const* post)
: pre(pre), post(post) {}
char const* pre;
char const* post;
};
+
+ struct anchor {
+ char const* dummy;
+ std::string id;
+ };
struct link {
- link_type type;
+ markup type;
std::string destination;
std::string content;
};
+ struct formatted {
+ markup type;
+ std::string content;
+ };
+
+ struct cond_phrase {
+ std::string macro_id;
+ std::string content;
+ };
+
+ struct break_ {
+ const char* dummy;
+ file_position position;
+ };
+
struct image {
typedef std::multimap<std::string, std::string> attribute_map;
@@ -51,9 +71,13 @@
attribute_map attributes;
};
- void process(quickbook::actions& actions, source_mode const& s);
- void process(quickbook::actions& actions, link const& x);
- void process(quickbook::actions& actions, image const& x);
+ void process(quickbook::actions&, source_mode const&);
+ void process(quickbook::actions&, anchor const&);
+ void process(quickbook::actions&, link const&);
+ void process(quickbook::actions&, formatted const&);
+ void process(quickbook::actions&, cond_phrase const&);
+ void process(quickbook::actions&, break_ const&);
+ void process(quickbook::actions&, image const&);
}
#endif // BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP
Modified: branches/quickbook-1.5-spirit2/phrase_actions.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase_actions.cpp (original)
+++ branches/quickbook-1.5-spirit2/phrase_actions.cpp 2010-01-27 17:01:21 EST (Wed, 27 Jan 2010)
@@ -10,6 +10,7 @@
#include "./phrase.hpp"
#include "./detail/actions_class.hpp"
+#include "./detail/markups.hpp"
namespace quickbook
{
@@ -17,6 +18,12 @@
actions.source_mode = s.mode;
}
+ void process(quickbook::actions& actions, anchor const& x) {
+ actions.phrase << "<anchor id=\"";
+ detail::print_string(x.id, actions.phrase.get());
+ actions.phrase << "\" />\n";
+ }
+
void process(quickbook::actions& actions, link const& x) {
actions.phrase << x.type.pre;
detail::print_string(x.destination, actions.phrase.get());
@@ -27,4 +34,24 @@
actions.phrase << x.content;
actions.phrase << x.type.post;
}
+
+ void process(quickbook::actions& actions, formatted const& x) {
+ actions.phrase << x.type.pre << x.content << x.type.post;
+ }
+
+ void process(quickbook::actions& actions, cond_phrase const& x) {
+ bool symbol_found = actions.macro.find(x.macro_id.c_str());
+
+ if (!x.content.empty() && symbol_found) {
+ actions.phrase << x.content; // print the body
+ }
+ }
+
+ void process(quickbook::actions& actions, break_ const& x) {
+ detail::outwarn(x.position.file,x.position.line)
+ << "in column:" << x.position.column << ", "
+ << "[br] and \\n are deprecated" << ".\n";
+ actions.phrase << break_mark;
+
+ }
}
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