Boost logo

Boost :

From: Bjørn Roald (bjorn_at_[hidden])
Date: 2006-01-04 18:33:55


On Tuesday 03 January 2006 23:42, Bjørn Roald wrote:
> On Tuesday 03 January 2006 23:19, Eric Niebler wrote:

> > If you do,
> > please post code that reproduces the error and I'll fix it. Even if the
> > recent changes fixed your problem, if you send the code anyway, I'll add
> > it to xpressive's regression test. (Hint: you should do this.)
>
> I will post cleaned up code tomorrow. At least if problem does not go
> away. Thanks.

I had no joy with updating my cvs working area today :-(
--- see seperate post.

Until I get the latest cvs tested I post the source which I cleaned up
somewhat, in case you want to use it:

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive.hpp>

using namespace boost::xpressive;

// Displays nested results to std::cout
struct output_nested_results
{
    int tabs_;

    output_nested_results( int tabs = 0 )
        : tabs_( tabs )
    {
    }

    template< typename BidiIterT >
    void operator ()( match_results< BidiIterT > const &what ) const
    {
        // output the match
        std::cout << what[0] << '\n'; // comment out this and it works

        // output any nested matches
        std::for_each(
            what.nested_results().begin(),
            what.nested_results().end(),
            output_nested_results( tabs_ + 1 ) );
    }
};

int main()
{
    sregex line_comment = "//" >> -*_ >> _n;
    sregex scoped_block;
    scoped_block = as_xpr('{')
>> *( keep( +~(set='{','}') ) | by_ref(scoped_block) )
>> '}';
    sregex boost_namespace_begin = as_xpr( "namespace" )
>> +space >> "boost"
>> +space >> '{';
    sregex boost_namespace_body = *(
        line_comment | // comment out this and it works
        scoped_block |
        space |
        *( keep( +~( set='{', '}' ) ) ) );
    sregex boost_namespace_end = as_xpr( '}' );
    sregex boost_namespace = boost_namespace_begin >> *space >>
                             boost_namespace_body >> *space >>
                             boost_namespace_end ;

    smatch what;
    std::string str = "#include <boost/xxxx.hpp>\n"
                      "namespace boost {\n"
                      "gruble \"grot}..\" .. {dfgdg(){aa} fddd
\"dffdfd\\\"dfdfgg\"}{bb}"
                      "}\n";

    if( regex_search( str, what, boost_namespace ) )
    {
        // display the whole match
        std::cout << what[0] << '\n'; // can be removed, but only prints
first line ???

        // display the nested results
        std::for_each(
            what.nested_results().begin(),
            what.nested_results().end(),
            output_nested_results() );
    }
}

I put comments on 3 lines which seem to effect the result negatively. My
program output is:

namespace boost {
namespace boost {
/bin/bash: line 1: 11082 Segmentation fault bin/gcc/debug/test_bug

regards,
bjorn


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk