comparison Lib/IMPL/Text/Parser/Player.pm @ 40:ac21a032e7a9

bnf parser in progress
author Sergey
date Thu, 10 Dec 2009 17:43:39 +0300
parents 4f5a6a1bfb0e
children c442eb67fa22
comparison
equal deleted inserted replaced
39:4f5a6a1bfb0e 40:ac21a032e7a9
17 IMPL::Text::Parser::Chunk::OP_REPEAT , &MatchRepeat 17 IMPL::Text::Parser::Chunk::OP_REPEAT , &MatchRepeat
18 ); 18 );
19 19
20 BEGIN { 20 BEGIN {
21 private _direct property _data => prop_all; 21 private _direct property _data => prop_all;
22 private _direct property _position => prop_all; 22 private _direct property _current => prop_all;
23 public _direct property Punctuation => prop_all; 23 public _direct property Punctuation => prop_all;
24 public _direct property Delimier => prop_all; 24 public _direct property Delimier => prop_all;
25 } 25 }
26 26
27 sub LoadString { 27 sub LoadString {
28 my ($this,$string) = @_; 28 my ($this,$string) = @_;
29 29
30 while ($string =~ /($rxDelim)|($rxPunct)|(.*?)/g) { 30 my $rxDelim = /(\s+|[.,;!-+*~$^&|%()`@\\\/])/;
31
32 31
33 } 32 my $line = 0;
33
34 $this->{$_data} = [
35 map {
36 $line++;
37 map {
38 [$line,$_]
39 } split $rxDelim, $_
40 } split /\n/, $string
41 ]
34 } 42 }
35 43
36 sub PlayChunk { 44 sub PlayChunk {
37 my ($this,$chunk) = @_; 45 my ($this,$chunk) = @_;
38 46
40 } 48 }
41 49
42 sub MatchRegexp { 50 sub MatchRegexp {
43 my ($this,$rx) = @_; 51 my ($this,$rx) = @_;
44 52
45 if ($this->{$_data} =~ $rx) { 53 if ($this->{$_current}{token} =~ $rx) {
46 54
47 } 55 }
48 } 56 }
49 57
58 sub moveNext {
59 my ($this) = @_;
60
61 my $pos = $this->{$_current}{pos};
62
63 $pos ++;
64
65 if ($pos < @{$this->{$_data}}) {
66
67 $this->{$_current} = {
68 pos => $pos
69 };
70
71 } else {
72 return undef;
73 }
74 }
75
50 1; 76 1;