Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54815 - in trunk/tools/quickbook: . detail doc test
From: daniel_james_at_[hidden]
Date: 2009-07-08 17:40:47


Author: danieljames
Date: 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
New Revision: 54815
URL: http://svn.boost.org/trac/boost/changeset/54815

Log:
Teletype source mode. Refs #1202.
Added:
   trunk/tools/quickbook/test/code-block-teletype.gold (contents, props changed)
   trunk/tools/quickbook/test/code-block-teletype.quickbook (contents, props changed)
Text files modified:
   trunk/tools/quickbook/detail/actions.cpp | 8 ++++
   trunk/tools/quickbook/detail/actions.hpp | 12 ++++++
   trunk/tools/quickbook/doc/quickbook.qbk | 1
   trunk/tools/quickbook/doc_info.hpp | 1
   trunk/tools/quickbook/phrase.hpp | 1
   trunk/tools/quickbook/syntax_highlight.hpp | 79 ++++++++++++++++++++++++++++++++++++++++
   trunk/tools/quickbook/test/Jamfile.v2 | 1
   7 files changed, 103 insertions(+), 0 deletions(-)

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -320,6 +320,14 @@
         {
             parse(first, last, python_p);
         }
+ else if (source_mode == "teletype")
+ {
+ parse(first, last, teletype_p);
+ }
+ else
+ {
+ BOOST_ASSERT(0);
+ }
 
         std::string str;
         temp.swap(str);

Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -432,6 +432,16 @@
       , collector>
     python_p_type;
     
+ typedef teletype_highlight<
+ plain_char_action
+ , string_symbols
+ , do_macro_action
+ , pre_escape_back
+ , post_escape_back
+ , actions
+ , collector>
+ teletype_p_type;
+
     struct syntax_highlight
     {
         syntax_highlight(
@@ -443,6 +453,7 @@
         , source_mode(source_mode)
         , cpp_p(temp, macro, do_macro_action(temp), escape_actions)
         , python_p(temp, macro, do_macro_action(temp), escape_actions)
+ , teletype_p(temp, macro, do_macro_action(temp), escape_actions)
         {
         }
 
@@ -452,6 +463,7 @@
         std::string const& source_mode;
         cpp_p_type cpp_p;
         python_p_type python_p;
+ teletype_p_type teletype_p;
     };
 
     struct code_action

Modified: trunk/tools/quickbook/doc/quickbook.qbk
==============================================================================
--- trunk/tools/quickbook/doc/quickbook.qbk (original)
+++ trunk/tools/quickbook/doc/quickbook.qbk 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -436,6 +436,7 @@
     [[Mode] [Source Mode Markup]]
     [[C++] [[^\[c++\]]]]
     [[Python] [[^\[python\]]]]
+ [[Plain Text] [[^\[teletype\]]]]
 ]
 
 [note The source mode strings are lowercase.]

Modified: trunk/tools/quickbook/doc_info.hpp
==============================================================================
--- trunk/tools/quickbook/doc_info.hpp (original)
+++ trunk/tools/quickbook/doc_info.hpp 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -153,6 +153,7 @@
>> (
                            str_p("c++")
                         | "python"
+ | "teletype"
                         ) [assign_a(actions.source_mode)]
                     ;
 

Modified: trunk/tools/quickbook/phrase.hpp
==============================================================================
--- trunk/tools/quickbook/phrase.hpp (original)
+++ trunk/tools/quickbook/phrase.hpp 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -403,6 +403,7 @@
                     (
                         str_p("c++")
                     | "python"
+ | "teletype"
                     ) [assign_a(actions.source_mode)]
                     ;
 

Modified: trunk/tools/quickbook/syntax_highlight.hpp
==============================================================================
--- trunk/tools/quickbook/syntax_highlight.hpp (original)
+++ trunk/tools/quickbook/syntax_highlight.hpp 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -323,6 +323,85 @@
         DoMacro do_macro;
         EscapeActions& escape_actions;
     };
