TODO
-* export keyword
-* make operator keyword for moose
+* create rule keyword
+* figure out why the parser is loosing its position
+* write builtin rules
INFO
<mst> rob: hey, we were talking about this
<mst> yes. I was hoping we vcould at least work out how to fake them in the process
<Zefram> I have a long-term plan to let much of the Perl parser work in a recursive-descent manner
<kentnl> 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
- };
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);
}
sub proto {
- my $parser = ${shift()};
+ my $parser = shift;
my $l = $parser->line;
if (substr($l, $parser->offset, 1) eq '(') {
my $length = $parser->scan_string;
}
}
-sub something {
- my $parser = ${shift()};
- warn "heyho";
-}
-
1;
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};
}
};
$self = {} unless $self;
no strict 'refs';
$self->{offset} = \${caller()."::_PARSER_OFFSET"};
- ${$self->{offset}} = 0;
+ ${$self->{offset}} ||= 0;
bless($self,__PACKAGE__);
}
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);