Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
38:d660fb38b7cc | 39:4f5a6a1bfb0e |
---|---|
1 package IMPL::Text::Parser::Chunk; | 1 package IMPL::Text::Parser::Chunk; |
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::Object); | 5 use base qw(IMPL::Object IMPL::Object::Autofill); |
6 | 6 |
7 use IMPL::Class::Property; | 7 use IMPL::Class::Property; |
8 use IMPL::Class::Property::Direct; | 8 use IMPL::Class::Property::Direct; |
9 | 9 |
10 use constant { | 10 use constant { |
11 OP_REGEXP => 1, | 11 OP_REGEXP => 1, |
12 OP_STRING => 2, | 12 OP_STRING => 2, |
13 OP_REFERENCE => 3, | 13 OP_REFERENCE => 3, |
14 OP_CHUNK => 4, | 14 OP_CHUNK => 4, |
15 OP_THROW => 5, | 15 OP_SWITCH => 5, |
16 OP_TRYCATCH => 6 | 16 OP_REPEAT => 7 |
17 }; | 17 }; |
18 | 18 |
19 BEGIN { | 19 BEGIN { |
20 public _direct property chunkName => prop_get; | 20 public _direct property chunkName => prop_get; |
21 public _direct property opStream => prop_get; | 21 public _direct property opStream => prop_get; |
57 die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk'); | 57 die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk'); |
58 | 58 |
59 push @{$this->{$opStream}}, [OP_CHUNK, $chunk]; | 59 push @{$this->{$opStream}}, [OP_CHUNK, $chunk]; |
60 } | 60 } |
61 | 61 |
62 sub Throw { | 62 sub Switch { |
63 my ($this, $msg) = @_; | 63 my $this = shift; |
64 | 64 |
65 push @{$this->{$opStream}}, [OP_THROW, $msg]; | 65 push @{$this->{$opStream}}, [OP_SWITCH, @_]; |
66 } | 66 } |
67 | 67 |
68 sub TryCatch { | 68 sub Repeat { |
69 my ($this,$chunkTry,$chunkCatch) = @_; | 69 my ($this,$chunk,$min,$max) = @_; |
70 | 70 |
71 push @{$this->{$opStream}}, [OP_TRYCATCH, $chunkTry, $chunkCatch]; | 71 die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk'); |
72 } | |
73 | |
74 sub compile { | |
75 my ($this) = @_; | |
76 | 72 |
77 my $text = ''; | 73 push @{$this->{$opStream}}, [OP_REPEAT, $chunk, $min, $max ]; |
78 | |
79 if ($this->{$opStream}) { | |
80 foreach my $op (@{$this->{$opStream}}) { | |
81 my $code = shift @$op; | |
82 | |
83 if ($code == OP_REGEXP) { | |
84 | |
85 } elsif ($code == OP_STRING) { | |
86 | |
87 } elsif ($code == OP_REFERENCE) { | |
88 | |
89 } elsif ($code == OP_CHUNK) { | |
90 | |
91 } elsif ($code == OP_THROW) { | |
92 | |
93 } elsif ($code == OP_TRYCATCH) { | |
94 | |
95 } | |
96 } | |
97 } | |
98 } | 74 } |
99 | 75 |
100 1; | 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 |