* and go through perl's -existing- keywords print $fh "sddfsd". $f, $c etc
* look at ... metalua ... and common lisp reader macros.
-* use carp
* remove globals
* write pod for Keyword::Declare
package Keyword;
use strict;
use warnings;
+use Carp;
use Devel::Declare;
use B::Hooks::EndOfScope;
use Data::Dumper;
#strip out the name of new keyword
my $keyword = parse_ident($kd) or
- die "expecting identifier for keyword near:\n".$kd->line;
+ croak "expecting identifier for keyword near:\n".$kd->line;
$kd->skip_ws;
#extract the prototype
my $proto = parse_proto($kd) or
- die "expecting prototype for keyword at:\n".$kd->line;
+ croak "expecting prototype for keyword at:\n".$kd->line;
my $parser = Keyword::Parser->new({proto=>$proto, module=>$KW_MODULE});
#strip out the name of parse routine
my $name = parse_ident($kd) or
- die "expecting identifier for parse near:\n".$kd->line;
+ croak "expecting identifier for parse near:\n".$kd->line;
$kd->skip_ws;
my $proto = parse_proto($kd) or
- die "expecting prototype for parse at:\n".$kd->line;
+ croak "expecting prototype for parse at:\n".$kd->line;
$kd->skip_ws;
my $l = $kd->line;
#strip out the name of action
my $name = parse_ident($kd) or
- die "expecting identifier for action near:\n".$kd->line;
+ croak "expecting identifier for action near:\n".$kd->line;
$kd->skip_ws;
my $proto = parse_proto($kd) or
- die "expecting prototype for action at:\n".$kd->line;
+ croak "expecting prototype for action at:\n".$kd->line;
$kd->skip_ws;
my $l = $kd->line;
package Keyword::Parser;
use strict;
use warnings;
+use Carp;
use Keyword::Declare;
our %BUILTIN = (
sub new {
my ($class, $self) = @_;
- $self->{proto} or die 'no proto provided';
- $self->{module} or die 'no module provided';
+ $self->{proto} or croak 'no proto provided';
+ $self->{module} or croak 'no module provided';
bless($self,$class);
}
my ($self, $pa) = @_;
my $match = &{$pa->{parse}}($self->declare);
$self->declare->skip_ws;
- die "failed to parse $pa->{name}" unless $match or $pa->{opt};
+ croak "failed to parse $pa->{name}" unless $match or $pa->{opt};
return &{$pa->{action}}($match);
}
my @i = split /\,/, $self->{proto};
for my $ident (@i){
$ident =~ /^[a-z]{1}\w+[\?]?$/i or
- die "bad identifier '$ident' in prototype.";
+ croak "bad identifier '$ident' in prototype.";
my $opt;
$ident =~ s/\?//g and $opt = 1 if $ident =~ /\?$/;
push @{$self->{plist}}, {name=>lc($ident),optional=>$opt};