in reply to Re: To make the Model WORK
in thread To make the Model WORK

25-year programmer showing graying roots. :) Real returned values might be '0', as well. That would fail.

I'm fortunate that, the way I've built this, now all I need to do is to 'flatten' the @item from IFTHENELSE into a one-dimensional array and then iterate. The first non-NIL result found will be returned, and I don't care which elsif or else clause gave it to me. Thanks to you and blokhead both, I see light illuminating repeated subrules. :D

Replies are listed 'Best First'.
Re^3: To make the Model WORK
by ikegami (Patriarch) on Jul 13, 2005 at 16:34 UTC
    Real returned values might be '0', as well. That would fail.

    Nope. '0' will not fail a production. Only undef.

    I stand corrected:

    use Parse::RecDescent; my $parser; $parser = Parse::RecDescent->new(q` test: { $return = 1 } `); print($parser->test('') ? 'ok' : 'fail', "\n"); # ok $parser = Parse::RecDescent->new(q` test: { $return = 0 } `); print($parser->test('') ? 'ok' : 'fail', "\n"); # fail $parser = Parse::RecDescent->new(q` test: { $return = '0' } `); print($parser->test('') ? 'ok' : 'fail', "\n"); # fail $parser = Parse::RecDescent->new(q` test: { $return = undef } `); print($parser->test('') ? 'ok' : 'fail', "\n"); # fail $parser = Parse::RecDescent->new(q` test: /\d+/ `); print($parser->test('1') ? 'ok' : 'fail', "\n"); # ok print($parser->test('0') ? 'ok' : 'fail', "\n"); # fail

    I never got into that situation, because I'd be returning
    [ ident   => ident ]
    or
    [ literal => literal ]
    or
    [ '*'     => expr, expr ]
    or
    [ '/'     => expr, expr ]
    or
    ...