Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68926 - in branches/quickbook-filenames/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-02-15 15:41:06


Author: danieljames
Date: 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
New Revision: 68926
URL: http://svn.boost.org/trac/boost/changeset/68926

Log:
Improve the simple markup parser.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/iterator.hpp | 15 +++++++++-
   branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp | 55 +++++++++++++++++++++++++++++++++++++--
   branches/quickbook-filenames/tools/quickbook/test/quickbook-manual.gold | 4 +-
   branches/quickbook-filenames/tools/quickbook/test/simple_markup.gold | 5 ++
   branches/quickbook-filenames/tools/quickbook/test/simple_markup.quickbook | 2 +
   5 files changed, 73 insertions(+), 8 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/iterator.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/iterator.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/iterator.hpp 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
@@ -11,6 +11,8 @@
 
 #include <boost/operators.hpp>
 #include <boost/iterator/iterator_traits.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <iterator>
 
 namespace quickbook
 {
@@ -35,9 +37,9 @@
     {
         position_iterator() {}
         explicit position_iterator(Iterator base)
- : base_(base), previous_('\0'), position_() {}
+ : original_(base), base_(base), previous_('\0'), position_() {}
         explicit position_iterator(Iterator base, file_position const& position)
- : base_(base), previous_('\0'), position_(position) {}
+ : original_(base), base_(base), previous_('\0'), position_(position) {}
     
         friend bool operator==(
             position_iterator const& x,
@@ -82,8 +84,17 @@
         Iterator base() const {
             return base_;
         }
+
+ typedef boost::iterator_range<std::reverse_iterator<Iterator> >
+ lookback_range;
+
+ lookback_range lookback() const
+ {
+ return lookback_range(base_, original_);
+ }
     
     private:
+ Iterator original_;
         Iterator base_;
         char previous_;
         file_position position_;

Modified: branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/main_grammar.cpp 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
@@ -23,6 +23,52 @@
 {
     namespace cl = boost::spirit::classic;
 
+ struct simple_markup_start_parser
+ : public cl::unary< cl::chlit<char>, cl::parser< simple_markup_start_parser > >
+ {
+ typedef simple_markup_start_parser self_t;
+ typedef cl::unary< cl::chlit<char>, cl::parser< simple_markup_start_parser > > base_t;
+
+ template <typename ScannerT>
+ struct result
+ {
+ typedef typename cl::parser_result<cl::chlit<char>, ScannerT>::type type;
+ };
+
+ simple_markup_start_parser(char c)
+ : base_t(cl::ch_p(c))
+ {}
+
+ template <typename ScannerT>
+ typename result<ScannerT>::type parse(ScannerT const &scan) const
+ {
+ typedef typename ScannerT::iterator_t iterator_t;
+ iterator_t save = scan.first;
+
+ typename cl::parser_result<cl::chlit<char>, ScannerT>::type result
+ = this->subject().parse(scan);
+
+ typename iterator_t::lookback_range lookback = save.lookback();
+
+ if (result && (
+ lookback.begin() == lookback.end() ||
+ cl::punct_p.test(*lookback.begin()) ||
+ cl::space_p.test(*lookback.begin())
+ ))
+ {
+ return scan.create_match(result.length(), cl::nil_t(), save, scan.first);
+ }
+ else {
+ return scan.no_match();
+ }
+ }
+ };
+
+ simple_markup_start_parser start_parser(char c)
+ {
+ return simple_markup_start_parser(c);
+ }
+
     template <typename Rule, typename Action>
     inline void
     simple_markup(
@@ -33,7 +79,7 @@
     )
     {
         simple =
- mark >>
+ start_parser(mark) >>
             (
                 (
                     cl::graph_p // A single char. e.g. *c*
@@ -44,8 +90,11 @@
             |
                 ( cl::graph_p >> // graph_p must follow mark
                     *(cl::anychar_p -
- ( (cl::graph_p >> mark) // Make sure that we don't go
- | close // past a single block
+ ( cl::graph_p
+ >> mark
+ >> (cl::space_p | cl::punct_p | cl::end_p)
+ | close // Make sure that we don't go
+ // past a single block
                         )
                     ) >> cl::graph_p // graph_p must precede mark
>> cl::eps_p(mark

Modified: branches/quickbook-filenames/tools/quickbook/test/quickbook-manual.gold
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/quickbook-manual.gold (original)
+++ branches/quickbook-filenames/tools/quickbook/test/quickbook-manual.gold 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
@@ -3178,8 +3178,8 @@
     :
         my_doc
     :
- &lt;xsl:param&gt;boost.image.src<literal>images/my_project_logo.png
- &lt;xsl:param&gt;boost.image.alt</literal>&quot;\&quot;My Project\&quot;&quot;
+ &lt;xsl:param&gt;boost.image.src=images/my_project_logo.png
+ &lt;xsl:param&gt;boost.image.alt=&quot;\&quot;My Project\&quot;&quot;
         &lt;xsl:param&gt;boost.image.w=100
         &lt;xsl:param&gt;boost.image.h=50
         &lt;xsl:param&gt;nav.layout=none

Modified: branches/quickbook-filenames/tools/quickbook/test/simple_markup.gold
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/simple_markup.gold (original)
+++ branches/quickbook-filenames/tools/quickbook/test/simple_markup.gold 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
@@ -10,10 +10,13 @@
       role="underline">underline</emphasis> <literal>teletype</literal>
     </para>
     <para>
- /all<emphasis>italic</emphasis> * not bold*
+ <emphasis>all/italic</emphasis> * not bold*
     </para>
     <para>
       /not italic <ulink url="http://www.boost.org/"><emphasis role="bold">bold</emphasis></ulink>
     </para>
+ <para>
+ not_underlined_
+ </para>
   </section>
 </article>

Modified: branches/quickbook-filenames/tools/quickbook/test/simple_markup.quickbook
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/test/simple_markup.quickbook (original)
+++ branches/quickbook-filenames/tools/quickbook/test/simple_markup.quickbook 2011-02-15 15:41:04 EST (Tue, 15 Feb 2011)
@@ -10,4 +10,6 @@
 
 /not italic [@http://www.boost.org/ *bold*]
 
+not_underlined_
+
 [endsect]
\ No newline at end of file


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