1 package Filter::Keyword::Parser;
4 has reader => (is => 'ro', required => 1);
6 has re_add => (is => 'ro', required => 1);
8 has keywords => (is => 'ro', default => sub { [] });
11 push @{$_[0]->keywords}, $_[1];
14 my ($self, $keyword) = @_;
15 my $keywords = $self->keywords;
16 for my $idx (0 .. $#$keywords) {
17 if ($keywords->[$idx] eq $keyword) {
18 splice @$keywords, $idx, 1;
24 has current_match => (is => 'rw');
26 has short_circuit => (is => 'rw');
28 has code => (is => 'rw', default => sub { '' });
32 if ($self->short_circuit) {
33 $self->short_circuit(0);
34 $self->${\$self->re_add};
37 for my $keyword (@{$self->keywords}) {
38 if ($keyword->have_match) {
39 $keyword->clear_globref;
40 return $keyword->parser->($keyword, $self);
43 return $self->check_match;
48 my $code = $self->code||'';
49 my ($extra_code, $not_eof) = $self->reader->();
56 my ($self, $first, $second) = @_;
57 $self->fetch_more while $self->code =~ /\A$first\s+\z/;
58 if (my @match = ($self->code =~ /(.*?${first}\s+${second})(.*\n?)\z/)) {
59 my $code = pop @match;
61 my $found = shift(@match);
62 return ($found, \@match);
69 unless ($self->code) {
73 for my $keyword (@{ $self->keywords }) {
75 my ($stripped, $matches)
76 = $self->match_source(
77 $keyword->keyword_name, qr/(\(|[A-Za-z][A-Za-z_0-9]*|{)/
80 $keyword->install_matcher($matches->[0]);
81 $self->current_match($matches);
82 $self->short_circuit(1);
83 return ($stripped, 1);
86 my $code = $self->code;