Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71142 - trunk/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-04-09 07:28:21


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

Log:
Quickbook: Detemplate the syntax highlighters.
Text files modified:
   trunk/tools/quickbook/src/syntax_highlight.cpp | 40 +-----------
   trunk/tools/quickbook/src/syntax_highlight.hpp | 128 +++++++++++++++------------------------
   2 files changed, 53 insertions(+), 115 deletions(-)

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:28:20 EDT (Sat, 09 Apr 2011)
@@ -8,41 +8,9 @@
     http://www.boost.org/LICENSE_1_0.txt)
 =============================================================================*/
 #include "syntax_highlight.hpp"
-#include "actions_class.hpp"
 
 namespace quickbook
-{
- typedef cpp_highlight<
- span
- , space
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , unexpected_char
- , collector>
- cpp_p_type;
-
- typedef python_highlight<
- span
- , space
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , unexpected_char
- , collector>
- python_p_type;
-
- typedef teletype_highlight<
- plain_char_action
- , string_symbols
- , do_macro_action
- , pre_escape_back
- , post_escape_back
- , collector>
- teletype_p_type;
-
+{
     std::string syntax_highlight(
         iterator first, iterator last,
         actions& escape_actions,
@@ -53,17 +21,17 @@
         // print the code with syntax coloring
         if (source_mode == "c++")
         {
- cpp_p_type cpp_p(temp, escape_actions.macro, do_macro_action(temp, escape_actions), escape_actions);
+ cpp_highlight cpp_p(temp, escape_actions);
             boost::spirit::classic::parse(first, last, cpp_p);
         }
         else if (source_mode == "python")
         {
- python_p_type python_p(temp, escape_actions.macro, do_macro_action(temp, escape_actions), escape_actions);
+ python_highlight python_p(temp, escape_actions);
             boost::spirit::classic::parse(first, last, python_p);
         }
         else if (source_mode == "teletype")
         {
- teletype_p_type teletype_p(temp, escape_actions.macro, do_macro_action(temp, escape_actions), escape_actions);
+ teletype_highlight teletype_p(temp, escape_actions);
             boost::spirit::classic::parse(first, last, teletype_p);
         }
         else

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-09 07:28:20 EDT (Sat, 09 Apr 2011)
@@ -17,26 +17,18 @@
 #include <boost/spirit/include/classic_loops.hpp>
 #include "grammar.hpp"
 #include "grammar_impl.hpp" // Just for context stuff. Should move?
+#include "actions_class.hpp"
 
 namespace quickbook
 {
     namespace cl = boost::spirit::classic;
 
     // Grammar for C++ highlighting
- template <
- typename Process
- , typename Space
- , typename Macro
- , typename DoMacro
- , typename PreEscape
- , typename PostEscape
- , typename Unexpected
- , typename Out>
     struct cpp_highlight
- : public cl::grammar<cpp_highlight<Process, Space, Macro, DoMacro, PreEscape, PostEscape, Unexpected, Out> >
+ : public cl::grammar<cpp_highlight>
     {
- cpp_highlight(Out& out, Macro const& macro, DoMacro do_macro, actions& escape_actions)
- : out(out), macro(macro), do_macro(do_macro), escape_actions(escape_actions) {}
+ cpp_highlight(collector& out, actions& escape_actions)
+ : out(out), escape_actions(escape_actions) {}
 
         template <typename Scanner>
         struct definition
@@ -46,27 +38,27 @@
             {
                 program
                     =
- *( (+cl::space_p) [Space(self.out)]
+ *( (+cl::space_p) [space(self.out)]
                     | macro
                     | escape
- | preprocessor [Process("preprocessor", self.out)]
+ | preprocessor [span("preprocessor", self.out)]
                     | comment
- | keyword [Process("keyword", self.out)]
- | identifier [Process("identifier", self.out)]
- | special [Process("special", self.out)]
- | string_ [Process("string", self.out)]
- | char_ [Process("char", self.out)]
- | number [Process("number", self.out)]
+ | keyword [span("keyword", self.out)]
+ | identifier [span("identifier", self.out)]
+ | special [span("special", self.out)]
+ | string_ [span("string", self.out)]
+ | char_ [span("char", self.out)]
+ | number [span("number", self.out)]
                     | cl::repeat_p(1)[cl::anychar_p]
- [Unexpected(self.out, self.escape_actions)]
+ [unexpected_char(self.out, self.escape_actions)]
                     )
                     ;
 
                 macro =
                     // must not be followed by alpha or underscore
- cl::eps_p(self.macro
+ cl::eps_p(self.escape_actions.macro
>> (cl::eps_p - (cl::alpha_p | '_')))
- >> self.macro [self.do_macro]
+ >> self.escape_actions.macro [do_macro_action(self.out, self.escape_actions)]
                     ;
 
                 qbk_phrase =
@@ -79,7 +71,7 @@
                     ;
 
                 escape =
- cl::str_p("``") [PreEscape(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
>>
                     (
                         (
@@ -94,7 +86,7 @@
                             cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
                         )
- ) [PostEscape(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions, save)]
                     ;
 
                 preprocessor
@@ -104,27 +96,27 @@
                 comment
                     = ( "//"
>> *(cl::anychar_p - (cl::eol_p | "``"))
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
>> *( escape
                         | (
                                 +(cl::anychar_p - (cl::eol_p | "``"))
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
                         )
                     | ( "/*"
>> *(cl::anychar_p - (cl::str_p("*/") | "``"))
>> ("*/" | cl::end_p)
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
                     | ( "/*"
>> *(cl::anychar_p - "``")
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
>> *( escape
                         | ( +(cl::anychar_p - (cl::str_p("*/") | "``"))
>> cl::eps_p("``")
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
                         )
>> !( +(cl::anychar_p - cl::str_p("*/"))
>> !cl::str_p("*/")
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
                     ;
 
                 keyword
@@ -189,29 +181,18 @@
             start() const { return program; }
         };
 
- Out& out;
- Macro const& macro;
- DoMacro do_macro;
+ collector& out;
         actions& escape_actions;
     };
 
     // Grammar for Python highlighting
     // See also: The Python Reference Manual
     // http://docs.python.org/ref/ref.html
- template <
- typename Process
- , typename Space
- , typename Macro
- , typename DoMacro
- , typename PreEscape
- , typename PostEscape
- , typename Unexpected
- , typename Out>
     struct python_highlight
- : public cl::grammar<python_highlight<Process, Space, Macro, DoMacro, PreEscape, PostEscape, Unexpected, Out> >
+ : public cl::grammar<python_highlight>
     {
- python_highlight(Out& out, Macro const& macro, DoMacro do_macro, actions& escape_actions)
- : out(out), macro(macro), do_macro(do_macro), escape_actions(escape_actions) {}
+ python_highlight(collector& out, actions& escape_actions)
+ : out(out), escape_actions(escape_actions) {}
 
         template <typename Scanner>
         struct definition
@@ -221,25 +202,25 @@
             {
                 program
                     =
- *( (+cl::space_p) [Space(self.out)]
+ *( (+cl::space_p) [space(self.out)]
                     | macro
                     | escape
                     | comment
- | keyword [Process("keyword", self.out)]
- | identifier [Process("identifier", self.out)]
- | special [Process("special", self.out)]
- | string_ [Process("string", self.out)]
- | number [Process("number", self.out)]
+ | keyword [span("keyword", self.out)]
+ | identifier [span("identifier", self.out)]
+ | special [span("special", self.out)]
+ | string_ [span("string", self.out)]
+ | number [span("number", self.out)]
                     | cl::repeat_p(1)[cl::anychar_p]
- [Unexpected(self.out, self.escape_actions)]
+ [unexpected_char(self.out, self.escape_actions)]
                     )
                     ;
 
                 macro =
                     // must not be followed by alpha or underscore
- cl::eps_p(self.macro
+ cl::eps_p(self.escape_actions.macro
>> (cl::eps_p - (cl::alpha_p | '_')))
- >> self.macro [self.do_macro]
+ >> self.escape_actions.macro [do_macro_action(self.out, self.escape_actions)]
                     ;
 
                 qbk_phrase =
@@ -253,7 +234,7 @@
                     ;
 
                 escape =
- cl::str_p("``") [PreEscape(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
>>
                     (
                         (
@@ -268,13 +249,13 @@
                             cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
                         )
- ) [PostEscape(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions, save)]
                     ;
 
                 comment
                     = ( "#"
>> *(cl::anychar_p - (cl::eol_p | "``"))
- ) [Process("comment", self.out)]
+ ) [span("comment", self.out)]
                     ;
 
                 keyword
@@ -350,25 +331,16 @@
             start() const { return program; }
         };
 
- Out& out;
- Macro const& macro;
- DoMacro do_macro;
+ collector& out;
         actions& escape_actions;
     };
 
     // Grammar for plain text (no actual highlighting)
- template <
- typename CharProcess
- , typename Macro
- , typename DoMacro
- , typename PreEscape
- , typename PostEscape
- , typename Out>
     struct teletype_highlight
- : public cl::grammar<teletype_highlight<CharProcess, Macro, DoMacro, PreEscape, PostEscape, Out> >
+ : public cl::grammar<teletype_highlight>
     {
- teletype_highlight(Out& out, Macro const& macro, DoMacro do_macro, actions& escape_actions)
- : out(out), macro(macro), do_macro(do_macro), escape_actions(escape_actions) {}
+ teletype_highlight(collector& out, actions& escape_actions)
+ : out(out), escape_actions(escape_actions) {}
 
         template <typename Scanner>
         struct definition
@@ -380,15 +352,15 @@
                     =
                     *( macro
                     | escape
- | cl::repeat_p(1)[cl::anychar_p] [CharProcess(self.out, self.escape_actions)]
+ | cl::repeat_p(1)[cl::anychar_p] [plain_char_action(self.out, self.escape_actions)]
                     )
                     ;
 
                 macro =
                     // must not be followed by alpha or underscore
- cl::eps_p(self.macro
+ cl::eps_p(self.escape_actions.macro
>> (cl::eps_p - (cl::alpha_p | '_')))
- >> self.macro [self.do_macro]
+ >> self.escape_actions.macro [do_macro_action(self.out, self.escape_actions)]
                     ;
 
                 qbk_phrase =
@@ -402,7 +374,7 @@
                     ;
 
                 escape =
- cl::str_p("``") [PreEscape(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
>>
                     (
                         (
@@ -417,7 +389,7 @@
                             cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
                         )
- ) [PostEscape(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions, save)]
                     ;
             }
 
@@ -430,9 +402,7 @@
             start() const { return program; }
         };
 
- Out& out;
- Macro const& macro;
- DoMacro do_macro;
+ collector& out;
         actions& escape_actions;
     };
 


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