Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75321 - in trunk/libs/spirit: doc repository/doc repository/doc/qi repository/example/qi
From: joel_at_[hidden]
Date: 2011-11-05 05:56:31


Author: djowel
Date: 2011-11-05 05:56:29 EDT (Sat, 05 Nov 2011)
New Revision: 75321
URL: http://svn.boost.org/trac/boost/changeset/75321

Log:
Docs for the seek directive
Added:
   trunk/libs/spirit/repository/doc/what_s_new.qbk (contents, props changed)
Text files modified:
   trunk/libs/spirit/doc/what_s_new.qbk | 2 -
   trunk/libs/spirit/repository/doc/qi/seek.qbk | 32 ++++++++++++---------------
   trunk/libs/spirit/repository/example/qi/seek.cpp | 46 ++++++++++++++++-----------------------
   3 files changed, 33 insertions(+), 47 deletions(-)

Modified: trunk/libs/spirit/doc/what_s_new.qbk
==============================================================================
--- trunk/libs/spirit/doc/what_s_new.qbk (original)
+++ trunk/libs/spirit/doc/what_s_new.qbk 2011-11-05 05:56:29 EDT (Sat, 05 Nov 2011)
@@ -15,8 +15,6 @@
 
 * Integrated Vitaly Budovski's patch to add binary floating point parsers and
   generators.
-* Added the __qi__ directive __qi_seek__ enabling skipping over the input,
- getting to the interested portion.
 
 [endsect]
 

Modified: trunk/libs/spirit/repository/doc/qi/seek.qbk
==============================================================================
--- trunk/libs/spirit/repository/doc/qi/seek.qbk (original)
+++ trunk/libs/spirit/repository/doc/qi/seek.qbk 2011-11-05 05:56:29 EDT (Sat, 05 Nov 2011)
@@ -59,21 +59,31 @@
 
 [heading Complexity]
 
-[:The complexity is defined by the complexity of the subject parser, `a`]
+[:The overall complexity is defined by the complexity of its subject
+parser. The complexity of `seek` itself is O(N), where N is the number
+of unsuccessful matches.]
+
+[note *seeking sequence with skipping*
+
+Using `seek[a >> b]` with skipping is inefficient, because when sequence fails, the backtracked position is non-skipped.
+The solution is to ensure the input will always be pre-skipped, for example:
+``
+ seek[lexeme[skip[a >> b]]]
+``
+does the trick.]
 
 [heading Example]
 
 [import ../../example/qi/seek.cpp]
 
-The following example shows a simple use case of the `seek[]` directive, seeking
-all the ints preceding by `'#'`.
+The following example shows a simple use case of the `seek[]` directive, parsing C-style comment.
 (For the full source of the example, see [@../../example/qi/seek.cpp seek.cpp])
 
 Some namespace aliases:
 
 [reference_qi_seek_namespace]
 
-The input iterators and the attribute to store the result:
+The input string and its iterators:
 
 [reference_qi_seek_vars]
 
@@ -81,18 +91,4 @@
 
 [reference_qi_seek_parse]
 
-Input:
-
-[pre
-1 will not be outputted while #2, ##3 and # 4 will.
-]
-
-Output:
-
-[pre
---------------------------------
-Parsing succeeded, got: \[ 2, 3, 4 \]
----------------------------------
-]
-
 [endsect]

Added: trunk/libs/spirit/repository/doc/what_s_new.qbk
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/doc/what_s_new.qbk 2011-11-05 05:56:29 EDT (Sat, 05 Nov 2011)
@@ -0,0 +1,23 @@
+[/==============================================================================
+ Copyright (C) 2001-2011 Joel de Guzman
+ Copyright (C) 2001-2011 Hartmut Kaiser
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+===============================================================================/]
+
+[section What's New]
+
+[/////////////////////////////////////////////////////////////////////////////]
+[section:spirit_2_5_1 Spirit V2.5.1]
+
+This section is added since V2.5.1 (Boost V1.48.0).
+
+[heading New Features in Qi]
+
+* Added the __qi__ directive __qi_seek__ enabling skipping over the input,
+ getting to the interested portion.
+
+[endsect]
+
+[endsect]

Modified: trunk/libs/spirit/repository/example/qi/seek.cpp
==============================================================================
--- trunk/libs/spirit/repository/example/qi/seek.cpp (original)
+++ trunk/libs/spirit/repository/example/qi/seek.cpp 2011-11-05 05:56:29 EDT (Sat, 05 Nov 2011)
@@ -5,15 +5,13 @@
     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //////////////////////////////////////////////////////////////////////////////*/
 
-// [ Jamboree May 3, 2011 ] first ver.
-// [ Jamboree Aug 13, 2011 ] minor change.
+// [ Jamboree Oct 27, 2011 ] new example.
 
 
 #include <cstdlib>
 #include <iostream>
 
 #include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/karma.hpp>
 #include <boost/spirit/repository/include/qi_seek.hpp>
 
 
@@ -21,36 +19,30 @@
 {
     //[reference_qi_seek_namespace
     namespace qi = boost::spirit::qi;
- namespace ka = boost::spirit::karma;
     namespace repo = boost::spirit::repository;
     //]
-
- std::string line;
+
     typedef std::string::const_iterator iterator;
 
- while (std::cout << ">>> ", std::getline(std::cin, line))
+ //[reference_qi_seek_vars
+ std::string str("/*C-style comment*/");
+ iterator it = str.begin();
+ iterator end = str.end();
+ //]
+
+ //[reference_qi_seek_parse
+ if (qi::parse(it, end, "/*" >> repo::qi::seek["*/"]))
     {
- //[reference_qi_seek_vars
- iterator it = line.begin();
- iterator end = line.end();
- std::vector<int> val;
- //]
-
- //[reference_qi_seek_parse
- if (qi::phrase_parse(it, end, +repo::qi::seek["#" >> qi::int_], qi::space, val))
- {
- std::cout << "-------------------------------- \n";
- std::cout << "Parsing succeeded, got: "
- << ka::format("[ " << ka::int_ % ", " << " ]\n", val);
- std::cout << "---------------------------------\n";
- }//]
- else
- {
- std::cout << "-------------------------------- \n";
- std::cout << "Parsing failed, rest: " << std::string(it, end) << "\n";
- std::cout << "-------------------------------- \n";
- }
+ std::cout << "-------------------------------- \n";
+ std::cout << "Parsing succeeded.\n";
+ std::cout << "---------------------------------\n";
     }
+ else
+ {
+ std::cout << "-------------------------------- \n";
+ std::cout << "Unterminated /* comment.\n";
+ std::cout << "-------------------------------- \n";
+ }//]
 
     return EXIT_SUCCESS;
 }


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