Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75894 - in branches/quickbook-dev/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-12-11 06:13:33


Author: danieljames
Date: 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
New Revision: 75894
URL: http://svn.boost.org/trac/boost/changeset/75894

Log:
Quickbook: Use values for code blocks.

Also better error report for unclosed code block.
Added:
   branches/quickbook-dev/tools/quickbook/test/code_unclosed_block-1_6-fail.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 37 ++++++++++++++++----------
   branches/quickbook-dev/tools/quickbook/src/actions.hpp | 20 --------------
   branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 3 --
   branches/quickbook-dev/tools/quickbook/src/actions_class.hpp | 3 --
   branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp | 56 ++++++++++++++++++++++-----------------
   branches/quickbook-dev/tools/quickbook/src/phrase_tags.hpp | 6 ++++
   branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 | 1
   7 files changed, 62 insertions(+), 64 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-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -89,6 +89,7 @@
     void footnote_action(quickbook::actions&, value);
     void raw_phrase_action(quickbook::actions&, value);
     void source_mode_action(quickbook::actions&, value);
+ void code_action(quickbook::actions&, value);
     void do_template_action(quickbook::actions&, value, string_iterator);
     
     void element_action::operator()(parse_iterator first, parse_iterator) const
@@ -173,6 +174,10 @@
         case source_mode_tags::python:
         case source_mode_tags::teletype:
             return source_mode_action(actions, v);
+ case code_tags::code_block:
+ case code_tags::inline_code_block:
+ case code_tags::inline_code:
+ return code_action(actions, v);
         case template_tags::template_:
             return do_template_action(actions, v, first.base());
         default:
@@ -586,11 +591,17 @@
         actions.source_mode = source_mode_tags::name(source_mode.get_tag());
     }
 
