From: Robin Edwards Date: Mon, 14 Dec 2009 10:40:09 +0000 (+0000) Subject: renamed parse routines X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=126fad4460337d9afaf61fe0f588a85a68a63449;p=p5sagit%2FDevel-Declare-Keyword.git renamed parse routines --- diff --git a/Changes b/Changes index 863998a..2a33607 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Keyword. +0.03 Mon Dec 14 10:37:23 GMT 2009 + added action keyword update tests + 0.02 Fri Dec 11 19:44:56 2009 added parse keyword diff --git a/lib/Keyword.pm b/lib/Keyword.pm index a176e46..ca08ea2 100644 --- a/lib/Keyword.pm +++ b/lib/Keyword.pm @@ -6,15 +6,16 @@ use Devel::Declare; use B::Hooks::EndOfScope; use Data::Dumper; use Keyword::Parser; -use Keyword::Parse::Ident; -use Keyword::Parse::Proto; use Keyword::Parse::Block; +use Keyword::Parse::Proto; +use Keyword::Parse::Ident; -our $VERSION = '0.02'; +our $VERSION = '0.03'; our $KW_MODULE = caller; #setup parser for keyword syntax sub import { + Devel::Declare->setup_for( $KW_MODULE, { keyword => { const => \&keyword_parser }, @@ -41,13 +42,13 @@ sub keyword_parser { $parser->skip_ws; #strip out the name of new keyword - my $keyword = Keyword::Parse::Ident::match($parser) or + my $keyword = Keyword::Parse::Ident::parse_ident($parser) or die "expecting identifier for keyword near:\n".$parser->line; $parser->skip_ws; #extract the prototype - my $proto = Keyword::Parse::Proto::match($parser) or + my $proto = Keyword::Parse::Proto::parse_proto($parser) or die "expecting prototype for keyword at:\n".$parser->line; #produce list of parse routines and there actions from prototype @@ -76,11 +77,11 @@ sub parse_parser { $parser->skip_ws; #strip out the name of parse routine - my $name = Keyword::Parse::Ident::match($parser) or + my $name = Keyword::Parse::Ident::parse_ident($parser) or die "expecting identifier for parse near:\n".$parser->line; $parser->skip_ws; - my $proto = Keyword::Parse::Proto::match($parser) or + my $proto = Keyword::Parse::Proto::parse_proto($parser) or die "expecting prototype for parse at:\n".$parser->line; $parser->skip_ws; @@ -90,11 +91,11 @@ sub parse_parser { substr($l, $parser->offset+1, 0) = $code; $parser->line($l); - no strict 'refs'; - no warnings 'redefine'; - *{$KW_MODULE.'::parse'} = sub (&) { - *{$parser->package."::parse_$name"} = shift; - }; + $parser->shadow("$KW_MODULE\::parse", sub (&) { + no strict 'refs'; + *{$KW_MODULE."::parse_$name"} = shift; + }); + } # parses the action keyword @@ -104,11 +105,11 @@ sub action_parser { $parser->skip_ws; #strip out the name of action - my $name = Keyword::Parse::Ident::match($parser) or + my $name = Keyword::Parse::Ident::parse_ident($parser) or die "expecting identifier for action near:\n".$parser->line; $parser->skip_ws; - my $proto = Keyword::Parse::Proto::match($parser) or + my $proto = Keyword::Parse::Proto::parse_proto($parser) or die "expecting prototype for action at:\n".$parser->line; $parser->skip_ws; @@ -171,14 +172,14 @@ sub proto_to_parselist { #builtin case 'ident' { push @pa, - {name=>$ident, parse=>\&{'Keyword::Parse::Ident::match'}, + {name=>$ident, parse=>\&{'Keyword::Parse::Ident::parse_ident'}, action=>\&{$KW_MODULE."::action_ident"}, opt=>$opt, builtin=>1} } case 'proto' { push @pa, - {name=>$ident, parse=>\&{'Keyword::Parse::Proto::match'}, + {name=>$ident, parse=>\&{'Keyword::Parse::Proto::parse_proto'}, action=>\&{$KW_MODULE."::action_proto"}, opt=>$opt, builtin=>1} } diff --git a/lib/Keyword/Parse/Ident.pm b/lib/Keyword/Parse/Ident.pm index 6b68f7f..54c2e61 100644 --- a/lib/Keyword/Parse/Ident.pm +++ b/lib/Keyword/Parse/Ident.pm @@ -1,8 +1,6 @@ package Keyword::Parse::Ident; -use strict; -use warnings; -sub match { +sub parse_ident { my $parser = shift; if (my $len = $parser->scan_word(1)) { my $l = $parser->line; diff --git a/lib/Keyword/Parse/Proto.pm b/lib/Keyword/Parse/Proto.pm index 3e76554..226ce9e 100644 --- a/lib/Keyword/Parse/Proto.pm +++ b/lib/Keyword/Parse/Proto.pm @@ -1,8 +1,6 @@ package Keyword::Parse::Proto; -use strict; -use warnings; -sub match { +sub parse_proto { my $parser = shift; my $l = $parser->line; if (substr($l, $parser->offset, 1) eq '(') {