annotate Lib/IMPL/Text/Parser/Chunk.pm @ 39:4f5a6a1bfb0e

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