# HG changeset patch # User Sergey # Date 1260282486 -10800 # Node ID 4f5a6a1bfb0e4e4156d7f920ec846929ea061ae9 # Parent d660fb38b7cc324d931084ab9140e7be334ef2f5 Text parser diff -r d660fb38b7cc -r 4f5a6a1bfb0e Lib/IMPL/Text/Parser/Chunk.pm --- 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 diff -r d660fb38b7cc -r 4f5a6a1bfb0e Lib/IMPL/Text/Parser/Player.pm --- /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;