Dynamic parsers allow to adjust parsing according to conditions. Constructing dynamic parsers requires a condition argument and a body parser argument. Additional arguments are required by some parsers.
Functions or functors returning values convertable to bool can be used as conditions. When the evaluation of the function/functor yields true it will be considered as meeting the condition.
Parsers can be used as conditions, as well. When the parser matches the condition is met. Parsers used as conditions work in an all-or-nothing manner: the scanner will not be advanced when they don't match.
A failure to meet the condition will not result in a parse error.
if_p can be used with or without an else-part. The syntax is:
When the condition is met the then-parser is used next in the parsing process. When the condition is not met and an else-parser is available the else-parser is used next. When the condition isn't met and no else-parser is available then the whole parser matches the empty sequence. ( Note: older versions of if_p report a failure when the condition isn't met and no else-parser is available.)
while_p/do_p syntax is:
As long as the condition is met the dynamic parser constructed by while_p will try to match the body-parser. do_p returns a parser that tries to match the body-parser and then behaves just like the parser returned by while_p. A failure to match the body-parser will cause a failure to be reported by the while/do-parser.
uint_p[assign(sum)] >> while_p('+')[uint_p(add(sum)] '"' >> while_p(~eps_p('"'))[c_escape_ch_p[append(result)]] >> '"'
for_p requires four arguments. The syntax is:
for_p(init, condition, step)[body-parser]
init and step have to be 0-ary functions/functors. for_p returns a parser that will:
Copyright © 2002-2003 Joel de Guzman
Copyright © 2002-2003 Martin Wille
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)