|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71144 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-04-09 07:29:23
Author: danieljames
Date: 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
New Revision: 71144
URL: http://svn.boost.org/trac/boost/changeset/71144
Log:
Quickbook: Nest escapes in syntax highlighted comments.
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 16 +++++++++++++++-
trunk/tools/quickbook/src/actions.hpp | 21 +++++++++++++++++++++
trunk/tools/quickbook/src/syntax_highlight.cpp | 40 ++++++++++++++++------------------------
trunk/tools/quickbook/test/code-block-cpp.gold | 10 +++++-----
trunk/tools/quickbook/test/code-block-python.gold | 4 ++--
5 files changed, 59 insertions(+), 32 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
@@ -522,12 +522,26 @@
}
// TODO: No need to check suppress since this is only used in the syntax
- // highlighter. I should moved this or something.
+ // highlighter. I should move this or something.
void span::operator()(iterator first, iterator last) const
{
+ if (name) out << "<phrase role=\"" << name << "\">";
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ if (name) out << "</phrase>";
+ }
+
+ void span_start::operator()(iterator first, iterator last) const
+ {
out << "<phrase role=\"" << name << "\">";
while (first != last)
detail::print_char(*first++, out.get());
+ }
+
+ void span_end::operator()(iterator first, iterator last) const
+ {
+ while (first != last)
+ detail::print_char(*first++, out.get());
out << "</phrase>";
}
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
@@ -162,6 +162,27 @@
collector& out;
};
+ struct span_start
+ {
+ span_start(char const* name, collector& out)
+ : name(name), out(out) {}
+
+ void operator()(iterator first, iterator last) const;
+
+ char const* name;
+ collector& out;
+ };
+
+ struct span_end
+ {
+ span_end(collector& out)
+ : out(out) {}
+
+ void operator()(iterator first, iterator last) const;
+
+ collector& out;
+ };
+
struct unexpected_char
{
// Handles unexpected chars in c++ syntax
Modified: trunk/tools/quickbook/src/syntax_highlight.cpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.cpp (original)
+++ trunk/tools/quickbook/src/syntax_highlight.cpp 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
@@ -91,29 +91,18 @@
;
comment
- = ( "//"
- >> *(cl::anychar_p - (cl::eol_p | "``"))
- ) [span("comment", self.out)]
+ = cl::str_p("//") [span_start("comment", self.out)]
>> *( escape
- | (
- +(cl::anychar_p - (cl::eol_p | "``"))
- ) [span("comment", self.out)]
- )
- | ( "/*"
- >> *(cl::anychar_p - (cl::str_p("*/") | "``"))
- >> ("*/" | cl::end_p)
- ) [span("comment", self.out)]
- | ( "/*"
- >> *(cl::anychar_p - "``")
- ) [span("comment", self.out)]
+ | (+(cl::anychar_p - (cl::eol_p | "``")))
+ [span(0, self.out)]
+ )
+ >> cl::eps_p [span_end(self.out)]
+ | cl::str_p("/*") [span_start("comment", self.out)]
>> *( escape
- | ( +(cl::anychar_p - (cl::str_p("*/") | "``"))
- >> cl::eps_p("``")
- ) [span("comment", self.out)]
- )
- >> !( +(cl::anychar_p - cl::str_p("*/"))
- >> !cl::str_p("*/")
- ) [span("comment", self.out)]
+ | (+(cl::anychar_p - (cl::str_p("*/") | "``")))
+ [span(0, self.out)]
+ )
+ >> (!cl::str_p("*/")) [span_end(self.out)]
;
keyword
@@ -250,9 +239,12 @@
;
comment
- = ( "#"
- >> *(cl::anychar_p - (cl::eol_p | "``"))
- ) [span("comment", self.out)]
+ = cl::str_p("#") [span_start("comment", self.out)]
+ >> *( escape
+ | (+(cl::anychar_p - (cl::eol_p | "``")))
+ [span(0, self.out)]
+ )
+ >> cl::eps_p [span_end(self.out)]
;
keyword
Modified: trunk/tools/quickbook/test/code-block-cpp.gold
==============================================================================
--- trunk/tools/quickbook/test/code-block-cpp.gold (original)
+++ trunk/tools/quickbook/test/code-block-cpp.gold 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
@@ -8,10 +8,10 @@
<phrase role="comment">/* No escape
* with newlines
*/</phrase>
-<phrase role="comment">// In Header: <</phrase><ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink><phrase role="comment">></phrase>
-<phrase role="comment">/* In Header: <</phrase><ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink><phrase role="comment">> */</phrase>
-<phrase role="comment">/* Multiple escapes: </phrase><emphasis>italic</emphasis><phrase role="comment">
- * </phrase><emphasis role="underline">underline</emphasis><emphasis role="bold">bold</emphasis><phrase role="comment">
+<phrase role="comment">// In Header: <<ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink>></phrase>
+<phrase role="comment">/* In Header: <<ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink>> */</phrase>
+<phrase role="comment">/* Multiple escapes: <emphasis>italic</emphasis>
+ * <emphasis role="underline">underline</emphasis><emphasis role="bold">bold</emphasis>
*/</phrase>
</programlisting>
<para>
@@ -24,6 +24,6 @@
A badly formed comment with an escape:
</para>
-<programlisting><phrase role="comment">/* Oh dear </phrase><emphasis role="bold">bold</emphasis><phrase role="comment">
+<programlisting><phrase role="comment">/* Oh dear <emphasis role="bold">bold</emphasis>
</phrase></programlisting>
</article>
Modified: trunk/tools/quickbook/test/code-block-python.gold
==============================================================================
--- trunk/tools/quickbook/test/code-block-python.gold (original)
+++ trunk/tools/quickbook/test/code-block-python.gold 2011-04-09 07:29:22 EDT (Sat, 09 Apr 2011)
@@ -4,7 +4,7 @@
xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Python Code Blocks</title>
<programlisting><phrase role="comment"># No escape</phrase>
-<phrase role="comment"># Escape: </phrase><emphasis role="bold">bold</emphasis>
-<phrase role="comment"># Escape: </phrase><emphasis role="underline">underline</emphasis><emphasis>italic</emphasis>
+<phrase role="comment"># Escape: <emphasis role="bold">bold</emphasis></phrase>
+<phrase role="comment"># Escape: <emphasis role="underline">underline</emphasis><emphasis>italic</emphasis></phrase>
</programlisting>
</article>
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