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 { '' });
30 has active_keyword => (is => 'rw', clearer => 1);
34 if ($self->short_circuit) {
35 $self->short_circuit(0);
36 $self->${\$self->re_add};
39 if (my $keyword = $self->active_keyword) {
40 $self->clear_active_keyword;
41 $keyword->clear_globref;
42 return $keyword->parse($self);
44 for my $keyword (@{$self->keywords}) {
45 if ($keyword->have_match) {
46 $self->active_keyword($keyword);
47 $self->short_circuit(1);
48 my $match = $self->current_match;
49 my $end = $match eq '{' ? '}'
55 return $self->check_match;
60 my $code = $self->code||'';
61 my ($extra_code, $not_eof) = $self->reader->();
68 my ($self, $first, $second) = @_;
69 $self->fetch_more while $self->code =~ /\A$first\s+\z/;
70 if (my @match = ($self->code =~ /(.*?${first}\s+${second})(.*\n?)\z/)) {
71 my $code = pop @match;
73 my $found = shift(@match);
74 return ($found, \@match);
81 unless ($self->code) {
85 for my $keyword (@{ $self->keywords }) {
87 my ($stripped, $matches)
88 = $self->match_source(
89 $keyword->keyword_name, qr/(\(|[A-Za-z][A-Za-z_0-9]*|{)/
92 $keyword->install_matcher($matches->[0]);
93 $self->current_match($matches->[0]);
94 $self->short_circuit(1);
95 return ($stripped, 1);
98 my $code = $self->code;