changeset 39:4f5a6a1bfb0e

Text parser
author Sergey
date Tue, 08 Dec 2009 17:28:06 +0300
parents d660fb38b7cc
children ac21a032e7a9
files Lib/IMPL/Text/Parser/Chunk.pm Lib/IMPL/Text/Parser/Player.pm
diffstat 2 files changed, 78 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Text/Parser/Chunk.pm	Mon Nov 23 17:57:07 2009 +0300
+++ b/Lib/IMPL/Text/Parser/Chunk.pm	Tue Dec 08 17:28:06 2009 +0300
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use base qw(IMPL::Object);
+use base qw(IMPL::Object IMPL::Object::Autofill);
 
 use IMPL::Class::Property;
 use IMPL::Class::Property::Direct;
@@ -12,8 +12,8 @@
     OP_STRING => 2,
     OP_REFERENCE => 3,
     OP_CHUNK => 4,
-    OP_THROW => 5,
-    OP_TRYCATCH => 6
+    OP_SWITCH => 5,
+    OP_REPEAT => 7
 };
 
 BEGIN {
@@ -59,42 +59,35 @@
     push @{$this->{$opStream}}, [OP_CHUNK, $chunk];
 }
 
-sub Throw {
-    my ($this, $msg) = @_;
+sub Switch {
+    my $this = shift;
     
-    push @{$this->{$opStream}}, [OP_THROW, $msg];
-}
-
-sub TryCatch {
-    my ($this,$chunkTry,$chunkCatch) = @_;
-    
-    push @{$this->{$opStream}}, [OP_TRYCATCH, $chunkTry, $chunkCatch];
+    push @{$this->{$opStream}}, [OP_SWITCH, @_];
 }
 
-sub compile {
-    my ($this) = @_;
-    
-    my $text = '';
+sub Repeat {
+    my ($this,$chunk,$min,$max) = @_;
     
-    if ($this->{$opStream}) {
-        foreach my $op (@{$this->{$opStream}}) {
-            my $code = shift @$op;
-            
-            if ($code == OP_REGEXP) {
-                
-            } elsif ($code == OP_STRING) {
-                
-            } elsif ($code == OP_REFERENCE) {
-                
-            } elsif ($code == OP_CHUNK) {
-                
-            } elsif ($code == OP_THROW) {
-                
-            } elsif ($code == OP_TRYCATCH) {
-                
-            }
-        }
-    }
+    die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk');
+    
+    push @{$this->{$opStream}}, [OP_REPEAT, $chunk, $min, $max ];
 }
 
 1;
+
+__END__
+
+=pod
+
+=head1 DESCRIPTION
+Именованный поток операций
+
+=head1 MEMBERS
+
+=level
+
+=item C<<$obj->>>
+
+=back
+
+=cut
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Text/Parser/Player.pm	Tue Dec 08 17:28:06 2009 +0300
@@ -0,0 +1,50 @@
+package IMPL::Text::Parser::Player;
+use strict;
+use warnings;
+
+use base qw(IMPL::Object);
+use IMPL::Class::Property;
+use IMPL::Class::Property::Direct;
+
+use IMPL::Text::Parser::Chunk;
+
+my %opCodesMap = (
+    IMPL::Text::Parser::Chunk::OP_REGEXP , &MatchRegexp ,
+    IMPL::Text::Parser::Chunk::OP_STRING , &MatchString ,
+    IMPL::Text::Parser::Chunk::OP_REFERENCE , &MatchReference ,
+    IMPL::Text::Parser::Chunk::OP_CHUNK , &PlayChunk ,
+    IMPL::Text::Parser::Chunk::OP_SWITCH , &MatchSwitch ,
+    IMPL::Text::Parser::Chunk::OP_REPEAT , &MatchRepeat
+);
+
+BEGIN {
+    private _direct property _data => prop_all;
+    private _direct property _position => prop_all;
+    public _direct property Punctuation => prop_all;
+    public _direct property Delimier => prop_all;
+}
+
+sub LoadString {
+    my ($this,$string) = @_;
+    
+    while ($string =~ /($rxDelim)|($rxPunct)|(.*?)/g) {
+        
+    
+    }
+}
+
+sub PlayChunk {
+    my ($this,$chunk) = @_;
+    
+    $opCodesMap{shift @$_}->(@$_) foreach @{$chunk->opStream};
+}
+
+sub MatchRegexp {
+    my ($this,$rx) = @_;
+    
+    if ($this->{$_data} =~ $rx) {
+        
+    }
+}
+
+1;