From: Robin Edwards Date: Sun, 6 Dec 2009 16:39:15 +0000 (+0000) Subject: parser now works being passed from rule to rule X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e1c7220912f4498177648850a46c853eedf0146;p=p5sagit%2FDevel-Declare-Keyword.git parser now works being passed from rule to rule --- diff --git a/README b/README index 11493c6..c5b6355 100644 --- a/README +++ b/README @@ -1,6 +1,7 @@ TODO -* export keyword -* make operator keyword for moose +* create rule keyword +* figure out why the parser is loosing its position +* write builtin rules INFO rob: hey, we were talking about this @@ -21,8 +22,3 @@ INFO yes. I was hoping we vcould at least work out how to fake them in the process I have a long-term plan to let much of the Perl parser work in a recursive-descent manner also, for pedanticsness sake, wouldn't the signature be keyword method ( Name?, Proto?, Block ) , unless of course, you meant the example to do "method ( $foo, $bar, $baz ) mymethod { } " notation - -use Keyword; -keyword method ( Name?, Proto?, Block ) { -#block - }; diff --git a/examples/Method2.pm b/examples/Method2.pm index 07d4ea3..07038e8 100644 --- a/examples/Method2.pm +++ b/examples/Method2.pm @@ -3,12 +3,12 @@ use lib 'lib/'; use Keyword; use Data::Dumper; -keyword method (ident?, proto?, something) { - warn Dumper @_; +keyword method (ident?, proto?) { + warn "hello"; }; sub ident { - my $parser = ${shift()}; + my $parser = shift; if (my $len = $parser->scan_word(1)) { my $l = $parser->line; my $ident = substr($l, $parser->offset, $len); @@ -19,7 +19,7 @@ sub ident { } sub proto { - my $parser = ${shift()}; + my $parser = shift; my $l = $parser->line; if (substr($l, $parser->offset, 1) eq '(') { my $length = $parser->scan_string; @@ -31,9 +31,4 @@ sub proto { } } -sub something { - my $parser = ${shift()}; - warn "heyho"; -} - 1; diff --git a/lib/Keyword.pm b/lib/Keyword.pm index 0857fbd..38a9d8c 100644 --- a/lib/Keyword.pm +++ b/lib/Keyword.pm @@ -120,11 +120,9 @@ sub rule_to_parser { my $result; for my $r (@$rule) { - warn Dumper $r; - my $match = &{$r->{rule}}(\$parser); - warn "$r->{name} matched:\n$match\n"; - #die "failed to match rule $r->{name}" unless $matched or $r->{opt}; - #$result->{$r->{name}} = &{$r->{action}}($matched); #call rules action + my $match = &{$r->{rule}}($parser); + $parser->skip_ws; + die "failed to match rule $r->{name}" unless $match or $r->{opt}; } }; diff --git a/lib/Keyword/Parser.pm b/lib/Keyword/Parser.pm index 9ad1616..8f0bdb3 100644 --- a/lib/Keyword/Parser.pm +++ b/lib/Keyword/Parser.pm @@ -8,7 +8,7 @@ sub new { $self = {} unless $self; no strict 'refs'; $self->{offset} = \${caller()."::_PARSER_OFFSET"}; - ${$self->{offset}} = 0; + ${$self->{offset}} ||= 0; bless($self,__PACKAGE__); } diff --git a/t/02-keyword-method.t b/t/02-keyword-method.t index d46f2d2..78f439b 100644 --- a/t/02-keyword-method.t +++ b/t/02-keyword-method.t @@ -2,31 +2,15 @@ package Foobar; use strict; use warnings; use lib 'examples/'; -use KeywordMethod; -use Data::Dumper; - -method oki () { - return 1; -} +use Method2; -method plus ($a, $b) { - warn "$a + $b"; - return $a + $b; -} +method name ($a, $b, $c) { + warn "hello"; +}; -method new () { - return bless({}, __PACKAGE__); -} 1; use Test::More qw/no_plan/; use Data::Dumper; ok 1; - -my $s = Foobar->new; -ok($s); -ok($s->oki); -ok(1); -ok($s->plus(1,2) == 3); -ok(1);