diff options
author | Akim Demaille <akim@lrde.epita.fr> | 2013-09-19 15:20:22 +0200 |
---|---|---|
committer | Akim Demaille <akim@lrde.epita.fr> | 2013-09-19 15:57:59 +0200 |
commit | b51cf830a6cb513ca8e357321307997672d6d6b0 (patch) | |
tree | c124ed53182fefb5b9f01e3d1d361fa175d4be7d | |
parent | 66b03e134fd851db9de1f57f8fe110799375234e (diff) | |
download | bison-b51cf830a6cb513ca8e357321307997672d6d6b0.tar.gz |
examples: improve the output of the "variant" example
* examples/variant.yy: Improve the printing of lists.
-rw-r--r-- | examples/variant.yy | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/variant.yy b/examples/variant.yy index 9413cbcf..fd551cc1 100644 --- a/examples/variant.yy +++ b/examples/variant.yy @@ -16,7 +16,7 @@ */ %debug -%skeleton "lalr1.cc" +%language "c++" %defines %define api.token.constructor %define api.value.type variant @@ -48,11 +48,17 @@ typedef std::list<std::string> strings_type; namespace std { std::ostream& - operator<< (std::ostream& o, const strings_type& s) + operator<< (std::ostream& o, const strings_type& ss) { - std::copy (s.begin (), s.end (), - std::ostream_iterator<strings_type::value_type> (o, "\n")); - return o; + o << "(" << &ss << ") {"; + const char *sep = ""; + for (strings_type::const_iterator i = ss.begin(), end = ss.end(); + i != end; ++i) + { + o << sep << *i; + sep = ", "; + } + return o << "}"; } } |