Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

simple HOP::Parser usage

by Anonymous Monk
on Mar 29, 2012 at 10:04 UTC ( [id://962332]=perlquestion: print w/replies, xml ) Need Help??

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'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://962332]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found