changeset 26:c529d386d80e

Text services in progress
author Sergey
date Thu, 15 Oct 2009 17:52:09 +0400
parents 9dd67fa91ee3
children b544a772b654
files Lib/IMPL/Text/Parser/Builder.pm Lib/IMPL/Text/Parser/Chunk.pm Lib/IMPL/Text/Schema.pm
diffstat 3 files changed, 136 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Text/Parser/Builder.pm	Thu Oct 15 17:52:09 2009 +0400
@@ -0,0 +1,7 @@
+package IMPL::Text::Parser::Builder;
+use strict;
+use warnings;
+
+
+
+1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Text/Parser/Chunk.pm	Thu Oct 15 17:52:09 2009 +0400
@@ -0,0 +1,100 @@
+package IMPL::Text::Parser::Chunk;
+use strict;
+use warnings;
+
+use base qw(IMPL::Object);
+
+use IMPL::Class::Property;
+use IMPL::Class::Property::Direct;
+
+use constant {
+    OP_REGEXP => 1,
+    OP_STRING => 2,
+    OP_REFERENCE => 3,
+    OP_CHUNK => 4,
+    OP_THROW => 5,
+    OP_TRYCATCH => 6
+};
+
+BEGIN {
+    public _direct property chunkName => prop_get;
+    public _direct property opStream => prop_get;
+}
+
+sub Regexp {
+    my ($this,$rx) = @_;
+    
+    if (ref $rx eq 'Regexp') {
+        
+    } elsif (not ref $rx) {
+        $rx = q/$rx/;
+    } else {
+        die new IMPL::InvalidArgumentException('A regular expression required');
+    }
+    
+    push @{$this->{$opStream}}, [OP_REGEXP, $rx];
+}
+
+sub String {
+    my ($this,$str) = @_;
+    
+    die new IMPL::InvalidArgumentException("A simple value is required") if ref $str;
+    
+    push @{$this->{$opStream}}, [OP_STRING, $str];
+}
+
+sub Reference {
+    my ($this,$ref) = @_;
+    
+    die new IMPL::InvalidArgumentException("A simple value is reqiured") if ref $ref;
+    
+    push @{$this->{$opStream}}, [OP_REFERENCE, $ref];
+}
+
+sub Chunk {
+    my ($this,$chunk) = @_;
+    
+    die new IMPL::InvalidArgumentException unless UNIVERSAL::isa($chunk,'IMPL::Text::Parser::Chunk');
+    
+    push @{$this->{$opStream}}, [OP_CHUNK, $chunk];
+}
+
+sub Throw {
+    my ($this, $msg) = @_;
+    
+    push @{$this->{$opStream}}, [OP_THROW, $msg];
+}
+
+sub TryCatch {
+    my ($this,$chunkTry,$chunkCatch) = @_;
+    
+    push @{$this->{$opStream}}, [OP_TRYCATCH, $chunkTry, $chunkCatch];
+}
+
+sub compile {
+    my ($this) = @_;
+    
+    my $text = '';
+    
+    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) {
+                
+            }
+        }
+    }
+}
+
+1;
--- a/Lib/IMPL/Text/Schema.pm	Tue Oct 13 17:51:25 2009 +0400
+++ b/Lib/IMPL/Text/Schema.pm	Thu Oct 15 17:52:09 2009 +0400
@@ -25,11 +25,36 @@
             <SwitchNode minOccur="1" maxOccur="unbounded">
                 <Node name="Word" type="Word"/>
                 <Node name="Statement" type="Word"/>
+                <Node name="Regexp" type="Regexp"/>
                 <Node name="Switch" type="Switch"/>
-                <Node name="List" type="List"/>
+                <Node name="Repeat" type="List"/>
             </SwitchNode>
         </NodeList>
     </ComplexType>
+    <SimpleType type="Word" nativeType="IMPL::Text::Schema::Word"/>
+    <SimpleType type="Regexp" nativeType="IMPL::Text::Schema::Regexp"/>
+    <ComplexType type="Switch" nativeType="IMPL::Text::Schema::Switch">
+        <NodeList>
+            <SwitchNode minOccur="1" maxOccur="unbounded">
+                <Node name="Word" type="Word"/>
+                <Node name="Statement" type="Word"/>
+                <Node name="Regexp" type="Regexp"/>
+                <Node name="Switch" type="Switch"/>
+                <Node name="Repeat" type="List"/>
+            </SwitchNode>
+        </NodeList>
+    </ComplexType>
+    <ComplexType type="Repeat" nativeType="IMPL::Text::Schema::Repeat">
+        <NodeList>
+            <SwitchNode minOccur="1" maxOccur="unbounded">
+                <Node name="Word" type="Word"/>
+                <Node name="Statement" type="Word"/>
+                <Node name="Regexp" type="Regexp"/>
+                <Node name="Switch" type="Switch"/>
+                <Node name="Repeat" type="List"/>
+            </SwitchNode>
+        </NodeList>
+    </CoomplexType>
 </schema>
 
 =head1 DESCRIPTION
@@ -44,7 +69,7 @@
 
 Допускаются следующие операторы
 1. Повтор
-2. 
+2. Ветвление
 
 =head1 METHODS
 
@@ -56,5 +81,7 @@
 
 =back
 
+=head1 INTERNALS
+
 
 =cut