|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2008-02-05 11:26:42
Thorsten Ottosen wrote:
> I'm trying to build a parser, this time with boost.xpressive instead of
> using boost.spirit.
>
> In spirit I have this function that displays when parsing failed:
<snip>
> Can I get the same info with xpressive somehow?
Not directly, no. One possibility is to define an iterator adaptor that
keeps track of the farthest position to which it's incremented. You can
then use that iterator with xpressive and find out how much of the
string gets eaten before the match fails.
Another possibility is to insert into your grammar strategically placed
actions that throw the current position on parse failures. Something
like ...
// untested!
struct parse_failure : std::exception
{
parse_failure(std::string::const_iterator pos)
{ ... }
};
sregex ARule = this | that
// this executes on parse failure
| nil [ throw_<parse_failure>(second(_)) ];
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk