|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75265 - branches/quickbook-dev/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-11-02 04:50:03
Author: danieljames
Date: 2011-11-02 04:49:59 EDT (Wed, 02 Nov 2011)
New Revision: 75265
URL: http://svn.boost.org/trac/boost/changeset/75265
Log:
Quickbook: Move syntax highlight actions.
Plus a little bit of a cleanup. There's a little bit of duplication
caused by this, but I think the clarity is worth it. Really do need a
better way of handling actions.
Text files modified:
branches/quickbook-dev/tools/quickbook/src/actions.cpp | 60 +-----------
branches/quickbook-dev/tools/quickbook/src/actions.hpp | 81 ----------------
branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 2
branches/quickbook-dev/tools/quickbook/src/syntax_highlight.cpp | 186 ++++++++++++++++++++++++++++++++++++---
4 files changed, 179 insertions(+), 150 deletions(-)
Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-11-02 04:49:59 EDT (Wed, 02 Nov 2011)
@@ -575,46 +575,6 @@
actions.out << markup.post;
}
- // TODO: No need to check suppress since this is only used in the syntax
- // highlighter. I should move this or something.
- void span::operator()(parse_iterator first, parse_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()(parse_iterator first, parse_iterator last) const
- {
- out << "<phrase role=\"" << name << "\">";
- while (first != last)
- detail::print_char(*first++, out.get());
- }
-
- void span_end::operator()(parse_iterator first, parse_iterator last) const
- {
- while (first != last)
- detail::print_char(*first++, out.get());
- out << "</phrase>";
- }
-
- void unexpected_char::operator()(parse_iterator first, parse_iterator last) const
- {
- file_position const pos = get_position(first, actions.current_file->source);
-
- detail::outwarn(actions.current_file->path, pos.line)
- << "in column:" << pos.column
- << ", unexpected character: " << detail::utf8(first, last)
- << "\n";
-
- // print out an unexpected character
- out << "<phrase role=\"error\">";
- while (first != last)
- detail::print_char(*first++, out.get());
- out << "</phrase>";
- }
-
void anchor_action(quickbook::actions& actions, value anchor)
{
value_consumer values = anchor;
@@ -644,28 +604,17 @@
}
}
- void space::operator()(char ch) const
+ void space_action::operator()(char ch) const
{
detail::print_space(ch, out.get());
}
- void space::operator()(parse_iterator first, parse_iterator last) const
+ void space_action::operator()(parse_iterator first, parse_iterator last) const
{
while (first != last)
detail::print_space(*first++, out.get());
}
- void pre_escape_back::operator()(parse_iterator, parse_iterator) const
- {
- escape_actions.phrase.push(); // save the stream
- }
-
- void post_escape_back::operator()(parse_iterator, parse_iterator) const
- {
- out << escape_actions.phrase.str();
- escape_actions.phrase.pop(); // restore the stream
- }
-
void source_mode_action(quickbook::actions& actions, value source_mode)
{
actions.source_mode = source_mode_tags::name(source_mode.get_tag());
@@ -736,11 +685,12 @@
detail::print_char(ch, phrase.get());
}
- void plain_char_action::operator()(parse_iterator first, parse_iterator /*last*/) const
+ void plain_char_action::operator()(parse_iterator first, parse_iterator last) const
{
write_anchors(actions, phrase);
- detail::print_char(*first, phrase.get());
+ while (first != last)
+ detail::print_char(*first++, phrase.get());
}
void escape_unicode_action::operator()(parse_iterator first, parse_iterator last) const
Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-11-02 04:49:59 EDT (Wed, 02 Nov 2011)
@@ -158,56 +158,6 @@
std::vector<std::string> anchors;
};
- struct span
- {
- // Decorates c++ code fragments
-
- span(char const* name, collector& out)
- : name(name), out(out) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- char const* name;
- collector& out;
- };
-
- struct span_start
- {
- span_start(char const* name, collector& out)
- : name(name), out(out) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- char const* name;
- collector& out;
- };
-
- struct span_end
- {
- span_end(collector& out)
- : out(out) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- collector& out;
- };
-
- struct unexpected_char
- {
- // Handles unexpected chars in c++ syntax
-
- unexpected_char(
- collector& out
- , quickbook::actions& actions)
- : out(out)
- , actions(actions) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- collector& out;
- quickbook::actions& actions;
- };
-
extern char const* quickbook_get_date;
extern char const* quickbook_get_time;
@@ -224,11 +174,11 @@
quickbook::actions& actions;
};
- struct space
+ struct space_action
{
// Prints a space
- space(collector& out)
+ space_action(collector& out)
: out(out) {}
void operator()(char ch) const;
@@ -237,33 +187,6 @@
collector& out;
};
- struct pre_escape_back
- {
- // Escapes back from code to quickbook (Pre)
-
- pre_escape_back(actions& escape_actions, std::string& save)
- : escape_actions(escape_actions), save(save) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- actions& escape_actions;
- std::string& save;
- };
-
- struct post_escape_back
- {
- // Escapes back from code to quickbook (Post)
-
- post_escape_back(collector& out, actions& escape_actions, std::string& save)
- : out(out), escape_actions(escape_actions), save(save) {}
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- collector& out;
- actions& escape_actions;
- std::string& save;
- };
-
struct plain_char_action
{
// Prints a single plain char.
Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.hpp 2011-11-02 04:49:59 EDT (Wed, 02 Nov 2011)
@@ -98,7 +98,7 @@
inline_code_action inline_code;
paragraph_action paragraph;
phrase_end_action phrase_end;
- space space_char;
+ space_action space_char;
plain_char_action plain_char;
escape_unicode_action escape_unicode;
Modified: branches/quickbook-dev/tools/quickbook/src/syntax_highlight.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/syntax_highlight.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/syntax_highlight.cpp 2011-11-02 04:49:59 EDT (Wed, 02 Nov 2011)
@@ -15,11 +15,170 @@
#include "grammar.hpp"
#include "grammar_impl.hpp" // Just for context stuff. Should move?
#include "actions_class.hpp"
+#include "files.hpp"
+#include "input_path.hpp"
namespace quickbook
{
namespace cl = boost::spirit::classic;
+ // quickbook::actions is used in a few places here, as 'escape_actions'.
+ // It's named differently to distinguish it from the syntax highlighting
+ // actions, declared below.
+
+ // Syntax Highlight Actions
+
+ struct span
+ {
+ // Decorates c++ code fragments
+
+ span(char const* name, collector& out)
+ : name(name), out(out) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ char const* name;
+ collector& out;
+ };
+
+ struct span_start
+ {
+ span_start(char const* name, collector& out)
+ : name(name), out(out) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ char const* name;
+ collector& out;
+ };
+
+ struct span_end
+ {
+ span_end(collector& out)
+ : out(out) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ collector& out;
+ };
+
+ struct unexpected_char
+ {
+ // Handles unexpected chars in c++ syntax
+
+ unexpected_char(
+ collector& out
+ , quickbook::actions& escape_actions)
+ : out(out)
+ , escape_actions(escape_actions) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ collector& out;
+ quickbook::actions& escape_actions;
+ };
+
+ struct plain_char
+ {
+ // Prints a single plain char.
+ // Converts '<' to "<"... etc See utils.hpp
+
+ plain_char(collector& out)
+ : out(out) {}
+
+ void operator()(char ch) const;
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ collector& out;
+ };
+
+ struct pre_escape_back
+ {
+ // Escapes back from code to quickbook (Pre)
+
+ pre_escape_back(actions& escape_actions)
+ : escape_actions(escape_actions) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ actions& escape_actions;
+ };
+
+ struct post_escape_back
+ {
+ // Escapes back from code to quickbook (Post)
+
+ post_escape_back(collector& out, actions& escape_actions)
+ : out(out), escape_actions(escape_actions) {}
+
+ void operator()(parse_iterator first, parse_iterator last) const;
+
+ collector& out;
+ actions& escape_actions;
+ };
+
+ void span::operator()(parse_iterator first, parse_iterator last) const
+ {
+ out << "<phrase role=\"" << name << "\">";
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ out << "</phrase>";
+ }
+
+ void span_start::operator()(parse_iterator first, parse_iterator last) const
+ {
+ out << "<phrase role=\"" << name << "\">";
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ }
+
+ void span_end::operator()(parse_iterator first, parse_iterator last) const
+ {
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ out << "</phrase>";
+ }
+
+ void unexpected_char::operator()(parse_iterator first, parse_iterator last) const
+ {
+ file_position const pos = get_position(first, escape_actions.current_file->source);
+
+ detail::outwarn(escape_actions.current_file->path, pos.line)
+ << "in column:" << pos.column
+ << ", unexpected character: " << detail::utf8(first, last)
+ << "\n";
+
+ // print out an unexpected character
+ out << "<phrase role=\"error\">";
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ out << "</phrase>";
+ }
+
+ void plain_char::operator()(char ch) const
+ {
+ detail::print_char(ch, out.get());
+ }
+
+ void plain_char::operator()(parse_iterator first, parse_iterator last) const
+ {
+ while (first != last)
+ detail::print_char(*first++, out.get());
+ }
+
+ void pre_escape_back::operator()(parse_iterator, parse_iterator) const
+ {
+ escape_actions.phrase.push(); // save the stream
+ }
+
+ void post_escape_back::operator()(parse_iterator, parse_iterator) const
+ {
+ out << escape_actions.phrase.str();
+ escape_actions.phrase.pop(); // restore the stream
+ }
+
+ // Syntax
+
struct keywords_holder
{
cl::symbols<> cpp, python;
@@ -80,7 +239,7 @@
{
program
=
- *( (+cl::space_p) [space(self.out)]
+ *( (+cl::space_p) [plain_char(self.out)]
| macro
| escape
| preprocessor [span("preprocessor", self.out)]
@@ -104,7 +263,7 @@
;
escape =
- cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions)]
>>
(
(
@@ -119,7 +278,7 @@
cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
)
- ) [post_escape_back(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions)]
;
preprocessor
@@ -130,13 +289,13 @@
= cl::str_p("//") [span_start("comment", self.out)]
>> *( escape
| (+(cl::anychar_p - (cl::eol_p | "``")))
- [span(0, self.out)]
+ [plain_char(self.out)]
)
>> cl::eps_p [span_end(self.out)]
| cl::str_p("/*") [span_start("comment", self.out)]
>> *( escape
| (+(cl::anychar_p - (cl::str_p("*/") | "``")))
- [span(0, self.out)]
+ [plain_char(self.out)]
)
>> (!cl::str_p("*/")) [span_end(self.out)]
;
@@ -179,7 +338,6 @@
string_char;
quickbook_grammar& g;
- std::string save;
cl::rule<Scanner> const&
start() const { return program; }
@@ -206,7 +364,7 @@
{
program
=
- *( (+cl::space_p) [space(self.out)]
+ *( (+cl::space_p) [plain_char(self.out)]
| macro
| escape
| comment
@@ -228,7 +386,7 @@
;
escape =
- cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions)]
>>
(
(
@@ -243,14 +401,14 @@
cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
)
- ) [post_escape_back(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions)]
;
comment
= cl::str_p("#") [span_start("comment", self.out)]
>> *( escape
| (+(cl::anychar_p - (cl::eol_p | "``")))
- [span(0, self.out)]
+ [plain_char(self.out)]
)
>> cl::eps_p [span_end(self.out)]
;
@@ -305,7 +463,6 @@
escape, string_char;
quickbook_grammar& g;
- std::string save;
cl::rule<Scanner> const&
start() const { return program; }
@@ -332,7 +489,7 @@
=
*( macro
| escape
- | cl::repeat_p(1)[cl::anychar_p] [plain_char_action(self.out, self.escape_actions)]
+ | cl::repeat_p(1)[cl::anychar_p] [plain_char(self.out)]
)
;
@@ -344,7 +501,7 @@
;
escape =
- cl::str_p("``") [pre_escape_back(self.escape_actions, save)]
+ cl::str_p("``") [pre_escape_back(self.escape_actions)]
>>
(
(
@@ -359,14 +516,13 @@
cl::eps_p [self.escape_actions.error]
>> *cl::anychar_p
)
- ) [post_escape_back(self.out, self.escape_actions, save)]
+ ) [post_escape_back(self.out, self.escape_actions)]
;
}
cl::rule<Scanner> program, macro, escape;
quickbook_grammar& g;
- std::string save;
cl::rule<Scanner> const&
start() const { return program; }
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