+
+ // Grammar for plain text (no actual highlighting)
+ template <
+ typename CharProcess
+ , typename Macro
+ , typename DoMacro
+ , typename PreEscape
+ , typename PostEscape
+ , typename EscapeActions
+ , typename Out>
+ struct teletype_highlight
+ : public grammar<teletype_highlight<CharProcess, Macro, DoMacro, PreEscape, PostEscape, EscapeActions, Out> >
+ {
+ teletype_highlight(Out& out, Macro const& macro, DoMacro do_macro, EscapeActions& escape_actions)
+ : out(out), macro(macro), do_macro(do_macro), escape_actions(escape_actions) {}
+
+ template <typename Scanner>
+ struct definition
+ {
+ definition(teletype_highlight const& self)
+ : common(self.escape_actions, unused)
+ , unused(false)
+ {
+ program
+ =
+ *( macro
+ | escape
+ | repeat_p(1)[anychar_p] [CharProcess(self.out)]
+ )
+ ;
+
+ macro =
+ eps_p(self.macro // must not be followed by
+ >> (eps_p - (alpha_p | '_'))) // alpha or underscore
+ >> self.macro [self.do_macro]
+ ;
+
+ qbk_phrase =
+ *( common
+ | (anychar_p - str_p("``")) [self.escape_actions.plain_char]
+ )
+ ;
+
+ escape =
+ str_p("``") [PreEscape(self.escape_actions, save)]
+ >>
+ (
+ (
+ (
+ (+(anychar_p - "``") >> eps_p("``"))
+ & qbk_phrase
+ )
+ >> str_p("``")
+ )
+ |
+ (
+ eps_p [self.escape_actions.error]
+ >> *anychar_p
+ )
+ ) [PostEscape(self.out, self.escape_actions, save)]
+ ;
+ }
+
+ rule<Scanner> program, macro, qbk_phrase, escape;
+
+ phrase_grammar<EscapeActions> common;
+ std::string save;
+ bool unused;
+
+ rule<Scanner> const&
+ start() const { return program; }
+ };
+
+ Out& out;
+ Macro const& macro;
+ DoMacro do_macro;
+ EscapeActions& escape_actions;
+ };
+
 }
 
 #endif // BOOST_SPIRIT_QUICKBOOK_SYNTAX_HIGHLIGHT_HPP

Modified: trunk/tools/quickbook/test/Jamfile.v2
==============================================================================
--- trunk/tools/quickbook/test/Jamfile.v2 (original)
+++ trunk/tools/quickbook/test/Jamfile.v2 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -15,6 +15,7 @@
     [ quickbook-test code-block-1 ]
     [ quickbook-test code-block-2 ]
     [ quickbook-test code-block-3 ]
+ [ quickbook-test code-block-teletype ]
     [ quickbook-test code-snippet ]
     [ quickbook-test preformatted ]
     [ quickbook-test link-side-by-side ]

Added: trunk/tools/quickbook/test/code-block-teletype.gold
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-teletype.gold 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="code_block_teletype_1" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>Code Block Teletype 1</title>
+ <articleinfo>
+ </articleinfo>
+ <para>
+ </para>
+ <section id="code_block_teletype_1.a_code_block">
+ <title><link linkend="code_block_teletype_1.a_code_block">A code block</link></title>
+
+<programlisting>Just some plain text.
+With some <emphasis role="bold">quickbook</emphasis> thrown in?
+</programlisting>
+ </section>
+</article>

Added: trunk/tools/quickbook/test/code-block-teletype.quickbook
==============================================================================
--- (empty file)
+++ trunk/tools/quickbook/test/code-block-teletype.quickbook 2009-07-08 17:40:46 EDT (Wed, 08 Jul 2009)
@@ -0,0 +1,14 @@
+[article Code Block Teletype 1
+ [quickbook 1.5]
+]
+
+[teletype]
+
+[section A code block]
+
+[def __text__ text]
+
+ Just some plain __text__.
+ ``With some *quickbook* thrown in?``
+
+[endsect]


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