- void code_action::operator()(parse_iterator first, parse_iterator last) const
+ void code_action(quickbook::actions& actions, value code_block)
     {
- bool inline_code = type == inline_ ||
- (type == inline_block && qbk_version_n < 106u);
- bool block = type != inline_;
+ int code_tag = code_block.get_tag();
+
+ value_consumer values = code_block;
+ string_ref code_value = values.consume().get_quickbook();
+ values.finish();
+
+ bool inline_code = code_tag == code_tags::inline_code ||
+ (code_tag == code_tags::inline_code_block && qbk_version_n < 106u);
+ bool block = code_tag != code_tags::inline_code;
 
         if (inline_code) {
             write_anchors(actions, actions.phrase);
@@ -600,13 +611,11 @@
             write_anchors(actions, actions.out);
         }
 
- std::string str;
-
         if (block) {
             // preprocess the code section to remove the initial indentation
             mapped_file_builder mapped;
             mapped.start(actions.current_file);
- mapped.unindent_and_add(first.base(), last.base());
+ mapped.unindent_and_add(code_value.begin(), code_value.end());
 
             file_ptr f = mapped.release();
 
@@ -620,16 +629,11 @@
             boost::swap(actions.current_file, saved_file);
 
             // print the code with syntax coloring
- str = syntax_highlight(first_, last_, actions, actions.source_mode);
+ std::string str = syntax_highlight(first_, last_, actions,
+ actions.source_mode);
 
             boost::swap(actions.current_file, saved_file);
- }
- else {
- parse_iterator first_(first);
- str = syntax_highlight(first_, last, actions, actions.source_mode);
- }
 
- if (block) {
             collector& output = inline_code ? actions.phrase : actions.out;
 
             // We must not place a \n after the <programlisting> tag
@@ -640,6 +644,11 @@
             output << "</programlisting>\n";
         }
         else {
+ parse_iterator first_(code_value.begin());
+ parse_iterator last_(code_value.end());
+ std::string str = syntax_highlight(first_, last_, actions,
+ actions.source_mode);
+
             actions.phrase << "<code>";
             actions.phrase << str;
             actions.phrase << "</code>";

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-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -242,26 +242,6 @@
         quickbook::actions& actions;
     };
 
- struct code_action
- {
- enum code_type { block, inline_block, inline_ };
-
- // Does the actual syntax highlighing of code
-
- code_action(
- code_type type
- , quickbook::actions& actions)
- : type(type)
- , actions(actions)
- {
- }
-
- void operator()(parse_iterator first, parse_iterator last) const;
-
- code_type type;
- quickbook::actions& actions;
- };
-
     struct break_action
     {
         break_action(collector& phrase, quickbook::actions& actions)

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -51,9 +51,6 @@
 
         , element(*this)
         , error(*this)
- , code(code_action::block, *this)
- , code_block(code_action::inline_block, *this)
- , inline_code(code_action::inline_, *this)
         , paragraph(*this)
         , list_item(*this)
         , phrase_end(*this)

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-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -84,9 +84,6 @@
         element_action element;
         error_action error;
 
- code_action code;
- code_action code_block;
- code_action inline_code;
         paragraph_action paragraph;
         list_item_action list_item;
         phrase_end_action phrase_end;

Modified: branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/main_grammar.cpp 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -425,10 +425,11 @@
             ;
 
         local.code =
- (
- local.code_line
+ actions.values.list(code_tags::code_block)
+ [( local.code_line
>> *(*local.blank_line >> local.code_line)
- ) [actions.code]
+ ) [actions.values.entry(ph::arg1, ph::arg2)]
+ ] [actions.element]
>> *eol
             ;
 
@@ -552,44 +553,51 @@
                 ;
 
         local.inline_code =
- '`' >>
- (
+ '`' >> actions.values.list(code_tags::inline_code)
+ [(
                *(cl::anychar_p -
                     ( '`'
                     | (cl::eol_p >> *cl::blank_p >> cl::eol_p)
                                                 // Make sure that we don't go
                     ) // past a single block
                 ) >> cl::eps_p('`')
- ) [actions.inline_code]
+ ) [actions.values.entry(ph::arg1, ph::arg2)]
>> '`'
+ ] [actions.element]
             ;
 
         local.code_block =
                 "```"
>> ~cl::eps_p("`")
- >> *(*cl::blank_p >> cl::eol_p)
- >> ( *( "````" >> *cl::ch_p('`')
- | ( cl::anychar_p
- - (*cl::space_p >> "```" >> ~cl::eps_p("`"))
- )
- )
- >> !(*cl::blank_p >> cl::eol_p)
- ) [actions.code_block]
- >> ( *cl::space_p >> "```"
+ >> ( actions.values.list(code_tags::inline_code_block)
+ [ *(*cl::blank_p >> cl::eol_p)
+ >> ( *( "````" >> *cl::ch_p('`')
+ | ( cl::anychar_p
+ - (*cl::space_p >> "```" >> ~cl::eps_p("`"))
+ )
+ )
+ >> !(*cl::blank_p >> cl::eol_p)
+ ) [actions.values.entry(ph::arg1, ph::arg2)]
+ >> (*cl::space_p >> "```")
+ ] [actions.element]
                 | cl::eps_p [actions.error("Unfinished code block")]
+ >> *cl::anychar_p
                 )
             | "``"
>> ~cl::eps_p("`")
- >> *(*cl::blank_p >> cl::eol_p)
- >> ( *( "```" >> *cl::ch_p('`')
- | ( cl::anychar_p
- - (*cl::space_p >> "``" >> ~cl::eps_p("`"))
- )
- )
- >> !(*cl::blank_p >> cl::eol_p)
- ) [actions.code_block]
- >> ( *cl::space_p >> "``"
+ >> ( actions.values.list(code_tags::inline_code_block)
+ [ *(*cl::blank_p >> cl::eol_p)
+ >> ( *( "```" >> *cl::ch_p('`')
+ | ( cl::anychar_p
+ - (*cl::space_p >> "``" >> ~cl::eps_p("`"))
+ )
+ )
+ >> !(*cl::blank_p >> cl::eol_p)
+ ) [actions.values.entry(ph::arg1, ph::arg2)]
+ >> (*cl::space_p >> "``")
+ ] [actions.element]
                 | cl::eps_p [actions.error("Unfinished code block")]
+ >> *cl::anychar_p
                 )
             ;
 

Modified: branches/quickbook-dev/tools/quickbook/src/phrase_tags.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/phrase_tags.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/phrase_tags.hpp 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -30,6 +30,12 @@
         ((python)("python"))
         ((teletype)("teletype"))
     )
+
+ QUICKBOOK_VALUE_TAGS(code_tags, 0x560,
+ (code_block)
+ (inline_code)
+ (inline_code_block)
+ )
 }
 
 #endif

Modified: branches/quickbook-dev/tools/quickbook/test/Jamfile.v2
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 (original)
+++ branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -34,6 +34,7 @@
     [ quickbook-error-test code_python_mismatched_escape-1_4-fail ]
     [ quickbook-test code_snippet-1_1 ]
     [ quickbook-test code_teletype-1_5 ]
+ [ quickbook-error-test code_unclosed_block-1_6-fail ]
     [ quickbook-test command_line_macro-1_1 : : :
         <quickbook-test-define>__macro__=*bold*
         <quickbook-test-define>__empty__ ]

Added: branches/quickbook-dev/tools/quickbook/test/code_unclosed_block-1_6-fail.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/code_unclosed_block-1_6-fail.quickbook 2011-12-11 06:13:24 EST (Sun, 11 Dec 2011)
@@ -0,0 +1,4 @@
+[article Odd code markup. [quickbook 1.6] ]
+
+``
+int main() {}


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