Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13080 closed Bugs (invalid)

Boost Xpressive ignores capture placeholders

Reported by: Evgeny Yashin <johny5.coder@…> Owned by: Eric Niebler
Milestone: To Be Determined Component: xpressive
Version: Boost 1.62.0 Severity: Showstopper
Keywords: Cc:

Description

This code:

#include "boost/xpressive/xpressive.hpp"

int main()
{
	using namespace boost::xpressive;

	cregex scheme = (s1 = +_w) >> "://";
	cregex host_ipv6 = (s2 = ('[' >> +(xdigit | ':') >> ']'));
	cregex uri_re = scheme >> host_ipv6;

	cmatch m;
	if( regex_match( "http://[fe::]", m, uri_re ) )
	{
		//	[first, last) pair of iterators, with implicit operator string()
		std::string protocol = m[1];
		protocol = protocol;
	}

    return 0;
}

It runs and it matches but protocol will contain empty string. Visual Studio 2015, in debug/release, 32/64bit.

Change History (4)

comment:1 by Eric Niebler, 5 years ago

Resolution: invalid
Status: newclosed

After the match, m has no sub_matches. It does, however, have nested results that correspond to the nested regexes in uri_re. Please read [^1] for more information.

[^1]: http://www.boost.org/doc/libs/1_64_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.grammars_and_nested_matches.nested_regexes_and_sub_match_scoping

comment:2 by Evgeny Yashin <johny5.coder@…>, 5 years ago

Thank you, overlooked indeed. A bit unexpected though.

Any way to flatten the matching results? Breaking into set of regexps, here, should be considered as simplifying final expression for human reading, not declaring any recursive grammars.

comment:3 by Evgeny Yashin <johny5.coder@…>, 5 years ago

Addition, I see that iterating through tree gives the flatten view over nested results, I am mostly about keeping original index based syntax, where s1= .. match will be accessed via m[1] index later on.

comment:4 by Eric Niebler, 5 years ago

It can't. There could be a 0th submatch in two nested regexes. They would stomp each other. The nested_results keeps them separate.

Note: See TracTickets for help on using tickets.