Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71098 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-04-07 20:10:00


Author: danieljames
Date: 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
New Revision: 71098
URL: http://svn.boost.org/trac/boost/changeset/71098

Log:
Quickbook: Escapes in syntax highlighted comments.

Not great since it closes the comments around the escaped code. But to
nest it properly will require a bigger change. Would also be nice to
deal with escape in other contexts - such as strings.
Added:
   trunk/tools/quickbook/test/code-block-cpp.gold (contents, props changed)
   trunk/tools/quickbook/test/code-block-cpp.quickbook (contents, props changed)
   trunk/tools/quickbook/test/code-block-python.gold (contents, props changed)
   trunk/tools/quickbook/test/code-block-python.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/src/syntax_highlight.hpp | 32 ++++++++++++++++++++++++++++----
   trunk/tools/quickbook/test/Jamfile.v2 | 2 ++
   trunk/tools/quickbook/test/quickbook-manual.gold | 24 ++++++++++++------------
   3 files changed, 42 insertions(+), 16 deletions(-)

Modified: trunk/tools/quickbook/src/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/src/syntax_highlight.hpp (original)
+++ trunk/tools/quickbook/src/syntax_highlight.hpp 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -50,7 +50,7 @@
                     | macro
                     | escape
                     | preprocessor [Process("preprocessor", self.out)]
- | comment [Process("comment", self.out)]
+ | comment
                     | keyword [Process("keyword", self.out)]
                     | identifier [Process("identifier", self.out)]
                     | special [Process("special", self.out)]
@@ -102,7 +102,29 @@
                     ;
 
                 comment
- = cl::comment_p("//") | cl::comment_p("/*", "*/")
+ = ( "//"
+ >> *(cl::anychar_p - (cl::eol_p | "``"))
+ ) [Process("comment", self.out)]
+ >> *( escape
+ | (
+ +(cl::anychar_p - (cl::eol_p | "``"))
+ ) [Process("comment", self.out)]
+ )
+ | ( "/*"
+ >> *(cl::anychar_p - (cl::str_p("*/") | "``"))
+ >> ("*/" | cl::end_p)
+ ) [Process("comment", self.out)]
+ | ( "/*"
+ >> *(cl::anychar_p - "``")
+ ) [Process("comment", self.out)]
+ >> *( escape
+ | ( +(cl::anychar_p - (cl::str_p("*/") | "``"))
+ >> cl::eps_p("``")
+ ) [Process("comment", self.out)]
+ )
+ >> !( +(cl::anychar_p - cl::str_p("*/"))
+ >> !cl::str_p("*/")
+ ) [Process("comment", self.out)]
                     ;
 
                 keyword
