This has been X-Posted to the "Higher Order Perl" discussion mailing list.

As we're using Parser.pm at my company (with the proper copyright notice, I might add) and I've started writing tests for it. Things have gone well until I encountered a case with &concatenate which doesn't match my expectations. Are my expectations wrong or is this a bug?

Below is a minimal test case demonstrating the problem. This assumes Stream.pm and Parser.pm are in the same directory as this script:

#!/usr/bin/perl use strict; use warnings; use lib '.'; use Stream qw/node list_to_stream/; use Parser ':all'; use Test::More 'no_plan'; my @tokens = ( node( OP => '+' ), node( VAR => 'x' ), node( VAL => 3 ) ); my $stream = list_to_stream(@tokens); my $parser = concatenate( lookfor('OP'), lookfor('VAR'), ); my ( $parsed, $remainder ) = $parser->($stream); is_deeply $parsed, [qw/+ x/], 'concatenate should return the parsed values'; is_deeply $remainder, [ VAL => 3 ], '... and the rest of the stream'; # the next test fails ... $parser = concatenate( lookfor('OP'), lookfor('VAR'), lookfor('VAL'), ); ( $parsed, $remainder ) = $parser->($stream); is_deeply $parsed, [qw/+ x 3/], 'concatenate should return the parsed values'; ok !defined $remainder, '... and the remaining stream should be empty';

When I try to concatenate just the first two tokens, everything is fine. However, the if I try and concatenate all of the tokens together, the parser fails to find a match.

I'm sure I can fix this, but I want to make sure this is really a bug and not me misunderstanding how this code is supposed to work. I seached the errata but couldn't find and example of this problem.

Cheers,
Ovid

New address of my CGI Course.


In reply to Testing the HOP Parser by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.