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

Text parser
author Sergey
date Tue, 08 Dec 2009 17:28:06 +0300
parents
children ac21a032e7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
1 package IMPL::Text::Parser::Player;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
2 use strict;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
3 use warnings;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
4
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object);
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
6 use IMPL::Class::Property;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
7 use IMPL::Class::Property::Direct;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
8
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
9 use IMPL::Text::Parser::Chunk;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
10
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
11 my %opCodesMap = (
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
12 IMPL::Text::Parser::Chunk::OP_REGEXP , &MatchRegexp ,
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
13 IMPL::Text::Parser::Chunk::OP_STRING , &MatchString ,
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
14 IMPL::Text::Parser::Chunk::OP_REFERENCE , &MatchReference ,
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
15 IMPL::Text::Parser::Chunk::OP_CHUNK , &PlayChunk ,
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
16 IMPL::Text::Parser::Chunk::OP_SWITCH , &MatchSwitch ,
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
17 IMPL::Text::Parser::Chunk::OP_REPEAT , &MatchRepeat
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
18 );
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
19
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
20 BEGIN {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
21 private _direct property _data => prop_all;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
22 private _direct property _position => prop_all;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
23 public _direct property Punctuation => prop_all;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
24 public _direct property Delimier => prop_all;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
25 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
26
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
27 sub LoadString {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
28 my ($this,$string) = @_;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
29
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
30 while ($string =~ /($rxDelim)|($rxPunct)|(.*?)/g) {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
31
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
32
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
33 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
34 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
35
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
36 sub PlayChunk {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
37 my ($this,$chunk) = @_;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
38
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
39 $opCodesMap{shift @$_}->(@$_) foreach @{$chunk->opStream};
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
40 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
41
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
42 sub MatchRegexp {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
43 my ($this,$rx) = @_;
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
44
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
45 if ($this->{$_data} =~ $rx) {
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
46
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
47 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
48 }
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
49
4f5a6a1bfb0e Text parser
Sergey
parents:
diff changeset
50 1;