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 current_keyword => (is => 'rw', clearer => 1);
31 has keyword_matched => (is => 'rw');
32 has keyword_parsed => (is => 'rw');
36 if ($self->short_circuit) {
37 $self->short_circuit(0);
38 $self->${\$self->re_add};
41 if (my $keyword = $self->current_keyword) {
42 if ($self->keyword_parsed) {
43 $keyword->clear_globref;
44 $self->clear_current_keyword;
45 $self->keyword_parsed(0);
47 elsif ($self->keyword_matched) {
48 $keyword->clear_globref;
49 $self->short_circuit(1);
50 $self->keyword_parsed(1);
51 return $keyword->parse($self);
53 elsif ($keyword->have_match) {
54 $self->keyword_matched(1);
55 $self->short_circuit(1);
56 my $match = $self->current_match;
57 my $end = $match eq '{' ? '}'
63 $keyword->restore_shadow;
64 $self->clear_current_keyword;
67 return $self->check_match;
72 my $code = $self->code||'';
73 my ($extra_code, $not_eof) = $self->reader->();
80 my ($self, $first, $second) = @_;
81 $self->fetch_more while $self->code =~ /\A$first\s+\z/;
82 if (my @match = ($self->code =~ /(.*?${first}\s+${second})(.*\n?)\z/)) {
83 my $code = pop @match;
85 my $found = shift(@match);
86 return ($found, \@match);
93 unless ($self->code) {
97 for my $keyword (@{ $self->keywords }) {
99 my ($stripped, $matches)
100 = $self->match_source(
101 $keyword->keyword_name, qr/(\(|[A-Za-z][A-Za-z_0-9]*|{)/
104 $keyword->install_matcher($matches->[0]);
105 $self->current_match($matches->[0]);
106 $self->current_keyword($keyword);
107 $self->keyword_matched(0);
108 $self->short_circuit(1);
109 return ($stripped, 1);
112 my $code = $self->code;