|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74797 - in trunk/libs/spirit/repository: doc doc/qi example/qi test test/qi
From: joel_at_[hidden]
Date: 2011-10-08 07:32:06
Author: djowel
Date: 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
New Revision: 74797
URL: http://svn.boost.org/trac/boost/changeset/74797
Log:
seek directive by TONGARI
Added:
trunk/libs/spirit/repository/doc/qi/seek.qbk (contents, props changed)
trunk/libs/spirit/repository/example/qi/seek.cpp (contents, props changed)
trunk/libs/spirit/repository/test/qi/seek.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/repository/doc/qi/directives.qbk | 1
trunk/libs/spirit/repository/doc/spirit2_repository.qbk | 45 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/spirit/repository/example/qi/Jamfile | 1
trunk/libs/spirit/repository/test/Jamfile | 1
4 files changed, 48 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/repository/doc/qi/directives.qbk
==============================================================================
--- trunk/libs/spirit/repository/doc/qi/directives.qbk (original)
+++ trunk/libs/spirit/repository/doc/qi/directives.qbk 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -10,4 +10,5 @@
[include confix.qbk]
[include distinct.qbk]
[include kwd.qbk]
+[include seek.qbk]
[endsect]
Added: trunk/libs/spirit/repository/doc/qi/seek.qbk
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/doc/qi/seek.qbk 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,98 @@
+[/==============================================================================
+ Copyright (C) 2001-2011 Joel de Guzman
+ Copyright (C) 2001-2011 Hartmut Kaiser
+ Copyright (C) 2011 Jamboree
+
+ 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:seek Qi Seek Parser Directive ]
+
+[heading Description]
+
+The `seek[]` parser-directive skips all input until the subject parser matches.
+On failure, the current position is the end of the input.
+
+[heading Header]
+
+ // forwards to <boost/spirit/repository/home/qi/directive/seek.hpp>
+ #include <boost/spirit/repository/include/qi_seek.hpp>
+
+Also, see __include_structure__.
+
+[heading Namespace]
+
+[table
+ [[Name]]
+ [[`boost::spirit::repository::qi::seek`]]
+]
+
+[heading Model of]
+
+[:__unary_parser_concept__]
+
+[variablelist Notation
+ [[`a`] [A __parser_concept__.]]
+]
+
+[heading Expression Semantics]
+
+Semantics of an expression is defined only where it differs from, or is
+not defined in __unary_parser_concept__.
+
+[table
+ [[Expression] [Semantics]]
+ [[`seek[a]`] [Advances until the parser `a` matches.]]
+]
+
+[heading Attributes]
+
+See __qi_comp_attr_notation__.
+
+[table
+ [[Expression] [Attribute]]
+ [[`seek[a]`]
+[``a: A --> seek[a]: A
+a: Unused --> seek[a]: Unused``]]
+]
+
+[heading Complexity]
+
+[:The complexity is defined by the complexity of the subject parser, `a`]
+
+[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 `'#'`.
+(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:
+
+[reference_qi_seek_vars]
+
+Parsing and showing the result:
+
+[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]
Modified: trunk/libs/spirit/repository/doc/spirit2_repository.qbk
==============================================================================
--- trunk/libs/spirit/repository/doc/spirit2_repository.qbk (original)
+++ trunk/libs/spirit/repository/doc/spirit2_repository.qbk 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -55,6 +55,51 @@
[def __caution__ [$images/caution.png]]
[def __danger__ [$images/alert.png]]
+[/ ----------------------------------------------------------------------------]
+[/ $$$ Refer to spirit2.qbk $$$]
+
+[/ References to abstracts ]
+
+[def __include_structure__ [@../../../doc/html/spirit/structure/include.html Include Structure]]
+
+[/ quick-ref]
+[def __qi_comp_attr_notation__ [@../../../doc/html/spirit/qi/quick_reference/compound_attribute_rules.html#spirit.qi.quick_reference.compound_attribute_rules.notation Compound Attribute Notation]]
+
+[/ concepts]
+[def __parser_concept__ [@../../../doc/html/spirit/qi/reference/parser_concepts/parser.html `Parser`]]
+[def __primitive_parser_concept__ [@../../../doc/html/spirit/qi/reference/parser_concepts/primitiveparser.html `PrimitiveParser`]]
+[def __unary_parser_concept__ [@../../../doc/html/spirit/qi/reference/parser_concepts/unaryparser.html `UnaryParser`]]
+[def __binary_parser_concept__ [@../../../doc/html/spirit/qi/reference/parser_concepts/binaryparser.html `BinaryParser`]]
+[def __nary_parser_concept__ [@../../../doc/html/spirit/qi/reference/parser_concepts/naryparser.html `NaryParser`]]
+[def __qi_nonterminal__ [@../../../doc/html/spirit/qi/reference/parser_concepts/nonterminal.html `Nonterminal`]]
+[def __qi_nonterminal_attribute__ [@../../../doc/html/spirit/qi/reference/parser_concepts/nonterminal.html#spirit.qi.reference.parser_concepts.nonterminal.attributes `Attribute`]]
+
+[/ basics]
+[def __qi_lazy_argument__ [@../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.lazy_argument Lazy Argument]]
+[def __qi_lazy_arguments__ [@../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.lazy_argument Lazy Arguments]]
+[def __char_encoding_namespace__ [@../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.character_encoding_namespace Character Encoding Namespace]]
+[def __string__ [@../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.string String]]
+[def __qi_basics_examples__ [@../../../doc/html/spirit/qi/reference/basics.html#spirit.qi.reference.basics.examples Basics Examples]]
+
+[/ quick-ref]
+[def __karma_comp_attr_notation__ [@../../../doc/html/spirit/karma/quick_reference/compound_attribute_rules.html#spirit.karma.quick_reference.compound_attribute_rules.notation Compound Attribute Notation]]
+
+[/ concepts]
+[def __generator_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/generator.html `Generator`]]
+[def __primitive_generator_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/primitivegenerator.html `PrimitiveGenerator`]]
+[def __unary_generator_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/unarygenerator.html `UnaryGenerator`]]
+[def __binary_generator_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/binarygenerator.html `BinaryGenerator`]]
+[def __nary_generator_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/narygenerator.html `NaryGenerator`]]
+[def __karma_nonterminal_concept__ [@../../../doc/html/spirit/karma/reference/generator_concepts/nonterminal.html `Nonterminal`]]
+[def __karma_nonterminal_attribute__ [@../../../doc/html/spirit/karma/reference/generator_concepts/nonterminal.html#spirit.karma.reference.generator_concepts.nonterminal.attributes `Attribute`]]
+
+[/ basics]
+[def __karma_lazy_argument__ [@../../../doc/html/spirit/karma/reference/basics.html#spirit.karma.reference.basics.lazy_argument Lazy Argument]]
+[def __karma_lazy_arguments__ [@../../../doc/html/spirit/karma/reference/basics.html#spirit.karma.reference.basics.lazy_argument Lazy Arguments]]
+[def __karma_basics_examples__ [@../../../doc/html/spirit/karma/reference/basics.html#spirit.karma.reference.basics.examples Basics Examples]]
+
+[/ ----------------------------------------------------------------------------]
+
[/ Here we go ]
[include preface.qbk]
Modified: trunk/libs/spirit/repository/example/qi/Jamfile
==============================================================================
--- trunk/libs/spirit/repository/example/qi/Jamfile (original)
+++ trunk/libs/spirit/repository/example/qi/Jamfile 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -21,3 +21,4 @@
exe keywords : keywords.cpp ;
exe derived : derived.cpp ;
exe options : options.cpp ;
+exe seek : seek.cpp ;
Added: trunk/libs/spirit/repository/example/qi/seek.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/example/qi/seek.cpp 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,56 @@
+/*//////////////////////////////////////////////////////////////////////////////
+ Copyright (c) 2011 Jamboree
+
+ 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)
+//////////////////////////////////////////////////////////////////////////////*/
+
+// [ Jamboree May 3, 2011 ] first ver.
+// [ Jamboree Aug 13, 2011 ] minor change.
+
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/karma.hpp>
+#include <boost/spirit/repository/include/qi_seek.hpp>
+
+
+int main(int argc, char *argv[])
+{
+ //[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
+ 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";
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
Modified: trunk/libs/spirit/repository/test/Jamfile
==============================================================================
--- trunk/libs/spirit/repository/test/Jamfile (original)
+++ trunk/libs/spirit/repository/test/Jamfile 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -27,6 +27,7 @@
[ run qi/distinct.cpp : : : : qi_repo_distinct ]
[ run qi/subrule.cpp : : : : qi_repo_subrule ]
[ run qi/keywords.cpp : : : : qi_repo_keywords ]
+ [ run qi/seek.cpp : : : : qi_repo_seek ]
# run Karma repository tests
[ run karma/confix.cpp : : : : karma_repo_confix ]
Added: trunk/libs/spirit/repository/test/qi/seek.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/test/qi/seek.cpp 2011-10-08 07:32:05 EDT (Sat, 08 Oct 2011)
@@ -0,0 +1,101 @@
+/*//////////////////////////////////////////////////////////////////////////////
+ Copyright (c) 2011 Jamboree
+
+ 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)
+//////////////////////////////////////////////////////////////////////////////*/
+
+
+#include <vector>
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi_parse.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_string.hpp>
+#include <boost/spirit/include/qi_int.hpp>
+#include <boost/spirit/include/qi_sequence.hpp>
+#include <boost/spirit/include/qi_plus.hpp>
+#include <boost/spirit/include/qi_eoi.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <boost/spirit/repository/include/qi_seek.hpp>
+
+#include "test.hpp"
+
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace spirit_test;
+ namespace qi = boost::spirit::qi;
+ namespace phx = boost::phoenix;
+ using boost::spirit::repository::qi::seek;
+ using boost::spirit::standard::space;
+
+ // test eoi
+ {
+ using qi::eoi;
+
+ BOOST_TEST(test("", seek[eoi]));
+ BOOST_TEST(test(" ", seek[eoi], space));
+ BOOST_TEST(test("a", seek[eoi]));
+ BOOST_TEST(test(" a", seek[eoi], space));
+ }
+
+ // test literal finding
+ {
+ using qi::int_;
+ using qi::char_;
+
+ int i = 0;
+
+ BOOST_TEST(
+ test_attr("!@#$%^&*KEY:123", seek["KEY:"] >> int_, i)
+ && i == 123
+ );
+ }
+
+ // test sequence finding
+ {
+ using qi::int_;
+ using qi::lit;
+
+ int i = 0;
+
+ BOOST_TEST(
+ test_attr("!@#$%^&* KEY : 123", seek[lit("KEY") >> ':'] >> int_, i, space)
+ && i == 123
+ );
+ }
+
+ // test attr finding
+ {
+ using qi::int_;
+
+ std::vector<int> v;
+
+ BOOST_TEST( // expect partial match
+ test_attr("a06b78c3d", +seek[int_], v, false)
+ && v[0] == 6 && v[1] == 78 && v[2] == 3
+ );
+ }
+
+ // test action
+ {
+ using phx::ref;
+
+ bool b = false;
+
+ BOOST_TEST( // expect partial match
+ test("abcdefg", seek["def"][ref(b) = true], false)
+ && b
+ );
+ }
+
+ return boost::report_errors();
+}
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