Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I don't get it, tokenizer/lexer works, but the parser doesn't ( no parse tree), what am I missing?

#!/usr/bin/perl -- use strict; use warnings; use HOP::Parser qw/:all/; use HOP::Lexer (); my @tokens = ( [ 'RO', qr/ro/i, ], [ 'SHAM', qr/sham/i, ], [ 'BO', qr/bo/i, ], #~ [ 'SPACE', qr/\s+/i, sub{()}], ); my $RoShamBo = star( alternate( lookfor('RO'), lookfor('SHAM'), lookfor('BO') ), ); my $entire_input = concatenate( $RoShamBo, \&End_of_Input, ); use Data::Dump qw/ dd pp /; my $lexer = HOP::Lexer::string_lexer( q{ RO SHAM BO }, @tokens ); print "tokenizer/lexer works\n"; while ( my $token = $lexer->() ) { dd $token; } print "\nbut parser doesn't work\n"; $lexer = HOP::Lexer::string_lexer( q{ RO SHAM BO }, @tokens ); if (my ($result, $remaining_input) = eval { $entire_input->($lexer) } +) { dd [ results => $result, remainder => $remaining_input ]; } else { print "Parse error. $@ ", pp($@), "\n"; } __END__ tokenizer/lexer works " " ["RO", "RO"] " " ["SHAM", "SHAM"] " " ["BO", "BO"] " " but parser doesn't work Parse error. ARRAY(0xa6b164) ["End of input", sub { ... }]

Replies are listed 'Best First'.