49
+ − 1 package IMPL::Text::Parser::Chunk;
+ − 2 use strict;
+ − 3 use warnings;
+ − 4
+ − 5 use base qw(IMPL::Object IMPL::Object::Autofill);
+ − 6
+ − 7 use IMPL::Class::Property;
+ − 8 use IMPL::Class::Property::Direct;
+ − 9
+ − 10 use constant {
+ − 11 OP_REGEXP => 1,
+ − 12 OP_STRING => 2,
+ − 13 OP_REFERENCE => 3,
+ − 14 OP_CHUNK => 4,
+ − 15 OP_SWITCH => 5,
+ − 16 OP_REPEAT => 7
+ − 17 };
+ − 18
+ − 19 BEGIN {
+ − 20 public _direct property chunkName => prop_get;
+ − 21 public _direct property opStream => prop_get;
+ − 22 }
+ − 23
+ − 24 sub Regexp {
+ − 25 my ($this,$rx) = @_;
+ − 26
+ − 27 if (ref $rx eq 'Regexp') {
+ − 28
+ − 29 } elsif (not ref $rx) {
+ − 30 $rx = q/$rx/;
+ − 31 } else {
+ − 32 die new IMPL::InvalidArgumentException('A regular expression required');
+ − 33 }
+ − 34
+ − 35 push @{$this->{$opStream}}, [OP_REGEXP, $rx];
+ − 36 }
+ − 37
+ − 38 sub String {
+ − 39 my ($this,$str) = @_;
+ − 40
+ − 41 die new IMPL::InvalidArgumentException("A simple value is required") if ref $str;
+ − 42
+ − 43 push @{$this->{$opStream}}, [OP_STRING, $str];
+ − 44 }
+ − 45
+ − 46 sub Reference {
+ − 47 my ($this,$ref) = @_;
+ − 48
+ − 49 die new IMPL::InvalidArgumentException("A simple value is reqiured") if ref $ref;
+ − 50
+ − 51 push @{$this->{$opStream}}, [OP_REFERENCE, $ref];
+ − 52 }
+ − 53
+ − 54 sub Chunk {
+ − 55 my ($this,$chunk) = @_;
+ − 56
+ − 57 die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk');
+ − 58
+ − 59 push @{$this->{$opStream}}, [OP_CHUNK, $chunk];
+ − 60 }
+ − 61
+ − 62 sub Switch {
+ − 63 my $this = shift;
+ − 64
+ − 65 push @{$this->{$opStream}}, [OP_SWITCH, @_];
+ − 66 }
+ − 67
+ − 68 sub Repeat {
+ − 69 my ($this,$chunk,$min,$max) = @_;
+ − 70
+ − 71 die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk');
+ − 72
+ − 73 push @{$this->{$opStream}}, [OP_REPEAT, $chunk, $min, $max ];
+ − 74 }
+ − 75
+ − 76 1;
+ − 77
+ − 78 __END__
+ − 79
+ − 80 =pod
+ − 81
+ − 82 =head1 DESCRIPTION
+ − 83 ����������� ����� ��������
+ − 84
+ − 85 =head1 MEMBERS
+ − 86
+ − 87 =level
+ − 88
+ − 89 =item C<<$obj->>>
+ − 90
+ − 91 =back
+ − 92
+ − 93 =cut