|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63892 - in trunk/libs/spirit: doc doc/karma example/karma test test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2010-07-11 15:41:54
Author: hkaiser
Date: 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
New Revision: 63892
URL: http://svn.boost.org/trac/boost/changeset/63892
Log:
Spirit: added karma::duplicate[] directive, tests and docs
Added:
trunk/libs/spirit/test/karma/duplicate.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/doc/karma/directive.qbk | 91 +++++++++++++++++++++++++++++++++++++++
trunk/libs/spirit/doc/karma/quick_reference.qbk | 3 +
trunk/libs/spirit/doc/spirit2.qbk | 1
trunk/libs/spirit/doc/what_s_new.qbk | 2
trunk/libs/spirit/example/karma/reference.cpp | 13 +++++
trunk/libs/spirit/test/Jamfile | 1
6 files changed, 109 insertions(+), 2 deletions(-)
Modified: trunk/libs/spirit/doc/karma/directive.qbk
==============================================================================
--- trunk/libs/spirit/doc/karma/directive.qbk (original)
+++ trunk/libs/spirit/doc/karma/directive.qbk 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -13,7 +13,8 @@
(`repeat[]`), directives controlling automatic delimiting (`verbatim[]`,
`no_delimit[]`, and `delimit[]`), controlling case sensitivity (`upper[]` and
`lower[]`), field width (`maxwidth[]`), buffering (`buffer[]`), splitting into
-columns (`columns[]`) and attribute handling (`omit[]` and `skip[]`).
+columns (`columns[]`) and attribute handling (`duplicate[]`, `omit[]`, and
+`skip[]`).
[heading Module Header]
@@ -890,7 +891,7 @@
embedded generator without generating any output. The `omit[]` directive
will still execute the embedded generator while discarding the generated output
afterwards. The `skip[]` directive will not execute the embedded generator, but
-will use it onlz to extract the exposed attribute type.
+will use it only to extract the exposed attribute type.
[heading Header]
@@ -1009,6 +1010,92 @@
[endsect] [/ omit]
[/////////////////////////////////////////////////////////////////////////////]
+[section:duplicate Duplicate Attribute (`duplicate[]`)]
+
+[heading Description]
+
+The directive `duplicate[]` duplicates its attribute to all elements of the
+embedded generator if this is a sequence generator. Otherwise it does nothing.
+
+[heading Header]
+
+ // forwards to <boost/spirit/home/karma/directive/duplicate.hpp>
+ #include <boost/spirit/include/karma_duplicate.hpp>
+
+Also, see __include_structure__.
+
+[table
+ [[Name]]
+ [[`boost::spirit::duplicate // alias: boost::spirit::karma::duplicate` ]]
+]
+
+[heading Model of]
+
+[:__unary_generator_concept__]
+
+[variablelist Notation
+ [[`a`] [A generator object]]
+ [[`A`] [Attribute type of generator `a`]]]
+
+[heading Expression Semantics]
+
+Semantics of an expression is defined only where it differs from, or is not
+defined in __unary_generator_concept__.
+
+[table
+ [[Expression] [Semantics]]
+ [[`duplicate[a]`] [The `duplicate` directive duplicates the supplied
+ attribute for all elements of a embedded sequence
+ generator. For all other types of embedded generators
+ it has no effect. It succeeds as long as its embedded
+ generator does not fail.]]
+]
+
+[heading Attributes]
+
+See __karma_comp_attr_notation__.
+
+[table
+ [[Expression] [Attribute]]
+ [[`duplicate[a]`]
+[``a: A --> duplicate[a]: A
+a: tuple<A, A, ...> --> duplicate[a]: A
+a: Unused --> duplicate[a]: Unused``]]
+]
+
+If the embedded generator of the `duplicate[]` directive is a sequence it is
+expected that all elements of this sequence expose either the same attribute
+type, an compatible attribute type, or `unused`. In this case, the
+`duplicate[]` directive exposes the attribute type of its first element. The
+behavior of the `duplicate[]` directive is undefined if the elements of an
+embedded sequence do not expose the same attributes. Most likely, the
+corresponding expression will not compile.
+
+[heading Complexity]
+
+[:The overall complexity of the `duplicate[]` directive depends on the complexity
+ of the embedded generator.]
+
+[heading Example]
+
+[note The test harness for the example(s) below is presented in the
+ __karma_basics_examples__ section.]
+
+Some includes:
+
+[reference_karma_includes]
+
+Some using declarations:
+
+[reference_karma_using_declarations_duplicate]
+
+Basic usage of the `duplicate` generators:
+
+[reference_karma_duplicate]
+
+[endsect] [/ duplicate]
+
+[/////////////////////////////////////////////////////////////////////////////]
[section:columns Separate Output Into Columns (`columns[]`)]
[heading Description]
Modified: trunk/libs/spirit/doc/karma/quick_reference.qbk
==============================================================================
--- trunk/libs/spirit/doc/karma/quick_reference.qbk (original)
+++ trunk/libs/spirit/doc/karma/quick_reference.qbk 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -443,6 +443,9 @@
[[__karma_skip__`[a]`] [`A`] [Consume the attribute type of `a` without generating anything.
The embedded generator will never be executed.]]
+ [[__karma_duplicate__`[a]`] [`A`] [The supplied attribute will be duplicated and passed unchanged to
+ all embedded elements of a sequence.]]
+
[[__karma_buffer__`[a]`][`A`] [Temporarily intercept the output generated by `a`,
flushing it only after `a` succeeded]]
Modified: trunk/libs/spirit/doc/spirit2.qbk
==============================================================================
--- trunk/libs/spirit/doc/spirit2.qbk (original)
+++ trunk/libs/spirit/doc/spirit2.qbk 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -181,6 +181,7 @@
[template karma_align[str] [link spirit.karma.reference.directive.alignment [str]]]
[def __karma_omit__ [link spirit.karma.reference.directive.omit `omit`]]
[def __karma_skip__ [link spirit.karma.reference.directive.omit `skip`]]
+[def __karma_duplicate__ [link spirit.karma.reference.directive.duplicate `duplicate`]]
[def __karma_buffer__ [link spirit.karma.reference.directive.buffer `buffer`]]
[template karma_repeat[str] [link spirit.karma.reference.directive.repeat [str]]]
[def __karma_verbatim__ [link spirit.karma.reference.directive.delimit `verbatim`]]
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 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -38,6 +38,8 @@
* Added strict mode to __karma__, leaving the current behavior (unchanged) as
relaxed mode. Added __karma__ compile time directives `strict[]` and
`relaxed[]` allowing to switch between the two.
+* Added __karma__ __karma_duplicate__ directive which duplicates the supplied
+ attribute to all elements of an embedded generator sequence.
[heading Bug Fixes]
Modified: trunk/libs/spirit/example/karma/reference.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/reference.cpp (original)
+++ trunk/libs/spirit/example/karma/reference.cpp 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -466,6 +466,19 @@
}
{
+ //[reference_karma_using_declarations_duplicate
+ using boost::spirit::karma::double_;
+ using boost::spirit::karma::duplicate;
+ using boost::spirit::karma::space;
+ //]
+
+ //[reference_karma_duplicate
+ test_generator_attr("2.02.0", duplicate[double_ << double_], 2.0);
+ test_generator_attr_delim("2.0 2.0 ", duplicate[double_ << double_], space, 2.0);
+ //]
+ }
+
+ {
//[reference_karma_using_declarations_columns
using boost::spirit::karma::double_;
using boost::spirit::karma::columns;
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -89,6 +89,7 @@
[ run karma/columns.cpp : : : : ]
[ run karma/debug.cpp : : : : karma_debug ]
[ run karma/delimiter.cpp : : : : ]
+ [ run karma/duplicate.cpp : : : : ]
[ run karma/encoding.cpp : : : : karma_encoding ]
[ run karma/eol.cpp : : : : karma_eol ]
[ run karma/eps.cpp : : : : karma_eps ]
Added: trunk/libs/spirit/test/karma/duplicate.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/duplicate.cpp 2010-07-11 15:41:53 EDT (Sun, 11 Jul 2010)
@@ -0,0 +1,48 @@
+// Copyright (c) 2001-2010 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)
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+using namespace spirit_test;
+
+int main()
+{
+ using boost::spirit::karma::double_;
+ using boost::spirit::karma::space;
+ using boost::spirit::karma::duplicate;
+
+ // test for sequences
+ {
+ BOOST_TEST(test("2.02.0", duplicate[double_ << double_], 2.0));
+ BOOST_TEST(test_delimited("2.0 2.0 ",
+ duplicate[double_ << double_], 2.0, space));
+ BOOST_TEST(test("2.02.02.0",
+ duplicate[double_ << double_ << double_], 2.0));
+ BOOST_TEST(test_delimited("2.0 2.0 2.0 ",
+ duplicate[double_ << double_ << double_], 2.0, space));
+ }
+
+ // test for non-sequences
+ {
+ BOOST_TEST(test("2.02.0", duplicate["2.0" << double_], 2.0));
+ BOOST_TEST(test_delimited("2.0 2.0 ",
+ duplicate["2.0" << double_], 2.0, space));
+ }
+
+ // test for subjects exposing no attribute
+ {
+ BOOST_TEST(test("2.02.0", duplicate["2.0"] << double_, 2.0));
+ BOOST_TEST(test_delimited("2.0 2.0 ",
+ duplicate["2.0"] << double_, 2.0, space));
+ }
+
+ 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