@@ -202,7 +224,7 @@
                     *( (+cl::space_p) [Space(self.out)]
                     | macro
                     | escape
- | comment [Process("comment", self.out)]
+ | comment
                     | keyword [Process("keyword", self.out)]
                     | identifier [Process("identifier", self.out)]
                     | special [Process("special", self.out)]
@@ -250,7 +272,9 @@
                     ;
 
                 comment
- = cl::comment_p("#")
+ = ( "#"
+ >> *(cl::anychar_p - (cl::eol_p | "``"))
+ ) [Process("comment", self.out)]
                     ;
 
                 keyword

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -26,6 +26,8 @@
     [ quickbook-test code-block-2 ]
     [ quickbook-test code-block-3 ]
     [ quickbook-test code-block-teletype ]
+ [ quickbook-test code-block-cpp ]
+ [ quickbook-test code-block-python ]
     [ quickbook-test code-snippet ]
     [ quickbook-test preformatted ]
     [ quickbook-test link ]

Added: trunk/tools/quickbook/test/code-block-cpp.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-cpp.gold 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="c___code_blocks" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>C++ Code Blocks</title>
+<programlisting><phrase role="comment">// No escape</phrase>
+<phrase role="comment">/* No escape */</phrase>
+<phrase role="comment">/* No escape
+ * with newlines
+ */</phrase>
+<phrase role="comment">// In Header: &lt;</phrase><ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink><phrase role="comment">&gt;</phrase>
+<phrase role="comment">/* In Header: &lt;</phrase><ulink url="boost:/boost/optional/optional.hpp">boost/optional/optional.hpp</ulink><phrase role="comment">&gt; */</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>
+</programlisting>
+ <para>
+ A badly formed comment:
+ </para>
+
+<programlisting><phrase role="comment">/* Oh dear
+</phrase></programlisting>
+ <para>
+ A badly formed comment with an escape:
+ </para>
+
+<programlisting><phrase role="comment">/* Oh dear </phrase><emphasis role="bold">bold</emphasis><phrase role="comment">
+</phrase></programlisting>
+</article>

Added: trunk/tools/quickbook/test/code-block-cpp.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-cpp.quickbook 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -0,0 +1,22 @@
+[article C++ Code Blocks
+[quickbook 1.5]
+]
+
+ // No escape
+ /* No escape */
+ /* No escape
+ * with newlines
+ */
+ // In Header: <``[@boost:/boost/optional/optional.hpp boost/optional/optional.hpp]``>
+ /* In Header: <``[@boost:/boost/optional/optional.hpp boost/optional/optional.hpp]``> */
+ /* Multiple escapes: ``/italic/``
+ * ``_underline_````*bold*``
+ */
+
+A badly formed comment:
+
+ /* Oh dear
+
+A badly formed comment with an escape:
+
+ /* Oh dear ``*bold*``

Added: trunk/tools/quickbook/test/code-block-python.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-python.gold 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="python_code_blocks" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ 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>
+</programlisting>
+</article>

Added: trunk/tools/quickbook/test/code-block-python.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-python.quickbook 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -0,0 +1,8 @@
+[article Python Code Blocks
+[quickbook 1.5]
+[source-mode python]
+]
+
+ # No escape
+ # Escape: ``*bold*``
+ # Escape: ``_underline_````/italic/``

Modified: trunk/tools/quickbook/test/quickbook-manual.gold
==============================================================================
--- trunk/tools/quickbook/test/quickbook-manual.gold (original)
+++ trunk/tools/quickbook/test/quickbook-manual.gold 2011-04-07 20:09:59 EDT (Thu, 07 Apr 2011)
@@ -1549,8 +1549,8 @@
 
 <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
 <phrase role="special">{</phrase>
- <phrase role="comment">// Sample code
-</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;Hello, World\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="comment">// Sample code</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;Hello, World\n&quot;</phrase><phrase role="special">;</phrase>
     <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
 <phrase role="special">}</phrase>
 </programlisting>
@@ -2714,8 +2714,8 @@
           
 <programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">foo</phrase><phrase role="special">()</phrase>
 <phrase role="special">{</phrase>
- <phrase role="comment">// return 'em, foo man!
-</phrase> <phrase role="keyword">return</phrase> <phrase role="string">&quot;foo&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="comment">// return 'em, foo man!</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="string">&quot;foo&quot;</phrase><phrase role="special">;</phrase>
 <phrase role="special">}</phrase>
 </programlisting>
         </para>
@@ -2726,8 +2726,8 @@
           
 <programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">bar</phrase><phrase role="special">()</phrase>
 <phrase role="special">{</phrase>
- <phrase role="comment">// return 'em, bar man!
-</phrase> <phrase role="keyword">return</phrase> <phrase role="string">&quot;bar&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="comment">// return 'em, bar man!</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="string">&quot;bar&quot;</phrase><phrase role="special">;</phrase>
 <phrase role="special">}</phrase></programlisting>
         </para>
         <para>
@@ -2743,10 +2743,10 @@
           get marked up. We use distinguishable comments following the form:
         </para>
         
-<programlisting><phrase role="comment">//[id
-</phrase><phrase role="identifier">some</phrase> <phrase role="identifier">code</phrase> <phrase role="identifier">here</phrase>
-<phrase role="comment">//]
-</phrase></programlisting>
+<programlisting><phrase role="comment">//[id</phrase>
+<phrase role="identifier">some</phrase> <phrase role="identifier">code</phrase> <phrase role="identifier">here</phrase>
+<phrase role="comment">//]</phrase>
+</programlisting>
         <para>
           The first comment line above initiates a named code-snippet. This prefix
           will not be visible in quickbook. The entire code-snippet in between <code><phrase
@@ -2764,8 +2764,8 @@
           Special comments of the form:
         </para>
         
-<programlisting><phrase role="comment">//` some [*quickbook] markup here
-</phrase></programlisting>
+<programlisting><phrase role="comment">//` some [*quickbook] markup here</phrase>
+</programlisting>
         <para>
           and:
         </para>


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