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