|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70204 - in trunk/tools/quickbook: . src test test/unit
From: dnljms_at_[hidden]
Date: 2011-03-19 15:13:39
Author: danieljames
Date: 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
New Revision: 70204
URL: http://svn.boost.org/trac/boost/changeset/70204
Log:
Quickbook: support escapes in simple markup.
Added:
trunk/tools/quickbook/test/unit/post_process_test.cpp
- copied unchanged from r69318, /branches/quickbook-filenames/tools/quickbook/test/unit/post_process_test.cpp
Properties modified:
trunk/tools/quickbook/ (props changed)
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 13 ++++-----
trunk/tools/quickbook/src/actions.hpp | 2
trunk/tools/quickbook/src/main_grammar.cpp | 53 +++++++++++++++++++++++++++------------
trunk/tools/quickbook/src/post_process.cpp | 44 +++++++++-----------------------
trunk/tools/quickbook/src/post_process.hpp | 16 ++++++++---
trunk/tools/quickbook/src/quickbook.cpp | 14 +++++++++
trunk/tools/quickbook/test/simple_markup.gold | 15 +++++++++++
trunk/tools/quickbook/test/simple_markup.quickbook | 12 +++++++++
trunk/tools/quickbook/test/unit/Jamfile.v2 | 1
9 files changed, 109 insertions(+), 61 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -308,11 +308,10 @@
content.get_boostbook(), anchor + "-heading", linkend);
}
- void simple_phrase_action::operator()(iterator first, iterator last) const
+ void simple_phrase_action::operator()(char mark) const
{
if(!actions.output_pre(out)) return;
- char mark = *first;
int tag =
mark == '*' ? phrase_tags::bold :
mark == '/' ? phrase_tags::italic :
@@ -323,18 +322,18 @@
assert(tag != 0);
detail::markup markup = detail::markups[tag];
- std::string str(
- boost::next(first.base()),
- boost::prior(last.base()));
+ value_consumer values = actions.values.get();
+ value content = values.consume();
+ values.finish();
out << markup.pre;
- if (std::string const* ptr = find(macro, str.c_str()))
+ if (std::string const* ptr = find(macro, content.get_quickbook().c_str()))
{
out << *ptr;
}
else
{
- detail::print_string(str, out.get());
+ out << content.get_boostbook();
}
out << markup.post;
}
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -142,7 +142,7 @@
, macro(macro)
, actions(actions) {}
- void operator()(iterator first, iterator last) const;
+ void operator()(char) const;
collector& out;
string_symbols const& macro;
Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp (original)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -101,7 +101,7 @@
top_level, blocks, paragraph_separator,
code, code_line, blank_line, hr,
list, list_item, element,
- escape,
+ nested_char, escape,
inline_code,
template_,
code_block, macro,
@@ -122,7 +122,8 @@
};
cl::rule<scanner, simple_markup_closure::context_t>
- simple_markup, simple_markup_end;
+ simple_markup;
+ cl::rule<scanner> simple_markup_end;
element_info::type_enum element_type;
cl::rule<scanner> element_rule;
@@ -381,7 +382,8 @@
;
local.simple_markup =
- ( cl::chset<>("*/_=") [local.simple_markup.mark = ph::arg1]
+ cl::chset<>("*/_=") [local.simple_markup.mark = ph::arg1]
+ >> cl::eps_p(cl::graph_p) // graph_p must follow first mark
>> lookback
[ cl::anychar_p
>> ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
@@ -392,17 +394,24 @@
// by space or punctuation or the
// mark character or a the start.
]
- >> cl::graph_p // graph_p must follow first mark
- >> *(cl::anychar_p - local.simple_markup_end(local.simple_markup.mark))
- >> cl::f_ch_p(local.simple_markup.mark)
- ) [actions.simple_markup]
+ >> actions.values.save()
+ [
+ actions.scoped_output()
+ [
+ (*( ~cl::eps_p(local.simple_markup_end)
+ >> local.nested_char
+ )) [actions.docinfo_value(ph::arg1, ph::arg2)]
+ ]
+ >> cl::f_ch_p(local.simple_markup.mark)
+ [actions.simple_markup]
+ ]
;
local.simple_markup_end
= ( lookback[cl::graph_p] // final mark must be preceeded by
// graph_p
- >> cl::f_ch_p(local.simple_markup_end.mark)
- >> ~cl::eps_p(cl::f_ch_p(local.simple_markup_end.mark))
+ >> cl::f_ch_p(local.simple_markup.mark)
+ >> ~cl::eps_p(cl::f_ch_p(local.simple_markup.mark))
// final mark not be followed by
// the same character.
>> (cl::space_p | cl::punct_p | cl::end_p)
@@ -452,6 +461,19 @@
]
;
+ local.nested_char =
+ cl::str_p("\\n") [actions.break_]
+ | "\\ " // ignore an escaped space
+ | '\\' >> cl::punct_p [actions.raw_char]
+ | "\\u" >> cl::repeat_p(4)
+ [cl::chset<>("0-9a-fA-F")]
+ [actions.escape_unicode]
+ | "\\U" >> cl::repeat_p(8)
+ [cl::chset<>("0-9a-fA-F")]
+ [actions.escape_unicode]
+ | cl::anychar_p [actions.plain_char]
+ ;
+
local.escape =
cl::str_p("\\n") [actions.break_]
| cl::str_p("\\ ") // ignore an escaped space
@@ -540,13 +562,12 @@
;
phrase_end =
- ']' |
- cl::if_p(var(actions.no_eols))
- [
- cl::eol_p >> *cl::blank_p >> cl::eol_p
- // Make sure that we don't go
- ] // past a single block, except
- ; // when preformatted.
+ ']'
+ | cl::eps_p(var(actions.no_eols))
+ >> cl::eol_p >> *cl::blank_p >> cl::eol_p
+ ; // Make sure that we don't go
+ // past a single block, except
+ // when preformatted.
comment =
"[/" >> *(local.dummy_block | (cl::anychar_p - ']')) >> ']'
Modified: trunk/tools/quickbook/src/post_process.cpp
==============================================================================
--- trunk/tools/quickbook/src/post_process.cpp (original)
+++ trunk/tools/quickbook/src/post_process.cpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -7,7 +7,6 @@
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include "post_process.hpp"
-#include "input_path.hpp"
#include <boost/spirit/include/classic_core.hpp>
#include <boost/bind.hpp>
#include <set>
@@ -403,6 +402,9 @@
void do_end_tag(iter_type f, iter_type l) const
{
+ if (state.tags.empty())
+ throw quickbook::post_process_failure("Mismatched tags.");
+
bool is_flow_tag = state.is_flow_tag(state.tags.top());
if (!is_flow_tag)
{
@@ -419,9 +421,8 @@
int indent;
};
- int post_process(
+ std::string post_process(
std::string const& in
- , std::ostream& out
, int indent
, int linewidth)
{
@@ -430,36 +431,17 @@
if (linewidth == -1)
linewidth = 80; // set default to 80
- try
+ std::string tidy;
+ tidy_compiler state(tidy, linewidth);
+ tidy_grammar g(state, indent);
+ cl::parse_info<iter_type> r = parse(in.begin(), in.end(), g, cl::space_p);
+ if (r.full)
{
- std::string tidy;
- tidy_compiler state(tidy, linewidth);
- tidy_grammar g(state, indent);
- cl::parse_info<iter_type> r = parse(in.begin(), in.end(), g, cl::space_p);
- if (r.full)
- {
- out << tidy;
- return 0;
- }
- else
- {
- // fallback!
- ::quickbook::detail::outerr()
- << "Warning: Post Processing Failed."
- << std::endl;
- out << in;
- return 1;
- }
+ return tidy;
}
-
- catch(...)
- {
- // fallback!
- ::quickbook::detail::outerr()
- << "Post Processing Failed."
- << std::endl;
- out << in;
- return 1;
+ else
+ {
+ throw quickbook::post_process_failure("Post Processing Failed.");
}
}
}
Modified: trunk/tools/quickbook/src/post_process.hpp
==============================================================================
--- trunk/tools/quickbook/src/post_process.hpp (original)
+++ trunk/tools/quickbook/src/post_process.hpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -9,16 +9,22 @@
#if !defined(BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP)
#define BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP
-#include <iostream>
#include <string>
+#include <stdexcept>
namespace quickbook
{
- int post_process(
+ std::string post_process(
std::string const& in
- , std::ostream& out
- , int indent
- , int linewidth);
+ , int indent = -1
+ , int linewidth = -1);
+
+ class post_process_failure : std::runtime_error
+ {
+ public:
+ post_process_failure(std::string const& error)
+ : std::runtime_error(error) {}
+ };
}
#endif // BOOST_SPIRIT_QUICKBOOK_POST_PROCESS_HPP
Modified: trunk/tools/quickbook/src/quickbook.cpp
==============================================================================
--- trunk/tools/quickbook/src/quickbook.cpp (original)
+++ trunk/tools/quickbook/src/quickbook.cpp 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -150,7 +150,19 @@
if (pretty_print)
{
- result = post_process(buffer.str(), fileout, indent, linewidth);
+ try
+ {
+ fileout << post_process(buffer.str(), indent, linewidth);
+ }
+ catch (quickbook::post_process_failure&)
+ {
+ // fallback!
+ ::quickbook::detail::outerr()
+ << "Post Processing Failed."
+ << std::endl;
+ fileout << buffer.str();
+ return 1;
+ }
}
else
{
Modified: trunk/tools/quickbook/test/simple_markup.gold
==============================================================================
--- trunk/tools/quickbook/test/simple_markup.gold (original)
+++ trunk/tools/quickbook/test/simple_markup.gold 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -31,5 +31,20 @@
<para>
_Should not underline escaped markup_. _or this escaped_ markup form.
</para>
+ <para>
+ <literal>Matti Meikäläinen</literal>
+ </para>
+ <para>
+ <literal>replaced</literal>
+ </para>
+ <para>
+ <emphasis role="underline">replaced</emphasis>
+ </para>
+ <para>
+ <literal>_macro_</literal>
+ </para>
+ <para>
+ /not italic/
+ </para>
</section>
</article>
Modified: trunk/tools/quickbook/test/simple_markup.quickbook
==============================================================================
--- trunk/tools/quickbook/test/simple_markup.quickbook (original)
+++ trunk/tools/quickbook/test/simple_markup.quickbook 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -2,6 +2,8 @@
[quickbook 1.5]
]
+[def _macro_ replaced]
+
[section Simple Markup]
/italic/ *bold* _underline_ =teletype=
@@ -21,4 +23,14 @@
_Should not underline '''escaped''' markup_.
_or this '''escaped_ markup''' form.
+=Matti Meik\u00E4l\u00E4inen=
+
+=_macro_=
+
+__macro__
+
+=_mac\ ro_=
+
+/not italic\/
+
[endsect]
\ No newline at end of file
Modified: trunk/tools/quickbook/test/unit/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/unit/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/unit/Jamfile.v2 2011-03-19 15:13:38 EDT (Sat, 19 Mar 2011)
@@ -5,3 +5,4 @@
;
run values_test.cpp ../../src/values.cpp ;
+run post_process_test.cpp ../../src/post_process.cpp ;
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