[Numpy-svn] r3385 - trunk/numpy/f2py/lib/parser

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Oct 23 18:42:03 EDT 2006


Author: pearu
Date: 2006-10-23 17:41:47 -0500 (Mon, 23 Oct 2006)
New Revision: 3385

Modified:
   trunk/numpy/f2py/lib/parser/expressions.py
   trunk/numpy/f2py/lib/parser/pattern_tools.py
   trunk/numpy/f2py/lib/parser/test_expressions.py
Log:
F2PY G3: Cont implementing Fortran expression parser, almost finished.

Modified: trunk/numpy/f2py/lib/parser/expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/expressions.py	2006-10-23 22:22:41 UTC (rev 3384)
+++ trunk/numpy/f2py/lib/parser/expressions.py	2006-10-23 22:41:47 UTC (rev 3385)
@@ -33,9 +33,6 @@
 class NoMatchError(Exception):
     pass
 
-class NoSubClasses:
-    pass
-
 class Base(object):
 
     subclasses = {}
@@ -51,8 +48,6 @@
             obj.string = string
             if hasattr(cls, 'init'):
                 obj.init(*result)
-            #if cls.__dict__.has_key('init'):
-            #    obj.init(*result)
             return obj
         elif isinstance(result, Base):
             return result
@@ -66,79 +61,8 @@
             raise AssertionError,`result`
         raise NoMatchError,'%s: %r' % (cls.__name__, string)
 
-    default_match = staticmethod(lambda string: None)
-
     findall = staticmethod(re.compile(r'(_F2PY_STRING_CONSTANT_\d+_|F2PY_EXPR_TUPLE_\d+)').findall)
     
-    def match_binary_operand_right(lhs_cls, op_pattern, rhs_cls, string):
-        line, repmap = string_replace_map(string)
-        t = op_pattern.rsplit(line)
-        if t is None: return
-        lhs, op, rhs = t
-        for k in Base.findall(lhs):
-            lhs = lhs.replace(k, repmap[k])
-        for k in Base.findall(rhs):
-            rhs = rhs.replace(k, repmap[k])
-        lhs_obj = lhs_cls(lhs)
-        rhs_obj = rhs_cls(rhs)
-        return lhs_obj, t[1], rhs_obj
-    match_binary_operand_right = staticmethod(match_binary_operand_right)
-
-    def match_binary_unary_operand_right(lhs_cls, op_pattern, rhs_cls, string):
-        line, repmap = string_replace_map(string)
-        t = op_pattern.rsplit(line)
-        if t is None: return
-        lhs, op, rhs = t
-        if lhs: 
-            for k in Base.findall(lhs):
-                lhs = lhs.replace(k, repmap[k])
-        for k in Base.findall(rhs):
-            rhs = rhs.replace(k, repmap[k])
-        rhs_obj = rhs_cls(rhs)
-        if lhs:
-            lhs_obj = lhs_cls(lhs)
-            return lhs_obj, t[1], rhs_obj
-        else:
-            return None, t[1], rhs_obj
-    match_binary_unary_operand_right = staticmethod(match_binary_unary_operand_right)
-
-    def match_binary_operand_left(lhs_cls, op_pattern, rhs_cls, string):
-        line, repmap = string_replace_map(string)
-        t = op_pattern.lsplit(line)
-        if t is None: return
-        lhs, op, rhs = t
-        for k in Base.findall(lhs):
-            lhs = lhs.replace(k, repmap[k])
-        for k in Base.findall(rhs):
-            rhs = rhs.replace(k, repmap[k])
-        lhs_obj = lhs_cls(lhs)
-        rhs_obj = rhs_cls(rhs)
-        return lhs_obj, t[1], rhs_obj
-    match_binary_operand_left = staticmethod(match_binary_operand_left)
-
-    def match_unary_operand(op_pattern, rhs_cls, string):
-        line, repmap = string_replace_map(string)
-        t = op_pattern.lsplit(line)
-        if t is None: return
-        lhs, op, rhs = t
-        for k in Base.findall(rhs):
-            rhs = rhs.replace(k, repmap[k])
-        assert not lhs,`lhs`
-        rhs_obj = rhs_cls(rhs)
-        return t[1], rhs_obj
-    match_unary_operand = staticmethod(match_unary_operand)
-
-    def match_list_of(subcls, string):
-        line, repmap = string_replace_map(string)
-        lst = []
-        for p in line.split(','):
-            p = p.strip()
-            for k in Base.findall(p):
-                p = p.replace(k,repmap[k])
-            lst.append(subcls(p))
-        return tuple(lst)
-    match_list_of = staticmethod(match_list_of)
-
     def init_list(self, *items):
         self.items = items
         return
@@ -149,59 +73,12 @@
     def torepr_list(self):
         return '%s(%s)' % (self.__class__.__name__,', '.join(map(repr,self.items)))
 
-    def init_binary_operand(self, lhs, op, rhs):
-        self.lhs = lhs
-        self.op = op
-        self.rhs = rhs
-        return
-
-    def init_unary_operand(self, op, rhs):
-        self.op = op
-        self.rhs = rhs
-        return
-
-    def init_primary(self, primary):
-        self.primary = primary
-        return
-
-    def tostr_binary_operand(self):
-        return '%s %s %s' % (self.lhs, self.op, self.rhs)
-
-    def tostr_binary_unary_operand(self):
-        if self.lhs is None:
-            return '%s %s' % (self.op, self.rhs)
-        return '%s %s %s' % (self.lhs, self.op, self.rhs)
-
-    def tostr_unary_operand(self):
-        return '%s %s' % (self.op, self.rhs)
-
-    def tostr_primary(self):
-        return str(self.primary)
-
     def tostr_string(self):
         return str(self.string)
 
-    def torepr_binary_operand(self):
-        return '%s(%r, %r, %r)' % (self.__class__.__name__,self.lhs, self.op, self.rhs)
-
-    def torepr_binary_unary_operand(self):
-        return '%s(%r, %r, %r)' % (self.__class__.__name__,self.lhs, self.op, self.rhs)
-
-    def torepr_unary_operand(self):
-        return '%s(%r, %r)' % (self.__class__.__name__,self.op, self.rhs)
-
-    def torepr_primary(self):
-        return '%s(%r)' % (self.__class__.__name__,self.primary)
-
     def torepr_string(self):
         return '%s(%r)' % (self.__class__.__name__,self.string)
 
-    def tostr_number(self):
-        if self.items[1] is None: return str(self.items[0])
-        return '%s_%s' % (self.items[0],self.items[1])
-    def torepr_number(self):
-        return '%s(%r,%r)' % (self.__class__.__name__, self.items[0],self.items[1])
-
     def __str__(self):
         return self.tostr()
         if self.__class__.__dict__.has_key('tostr'):
@@ -215,7 +92,9 @@
         return '%s(%r)' % (self.__class__.__name__, self.string)
 
 class SequenceBase(Base):
-
+    """
+    <sequence-base> = <obj> [ , <obj> ]...
+    """
     def match(separator, subcls, string):
         line, repmap = string_replace_map(string)
         lst = []
@@ -229,10 +108,18 @@
     def init(self, separator, items):
         self.separator = separator
         self.items = items
-    def tostr(self): return (self.separator+' ').join(map(str, self.items))
+        return
+    def tostr(self):
+        s = self.separator
+        if s==',': s = s + ' '
+        else: s = ' ' + s + ' '
+        return s.join(map(str, self.items))
     def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.separator, self.items)
     
 class UnaryOpBase(Base):
+    """
+    <unary-op-base> = [ <unary-op> ] <rhs>
+    """
     def init(self, op, rhs):
         self.op = op
         self.rhs = rhs
@@ -256,7 +143,7 @@
 
 class BinaryOpBase(Base):
     """
-    <..> = <lhs> <op> <rhs>
+    <binary-op-base> = <lhs> <op> <rhs>
     """
     def match(lhs_cls, op_pattern, rhs_cls, string):
         line, repmap = string_replace_map(string)
@@ -285,7 +172,7 @@
 
 class RBinaryOpBase(BinaryOpBase):
     """
-    <..> = [ <lhs> <op> ] <rhs>
+    <rbinary-op-base> = [ <lhs> <op> ] <rhs>
     """
     def match(lhs_cls, op_pattern, rhs_cls, string):
         line, repmap = string_replace_map(string)
@@ -304,7 +191,7 @@
 
 class LBinaryOpBase(BinaryOpBase):
     """
-    <..> = <lhs> [ <op> <rhs> ]
+    <lbinary-op-base> = <lhs> [ <op> <rhs> ]
     """
     def match(lhs_cls, op_pattern, rhs_cls, string):
         line, repmap = string_replace_map(string)
@@ -321,16 +208,90 @@
         return lhs_obj, t[1], rhs_obj
     match = staticmethod(match)
 
+class KeywordValueBase(BinaryOpBase):
+    """
+    <keyword-value-base> = [ <keyword> = ] <rhs>
+    """
+    def match(cls, string):
+        if '=' not in string: return cls(string)
+        lhs,rhs = string.split('=',1)
+        return Keyword(lhs.rstrip()),'=',cls(rhs.lstrip())
+    match = staticmethod(match)
+    
+class BracketBase(Base):
+    """
+    <bracket-base> = <left-bracket-base> <something> <right-bracket>
+    """
+    def match(brackets, cls, string):
+        left = brackets[:len(brackets)/2]
+        right = brackets[-len(brackets)/2:]
+        if string.startswith(left) and string.endswith(right):
+            return left,cls(string[len(left):-len(right)].strip())
+        return
+    match = staticmethod(match)
+    def init(self,left,item,right):
+        self.left = left
+        self.item = item
+        self.right = right
+        return
+    def tostr(self): '%s%s%s' % (self.left, self.item, self.right)
+    def torepr(self): '%s(%r, %r, %r)' % (self.__class__.__name__, self.left, self.item, self.right)
+
+class NumberBase(Base):
+    """
+    <number-base> = <number> [ _ <kind-param> ]
+    """
+    def match(number_pattern, string):
+        m = number_pattern.match(string)
+        if m is None: return
+        return m.group('value'),m.group('kind_param')
+    match = staticmethod(match)
+    def init(self, value, kind_param):
+        self.value = value
+        self.kind_param = kind_param
+        return
+    def tostr(self):
+        if self.kind_param is None: return str(self.value)
+        return '%s_%s' % (self.value, self.kind_param)
+    def torepr(self):
+        return '%s(%r, %r)' % (self.__class__.__name__, self.value, self.kind_param)
+
+class CallBase(Base):
+    """
+    <call-base> = <lhs> ( <rhs> )
+    """
+    def match(lhs_cls, rhs_cls, string):
+        if not string.endswith(')'): return
+        line, repmap = string_replace_map(string)
+        i = line.find('(')
+        if i==-1: return
+        lhs = line[:i]
+        rhs = line[i+1:-1].strip()
+        for k in Base.findall(lhs):
+            lhs = lhs.replace(k,repmap[k])
+        for k in Base.findall(rhs):
+            rhs = rhs.replace(k,repmap[k])
+        return lhs_cls(lhs), rhs_cls(rhs)
+    match = staticmethod(match)
+    def init(self, lhs, rhs):
+        self.lhs = lhs
+        self.rhs = rhs
+        return
+    def tostr(self): return '%s(%s)' % (self.lhs, self.rhs)
+    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.lhs, self.rhs)
+
+##################################################
+    
 class Expr(RBinaryOpBase):
     """
     <expr> = [ <expr> <defined-binary-op> ] <level-5-expr>
     <defined-binary-op> = . <letter> [ <letter> ]... .
     TODO: defined_binary_op must not be intrinsic_binary_op!!
     """
-    #subclass_names = ['Level_5_Expr']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(Expr, pattern.defined_binary_op.named(), Level_5_Expr,
-                                 string)
+                                   string)
     match = staticmethod(match)
 
 class Level_5_Expr(RBinaryOpBase):
@@ -339,7 +300,7 @@
     <equiv-op> = .EQV.
                | .NEQV.
     """
-    #subclass_names = ['Equiv_Operand']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Level_5_Expr,pattern.equiv_op.named(),Equiv_Operand,string)
@@ -350,7 +311,7 @@
     <equiv-operand> = [ <equiv-operand> <or-op> ] <or-operand>
     <or-op>  = .OR.
     """
-    #subclass_names = ['Or_Operand']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Equiv_Operand,pattern.or_op.named(),Or_Operand,string)
@@ -361,7 +322,7 @@
     <or-operand> = [ <or-operand> <and-op> ] <and-operand>    
     <and-op> = .AND.
     """
-    #subclass_names = ['And_Operand']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Or_Operand,pattern.and_op.named(),And_Operand,string)
@@ -372,7 +333,7 @@
     <and-operand> = [ <not-op> ] <level-4-expr>
     <not-op> = .NOT.
     """
-    #subclass_names = ['Level_4_Expr']
+    subclass_names = []
     def match(string):
         return UnaryOpBase.match(\
             pattern.not_op.named(),Level_4_Expr,string)
@@ -383,7 +344,7 @@
     <level-4-expr> = [ <level-3-expr> <rel-op> ] <level-3-expr>
     <rel-op> = .EQ. | .NE. | .LT. | .LE. | .GT. | .GE. | == | /= | < | <= | > | >=
     """
-    #subclass_names = ['Level_3_Expr']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Level_3_Expr,pattern.rel_op.named(),Level_3_Expr,string)
@@ -394,7 +355,7 @@
     <level-3-expr> = [ <level-3-expr> <concat-op> ] <level-2-expr>
     <concat-op>    = //
     """
-    #subclass_names = ['Level_2_Expr']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Level_3_Expr,pattern.concat_op.named(),Level_2_Expr,string)
@@ -406,7 +367,7 @@
     <add-op>   = +
                  | -
     """
-    subclass_names = ['Add_Operand']
+    subclass_names = []
     def match(string):
         lhs_cls, op_pattern, rhs_cls = Level_2_Expr,pattern.add_op.named(),Add_Operand
         line, repmap = string_replace_map(string)
@@ -432,7 +393,7 @@
     <mult-op>  = *
                  | /
     """
-    #subclass_names = ['Mult_Operand']
+    subclass_names = []
     def match(string):
         return RBinaryOpBase.match(\
             Add_Operand,pattern.mult_op.named(),Mult_Operand,string)
@@ -443,7 +404,7 @@
     <mult-operand> = <level-1-expr> [ <power-op> <mult-operand> ]
     <power-op> = **
     """
-    #subclass_names = ['Level_1_Expr']
+    subclass_names = []
     def match(string):
         return LBinaryOpBase.match(\
             Level_1_Expr,pattern.power_op.named(),Mult_Operand,string)
@@ -454,7 +415,7 @@
     <level-1-expr> = [ <defined-unary-op> ] <primary>
     <defined-unary-op> = . <letter> [ <letter> ]... .
     """
-    #subclass_names = ['Primary']
+    subclass_names = []
     def match(string):
         return UnaryOpBase.match(\
             pattern.defined_unary_op.named(),Primary,string)
@@ -490,42 +451,39 @@
             Designator, pattern.percent_op.named(), Type_Param_Name, string)
     match = staticmethod(match)
 
+class Structure_Constructor_2(KeywordValueBase):
+    """
+    <structure-constructor-2> = [ <keyword> = ] <component-data-source>
+    """
+    subclass_names = []
+    def match(string): return KeywordValueBase.match(Component_Data_Source, string)
+    match = staticmethod(match)
+
 class Structure_Constructor(Base):
     """
     <structure-constructor> = <derived-type-spec> ( [ <component-spec-list> ] )
                             | [ <keyword> = ] <component-data-source>
     """
-    subclass_names = []
+    subclass_names = ['Structure_Constructor_2']
     def match(string):
+        if string[-1]!=')': return
         line, repmap = string_replace_map(string)
-        if line[-1]==')':
-            i = line.rfind('(')
-            if i==-1: return
-            specline = line[:i].rstrip()
-            for k in Base.findall(specline):
-                specline = specline.replace(k,repmap[k])
-            try:
-                spec = Derived_Type_Spec(specline)
-            except NoMatchError:
-                spec = None
-            if spec is not None:
-                l = line[i+1:-1].strip()
-                for k in Base.findall(l):
-                    l = l.replace(k,repmap[k])
-                if not l: return spec,'(',None,')'
-                return spec,'(',Component_Spec_List(l),')'
-        if '=' not in string: return None, Component_Data_Source(string)
-        lhs,rhs = string.split('=',1)
-        return Keyword(lhs.rstrip()), Component_Data_Source(rhs.lstrip())        
+        i = line.rfind('(')
+        if i==-1: return
+        specline = line[:i].rstrip()
+        for k in Base.findall(specline):
+            specline = specline.replace(k,repmap[k])
+        spec = Derived_Type_Spec(specline)
+        l = line[i+1:-1].strip()
+        for k in Base.findall(l):
+            l = l.replace(k,repmap[k])
+        if not l: return spec,'(',None,')'
+        return spec,'(',Component_Spec_List(l),')'
     match = staticmethod(match)
     init = Base.init_list
     def tostr(self):
-        if len(self.items)==4:
-            if self.items[2] is None: return '%s()' % (self.items[0])
-            return '%s(%s)' % (self.items[0],self.items[2])
-        if self.items[0] is None:
-            return str(self.items[1])
-        return '%s = %s' % (self.items[0], self.items[1])
+        if self.items[2] is None: return '%s()' % (self.items[0])
+        return '%s(%s)' % (self.items[0],self.items[2])
     torepr = Base.torepr_list
 
 class Component_Data_Source(Base):
@@ -534,7 +492,7 @@
                               | <data-target>
                               | <proc-target>
     """
-    subclass_names = ['Expr','Data-Target','Proc-Target']
+    subclass_names = ['Expr','Data_Target','Proc_Target']
 
 class Data_Target(Base):
     """
@@ -549,7 +507,7 @@
                     | <procedure-name>
                     | <proc-component-ref>
     """
-    subclass_names = ['Expr','Procedure_Name','Proc_Component_Ref']
+    subclass_names = ['Procedure_Name','Proc_Component_Ref', 'Expr']
 
 class Proc_Component_Ref(BinaryOpBase):
     """
@@ -561,36 +519,23 @@
             Variable, pattern.percent_op.named(), Procedure_Component_Name, string)            
     match = staticmethod(match)
 
-class Component_Spec(Base):
+class Component_Spec(KeywordValueBase):
     """
     <component-spec> = [ <keyword> = ] <component-data-source>
     """
     subclass_names = []
-    def match(string):
-        if '=' not in string: return None, Component_Data_Source(string)
-        lhs,rhs = string.split('=',1)
-        return Keyword(lhs.rstrip()), Component_Data_Source(rhs.lstrip())
+    def match(string): return KeywordValueBase.match(Component_Data_Source, string)
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        if self.items[0] is None: return str(self.items[1])
-        return '%s = %s' % tuple(self.items)
-    def torepr(self):
-        return '%s(%r, %r)' % (self.__class__.__name__, self.items[0],self.items[1])
 
-class Component_Spec_List(Base):
+class Component_Spec_List(SequenceBase):
     """
     <component-spec-list> = <component-spec> [ , <component-spec> ]...
     """
     subclass_names = []
-    def match(string):
-        return Base.match_list_of(Component_Spec, string)
+    def match(string): return SequenceBase.match(r',', Component_Spec, string)
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_list
-    torepr = Base.torepr_list
 
-class Array_Constructor(Base):
+class Array_Constructor(BracketBase):
     """
     <array-constructor> = (/ <ac-spec> /)
                           | <left-square-bracket> <ac-spec> <right-square-bracket>
@@ -598,15 +543,14 @@
     """
     subclass_names = []
     def match(string):
-        if string[:2]+string[-2:]=='(//)':
-            return '(/',Ac_Spec(string[2:-2].strip()),'/)'
-        if string[:1]+string[-1:]=='[]':
-            return '[',Ac_Spec(string[1:-1].strip()),']'
-        return
+        try:
+            obj = BracketBase.match('(//)', Ac_Spec, string)
+        except NoMatchError:
+            obj = None
+        if obj is None:
+            obj = BracketBase.match('[]', Ac_Spec, string)
+        return obj
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self): return ''.join(map(str,self.items))
-    def torepr(self): return '%s(%s)' % (self.__class__.__name__, ', '.join(map(repr,self.items)))
 
 class Ac_Spec(Base):
     """
@@ -639,17 +583,16 @@
     def torepr(self):
         return '%s(%r, %r)' % (self.__class__.__name__, self.items[0], self.items[1])
 
-class Ac_Value_List(Base):
+class Ac_Value_List(SequenceBase):
     """
     <ac-value-list> = <ac-value> [ , <ac-value> ]...
     """
     subclass_names = []
     def match(string):
-        return Base.match_list_of(Ac_Value, string)
+        r = SequenceBase.match(r',', Ac_Value, string)
+        if len(r[1])==1: return r[1][0]
+        return r
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_list
-    torepr = Base.torepr_list
 
 class Ac_Value(Base):
     """
@@ -657,7 +600,6 @@
                  | <ac-implied-do>
     """
     subclass_names = ['Ac_Implied_Do','Expr']
-    extra_subclasses = [Expr]
 
 class Ac_Implied_Do(Base):
     """
@@ -707,7 +649,6 @@
     <scalar-int-expr> = <expr>
     """
     subclass_names = ['Expr']
-    extra_subclasses = [Expr]
 
 class Ac_Do_Variable(Base):
     """
@@ -932,7 +873,6 @@
                        | :
     """
     subclass_names = ['Scalar_Int_Expr']
-    extra_subclasses = [Scalar_Int_Expr]
     def match(string):
         if string in ['*',':']: return string,
         return
@@ -959,34 +899,24 @@
     def torepr(self):
         return '%s(%r, %r)' % (self.__class__.__name__, self.items[0],self.items[1])
 
-class Type_Param_Spec(Base):
+class Type_Param_Spec(KeywordValueBase):
     """
     <type-param-spec> = [ <keyword> = ] <type-param-value>
     """
     subclass_names = []
-    def match(string):
-        if '=' not in string: return None, Type_Param_Value(string)
-        lhs,rhs = string.split('=',1)
-        return Keyword(lhs.rstrip()), Type_Param_Value(rhs.lstrip())
+    def match(string): return KeywordValueBase.match(Type_Param_Value, string)
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        if self.items[0] is None: return str(self.items[1])
-        return '%s = %s' % tuple(self.items)
-    def torepr(self):
-        return '%s(%r, %r)' % (self.__class__.__name__, self.items[0],self.items[1])
 
-class Type_Param_Spec_List(Base):
+class Type_Param_Spec_List(SequenceBase):
     """
-    <type-param-spec> = <type-param> [ , <type-param> ]...
+    <type-param-spec-list> = <type-param> [ , <type-param> ]...
     """
     subclass_names = []
     def match(string):
-        return Base.match_list_of(Type_Param_Spec, string)
+        r = SequenceBase.match(',', Type_Param_Spec, string)
+        if len(r[1])==1: return r[1][0]
+        return r
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_list
-    torepr = Base.torepr_list
 
 
 class Constant(Base):
@@ -1003,15 +933,6 @@
                    | <array-section>
                    | <structure-component>
                    | <substring>
-    <array-element> = <data-ref>
-    <array-section> = <data-ref> [ ( <substring-range> ) ]
-    <data-ref> = <part-ref> [ % <part-ref> ]...
-    <part-ref> = <part-name> [ ( <section-subscript-list> ) ]
-    <substring> = <parent-string> ( <substring-range> )
-    <parent-string> = <scalar-variable-name>
-                      | <array-element>
-                      | <scalar-structure-component>
-                      | <scalar-constant>
     <substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
     <structure-component> = <data-ref>
     """
@@ -1019,6 +940,98 @@
                       'Substring'
                       ]
 
+class Substring(CallBase):
+    """
+    <substring> = <parent-string> ( <substring-range> )    
+    """
+    subclass_names = []
+    def match(string): return CallBase.match(Parent_String, Substring_Range, string)
+    match = staticmethod(match)
+
+class Parent_String(Base):
+    """
+    <parent-string> = <scalar-variable-name>
+                      | <array-element>
+                      | <scalar-structure-component>
+                      | <scalar-constant>    
+    """
+    subclass_names = ['Scalar_Variable_Name', 'Array_Element', 'Scalar_Structure_Component', 'Scalar_Constant']
+
+class Scalar_Variable_Name(Base):
+    """
+    <scalar-variable-name> = <name>
+    """
+    subclass_names = ['Name']
+
+class Scalar_Structure_Component(Base):
+    """
+    <scalar-structure-component> = <structure-component>
+    """
+    subclass_names = ['Structure_Component']
+
+class Scalar_Constant(Base):
+    """
+    <scalar-constant> = <constant>
+    """
+    subclass_names = ['Constant']
+
+class Structure_Component(Base):
+    """
+    <structure-component> = <data-ref>
+    """
+    subclass_names = ['Data_Ref']
+
+class Array_Section(CallBase):
+    """
+    <array-section> = <data-ref> [ ( <substring-range> ) ]
+    """
+    subclass_names = ['Data_Ref']
+    def match(string): return CallBase.match(Data_Ref, Substring_Range, string)
+    match = staticmethod(match)
+
+class Substring_Range(Base):
+    """
+    <substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
+    """
+    subclass_names = []
+    def match(string):
+        line, repmap = string_replace_map(string)
+        if ':' not in line: return
+        lhs,rhs = line.split(':',1)
+        lhs = lhs.rstrip()
+        rhs = rhs.lstrip()
+        if lhs:
+            for k in Base.findall(lhs):
+                lhs = lhs.replace(k,repmap[k])
+            lhs_obj = Scalar_Int_Expr(lhs)
+        else:
+            lhs_obj = None
+        if rhs:
+            for k in Base.findall(rhs):
+                rhs = rhs.replace(k,repmap[k])
+            rhs_obj = Scalar_Int_Expr(rhs)
+        else:
+            rhs_obj = None
+        return lhs_obj, rhs_obj
+    match = staticmethod(match)
+    def init(self, lhs, rhs):
+        self.lhs, self.rhs = lhs, rhs
+        return
+    def tostr(self):
+        if self.lhs is None:
+            if self.rhs is None: return ':'
+            return ': '+ str(self.rhs)
+        else:
+            if self.rhs is None: return str(self.lhs)+' :'
+            return str(self.lhs)+' : '+ str(self.rhs)
+    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.lhs, self.rhs)
+        
+class Array_Element(Base):
+    """
+    <array-element> = <data-ref>
+    """
+    subclass_names = ['Data_Ref']
+
 class Literal_Constant(Base):
     """
     <literal-constant> = <int-literal-constant>
@@ -1031,45 +1044,50 @@
     subclass_names = ['Int_Literal_Constant', 'Real_Literal_Constant','Complex_Literal_Constant',
                       'Logical_Literal_Constant','Char_Literal_Constant','Boz_Literal_Constant']
 
-class Int_Literal_Constant(Base):
+class Int_Literal_Constant(NumberBase):
     """
     <int-literal-constant> = <digit-string> [ _ <kind-param> ]
     """
     subclass_names = []
     def match(string):
-        m = pattern.abs_int_literal_constant_named.match(string)
-        if m is None: return
-        return m.group('value'),m.group('kind_param')
+        return NumberBase.match(pattern.abs_int_literal_constant_named, string)
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_number
-    torepr = Base.torepr_number
 
+class Signed_Int_Literal_Constant(NumberBase):
+    """
+    <signed-int-literal-constant> = [ <sign> ] <int-literal-constant>
+    """
+    subclass_names = []
+    def match(string):
+        return NumberBase.match(pattern.abs_signed_int_literal_constant_named, string)
+    match = staticmethod(match)
+
 class Scalar_Int_Literal_Constant(Base):
     """
     <scalar-int-literal-constant> = <int-literal-constant>
     """
     subclass_names = ['Int_Literal_Constant']
 
-class Real_Literal_Constant(Base):
+class Real_Literal_Constant(NumberBase):
     """
     """
     subclass_names = []
     def match(string):
-        m = pattern.abs_real_literal_constant_named.match(string)
-        if m is None: return
-        return m.group('value'),m.group('kind_param')
+        return NumberBase.match(pattern.abs_real_literal_constant_named, string)
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_number
-    torepr = Base.torepr_number
 
+class Signed_Real_Literal_Constant(NumberBase):
+    """
+    <signed-real-literal-constant> = [ <sign> ] <real-literal-constant>
+    """
+    subclass_names = []
+    def match(string):
+        return NumberBase.match(pattern.abs_signed_real_literal_constant_named, string)
+    match = staticmethod(match)
+
 class Complex_Literal_Constant(Base):
     """
     <complex-literal-constant> = ( <real-part>, <imag-part> )
-    <real-part> = <imag-part> = <signed-int-literal-constant>
-                                | <signed-real-literal-constant>
-                                | <named-constant>
     """
     subclass_names = []
     def match(string):
@@ -1079,9 +1097,11 @@
         r,i = string[1:-1].split(',')
         return Real_Part(r.strip()), Imag_Part(i.strip())
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self): return '(%s, %s)' % (self.items[0], self.items[1])
-    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.items[0], self.items[1])
+    def init(self,real,imag):
+        self.real, self.imag = real, imag
+        return
+    def tostr(self): return '(%s, %s)' % (self.real, self.imag)
+    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.real, self.imag)
 
 class Real_Part(Base):
     """
@@ -1089,41 +1109,13 @@
                   | <signed-real-literal-constant>
                   | <named-constant>
     """
-    subclass_names = []
-    def match(string):
-        clses = [Int_Literal_Constant, Real_Literal_Constant]
-        if string[0] in '+-':
-            sign = string[0]
-            string = string[1:].lstrip()
+    subclass_names = ['Signed_Int_Literal_Constant','Signed_Real_Literal_Constant','Named_Constant']
 
-        else:
-            sign = None
-            clses.append(Named_Constant)
-        obj = None
-        for cls in clses:
-            try:
-                obj = cls(string)
-            except NoMatchError:
-                pass
-        if obj is None:
-            return
-        return sign, obj
-    match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        if self.items[0] is None: return str(self.items[1])
-        return '%s%s' % (self.items[0], self.items[1])
-    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.items[0], self.items[1])
-
-class Imag_Part(Real_Part):
+class Imag_Part(Base):
     """
     <imag-part> = <real-part>
     """
-    subclass_names = []
-    match = staticmethod(Real_Part.match)
-    init = Real_Part.init
-    tostr = Real_Part.tostr
-    torepr = Real_Part.torepr
+    subclass_names = ['Signed_Int_Literal_Constant','Signed_Real_Literal_Constant','Named_Constant']
 
 class Char_Literal_Constant(Base):
     """
@@ -1152,22 +1144,15 @@
         return '%s_%s' % (self.items[1], self.items[0])
     def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.items[0], self.items[1])
 
-class Logical_Literal_Constant(Base):
+class Logical_Literal_Constant(NumberBase):
     """
     <logical-literal-constant> = .TRUE. [ _ <kind-param> ]
                                  | .FALSE. [ _ <kind-param> ]
     """
     subclass_names = []
     def match(string):
-        m = pattern.abs_logical_literal_constant_named.match(string)
-        if m is None: return
-        return m.group('value'), m.group('kind_param')
+        return NumberBase.match(pattern.abs_logical_literal_constant_named, string)    
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        if self.items[1] is None: return self.items[0]
-        return '%s_%s' % (self.items[0], self.items[1])
-    def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.items[0], self.items[1])
 
 class Boz_Literal_Constant(Base):
     """
@@ -1260,11 +1245,11 @@
         
 
 
-class Procedure_Designator(Base):
+class Procedure_Designator(BinaryOpBase):
     """
     <procedure-designator> = <procedure-name>
-                           | <proc-component-ref>
-                           | <data-ref> % <binding-name>
+                             | <proc-component-ref>
+                             | <data-ref> % <binding-name>
     """
     subclass_names = ['Procedure_Name','Proc_Component_Ref']
     def match(string):
@@ -1272,20 +1257,102 @@
             Data_Ref, pattern.percent_op.named(),  Binding_Name, string)
     match = staticmethod(match)
 
-class Part_Ref(Base):
+class Part_Ref(CallBase):
     """
     <part-ref> = <part-name> [ ( <section-subscript-list> ) ]
     """
     subclass_names = ['Part_Name']
+    def match(string): return CallBase.match(Part_Name, Section_Subscript_List, string)
+    match = staticmethod(match)
+
+class Section_Subscript_List(SequenceBase):
+    """
+    <section-subscript-list> = <section-subscript> [ , <section-subscript> ]...
+    """
+    subclass_names = []
     def match(string):
-        if string.endswith(')'):
-            i = string.find('(')
-            if i==-1: return
-            return Part_Name(string[:i].rstrip()),'(',Section_Subscript_List(string[i+1:-1].strip()),')'
-        return
+        r = SequenceBase.match(',', Section_Subscript, string)
+        if len(r[1])==1: return r[1][0]
+        return r
     match = staticmethod(match)
-    init = Base.init_list
 
+class Section_Subscript(Base):
+    """
+    <section-subscript> = <subscript>
+                          | <subscript-triplet>
+                          | <vector-subscript>
+    """
+    subclass_names = ['Subscript', 'Subscript_Triplet', 'Vector_Subscript']
+
+class Subscript_Triplet(Base):
+    """
+    <subscript-triplet> = [ <subscript> ] : [ <subscript> ] [ : <stride> ]
+    """
+    subclass_names = []
+    def match(string):
+        line, repmap = string_replace_map(string)
+        t = line.split(':')
+        if len(t)==1 or len(t)>3: return
+        lhs_obj,rhs_obj, stride_obj = None, None, None
+        if len(t)==2:
+            lhs,rhs = t[0].rstrip(),t[1].lstrip()
+        else:
+            lhs,rhs,stride = t[0].rstrip(),t[1].strip(),t[2].lstrip()
+            if stride:
+                for k in Base.findall(stride):
+                    stride = stride.replace(k, repmap[k])
+                stride_obj = Stride(stride)
+        if lhs:
+            for k in Base.findall(lhs):
+                lhs = lhs.replace(k, repmap[k])
+            lhs_obj = Subscript(lhs)
+        if rhs:
+            for k in Base.findall(rhs):
+                rhs = rhs.replace(k, repmap[k])
+            rhs_obj = Subscript(rhs)
+        return lhs_obj, rhs_obj, stride_obj
+    match = staticmethod(match)
+    def init(self, lhs, rhs, stride):
+        self.lhs, self.rhs, self.stride =lhs, rhs, stride
+        return
+    def tostr(self):
+        s = ''
+        if self.lhs is not None:
+            s += str(self.lhs) + ' :'
+        else:
+            s += ':'
+        if self.rhs is not None:
+            s += ' ' + str(self.rhs)
+        if self.stride is not None:
+            s += ' : ' + str(self.stride)
+        return s
+    def torepr(self):
+        return '%s(%r, %r, %r)' % (self.__class__.__name__,self.lhs, self.rhs, self.stride)        
+
+class Stride(Base):
+    """
+    <stride> = <scalar-int-expr>
+    """
+    subclass_names = ['Scalar_Int_Expr']
+
+class Vector_Subscript(Base):
+    """
+    <vector-subscript> = <int-expr>
+    """
+    subclass_names = ['Int_Expr']
+
+class Int_Expr(Base):
+    """
+    <int-expr> = <expr>
+    """
+    subclass_names = ['Expr']
+
+class Subscript(Base):
+    """
+    <subscript> = <scalar-int-expr>
+    """
+    subclass_names = ['Scalar_Int_Expr']
+
 class Part_Name(Base):
     """
     <part-name> = <name>
@@ -1304,47 +1371,29 @@
     """
     subclass_names = []
     def match(string):
-        return SequenceBase.match(r'%', Part_Ref, string)
+        r = SequenceBase.match('%', Part_Ref, string)
+        if len(r[1])==1: return r[1][0]
+        return r
     match = staticmethod(match)
 
-class Actual_Arg_Spec_List(Base):
+class Actual_Arg_Spec_List(SequenceBase):
     """
     <actual-arg-spec-list> = <actual-arg-spec> [ , <actual-arg-spec> ]...
     """
     subclass_names = []
     def match(string):
-        return Base.match_list_of(Actual_Arg_Spec, string)
+        r = SequenceBase.match(r',', Actual_Arg_Spec, string)
+        if len(r[1])==1: return r[1][0]
+        return r
     match = staticmethod(match)
-    init = Base.init_list
-    tostr = Base.tostr_list
-    torepr = Base.torepr_list
 
-class Actual_Arg_Spec(Base):
+class Actual_Arg_Spec(KeywordValueBase):
     """
     <actual-arg-spec> = [ <keyword> = ] <actual-arg>
     """
     subclass_names = []
-    def match(string):
-        if pattern.keyword_equal.match(string):
-            i = string.find('=')
-            assert i!=-1,`string`
-            kw = Keyword(string[:i].rstrip())
-            string = string[i+1:].lstrip()
-        else:
-            kw = None
-        return kw, Actual_Arg(string)
-
+    def match(string): return KeywordValueBase.match(Actual_Arg, string)
     match = staticmethod(match)
-    def init(self,kw,arg):
-        self.keyword = kw
-        self.actual_arg =arg
-        return
-    def tostr(self):
-        if self.keyword is not None:
-            return '%s = %s' % (self.keyword, self.actual_arg)
-        return str(self.actual_arg)
-    def torepr(self):
-        return '%s(%s, %s)' % (self.__class__.__name__, self.keyword, self.actual_arg)
 
 class Keyword(Base):
     """
@@ -1362,8 +1411,6 @@
         if pattern.abs_intrinsic_type_name.match(string): return
         return Name(string)
     match = staticmethod(match)
-    tostr = Base.tostr_string
-    torepr = Base.torepr_string        
     
 class Actual_Arg(Base):
     """
@@ -1372,19 +1419,32 @@
                  | <procedure-name>
                  | <proc-component-ref>
                  | <alt-return-spec>
+    """
+    subclass_names = ['Expr','Variable','Procedure_Name','Proc_Component_Ref','Alt_Return_Spec']
+
+class Alt_Return_Spec(Base):
+    """
     <alt-return-spec> = * <label>
-    <variable> = <designator>
-    <proc-component-ref> = <variable> % <procedure-component-name>
     """
-    subclass_names = ['Expr','Variable','Procedure_Name','Alt_Return_Spec']
-    extra_subclasses = [Expr]
+    subclass_names = []
+    def match(string):
+        if not string.startswith('*'): return
+        line = string[1:].lstrip()
+        if pattern.abs_label.match(line):
+            return line,
+        return
+    match = staticmethod(match)
+    def init(self, label):
+        self.label = label
+        return
+    def tostr(self): return '*%s' % (self.label)
+    def torepr(self): return '%s(%r)' % (self.__class__.__name__, self.label)
 
 class Variable(Base):
     """
     <variable> = <designator>
     """
     subclass_names = ['Designator']
-    extra_subclasses = [Designator]
 
 class Procedure_Component_Name(Base):
     """
@@ -1398,19 +1458,13 @@
     """
     subclass_names = ['Name']
     
-class Parenthesis(Base):
+class Parenthesis(BracketBase):
     """
     <parenthesis> = ( <expr> )
     """
     subclass_names = []
-    def match(string):
-        if string[0]+string[-1]=='()':
-            return '(',Expr(string[1:-1].strip()),')'
-        return None
+    def match(string): BracketBase.match('()', Expr, string)
     match = staticmethod(match)
-    init = Base.init_binary_operand
-    tostr = Base.tostr_binary_operand
-    torepr = Base.torepr_binary_operand
 
 class Name(Base):
     """
@@ -1424,6 +1478,8 @@
     match = staticmethod(match)
     tostr = Base.tostr_string
     torepr = Base.torepr_string
+
+##############################################################################
     
 ClassType = type(Base)
 Base_classes = {}
@@ -1435,7 +1491,8 @@
 for clsname, cls in Base_classes.items():
     subclass_names = getattr(cls, 'subclass_names', None)
     if subclass_names is None:
-        print '%s class is missing subclass_names list' % (clsname)
+        if clsname[-4:]!='Base':
+            print '%s class is missing subclass_names list' % (clsname)
         continue
     try:
         l = Base.subclasses[clsname]
@@ -1447,26 +1504,6 @@
         else:
             print '%s not implemented needed by %s' % (n,clsname)
 
-print 
-for clsname in dir():
-    break
-    cls = eval(clsname)
-    if isinstance(cls, ClassType) and issubclass(cls, Base):
-        extra_subclasses = cls.__dict__.get('extra_subclasses',[])
-        if extra_subclasses:
-            try:
-                l = Base.subclasses[cls.__name__]
-            except KeyError:
-                Base.subclasses[cls.__name__] = l = []
-            l.extend(extra_subclasses)
-        for basecls in cls.__bases__:
-            if basecls is Base: continue
-            if issubclass(basecls, Base):
-                try:
-                    Base.subclasses[basecls.__name__].append(cls)
-                except KeyError:
-                    Base.subclasses[basecls.__name__] = [cls]
-
 for cls in Base_classes.values():
     subclasses = Base.subclasses.get(cls.__name__,[])
     subclasses_names = [c.__name__ for c in subclasses]

Modified: trunk/numpy/f2py/lib/parser/pattern_tools.py
===================================================================
--- trunk/numpy/f2py/lib/parser/pattern_tools.py	2006-10-23 22:22:41 UTC (rev 3384)
+++ trunk/numpy/f2py/lib/parser/pattern_tools.py	2006-10-23 22:41:47 UTC (rev 3385)
@@ -209,8 +209,8 @@
 signed_digit_string = ~sign + digit_string
 int_literal_constant = digit_string + ~('_' + kind_param)
 signed_int_literal_constant = ~sign + int_literal_constant
-
 int_literal_constant_named = digit_string.named('value') + ~ ('_' + kind_param_named)
+signed_int_literal_constant_named = (~sign + digit_string).named('value') + ~ ('_' + kind_param_named)
 
 binary_constant = ('B' + ("'" & binary_digit_string & "'" | '"' & binary_digit_string & '"')).flags(re.I)
 octal_constant = ('O' + ("'" & octal_digit_string & "'" | '"' & octal_digit_string & '"')).flags(re.I)
@@ -223,6 +223,8 @@
                         digit_string + exponent_letter + exponent + ~ ('_' + kind_param)
 real_literal_constant_named = (significand + ~(exponent_letter + exponent) |\
                                digit_string + exponent_letter + exponent).named('value') +  ~ ('_' + kind_param_named)
+signed_real_literal_constant_named = (~sign + (significand + ~(exponent_letter + exponent) |\
+                               digit_string + exponent_letter + exponent)).named('value') +  ~ ('_' + kind_param_named)
 signed_real_literal_constant = ~sign + real_literal_constant
 
 named_constant = name
@@ -262,6 +264,7 @@
 defined_operator = defined_unary_op | defined_binary_op | extended_intrinsic_operator
 
 label = Pattern('<label>','\d{1,5}')
+abs_label = abs(label)
 
 keyword = name
 keyword_equal = keyword + '='
@@ -269,8 +272,12 @@
 abs_constant = abs(constant)
 abs_literal_constant = abs(literal_constant)
 abs_int_literal_constant = abs(int_literal_constant)
+abs_signed_int_literal_constant = abs(signed_int_literal_constant)
+abs_signed_int_literal_constant_named = abs(signed_int_literal_constant_named)
 abs_int_literal_constant_named = abs(int_literal_constant_named)
 abs_real_literal_constant = abs(real_literal_constant)
+abs_signed_real_literal_constant = abs(signed_real_literal_constant)
+abs_signed_real_literal_constant_named = abs(signed_real_literal_constant_named)
 abs_real_literal_constant_named = abs(real_literal_constant_named)
 abs_complex_literal_constant = abs(complex_literal_constant)
 abs_logical_literal_constant = abs(logical_literal_constant)

Modified: trunk/numpy/f2py/lib/parser/test_expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/test_expressions.py	2006-10-23 22:22:41 UTC (rev 3384)
+++ trunk/numpy/f2py/lib/parser/test_expressions.py	2006-10-23 22:41:47 UTC (rev 3385)
@@ -17,6 +17,15 @@
         assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
 
+class test_Designator(NumpyTestCase):
+
+    def check_substring(self):
+        cls = Substring
+        a = cls('a(1:2)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a(1 : 2)')
+        assert_equal(repr(a),"Substring(Name('a'), Substring_Range(Int_Literal_Constant('1', None), Int_Literal_Constant('2', None)))")
+
 class test_Procedure_Designator(NumpyTestCase):
 
     def check_part_ref(self):
@@ -32,7 +41,7 @@
         a = cls('(1)')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(KIND = 1)')
-        assert_equal(repr(a),"Kind_Selector('(', Int_Literal_Constant('1',None), ')')")
+        assert_equal(repr(a),"Kind_Selector('(', Int_Literal_Constant('1', None), ')')")
 
         a = cls('(kind=1+2)')
         assert isinstance(a,cls),`a`
@@ -62,7 +71,7 @@
         a = cls('1')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'1')
-        assert_equal(repr(a),"Char_Length(Int_Literal_Constant('1',None))")
+        assert_equal(repr(a),"Char_Length(Int_Literal_Constant('1', None))")
 
         a = cls('(1)')
         assert isinstance(a,cls),`a`
@@ -92,7 +101,7 @@
         a = cls('(len=2, kind=8)')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(LEN = 2, KIND = 8)')
-        assert_equal(repr(a),"Char_Selector(Int_Literal_Constant('2',None), Int_Literal_Constant('8',None))")
+        assert_equal(repr(a),"Char_Selector(Int_Literal_Constant('2', None), Int_Literal_Constant('8', None))")
 
 
         a = cls('(2, kind=8)')
@@ -148,10 +157,10 @@
 
     def check_type_param_spec(self):
         cls = Type_Param_Spec
-        a = cls('a')
+        a = cls('a=1')
         assert isinstance(a,cls),`a`
-        assert_equal(str(a),'a')
-        assert_equal(repr(a),"Type_Param_Spec(None, Name('a'))")
+        assert_equal(str(a),'a = 1')
+        assert_equal(repr(a),"Type_Param_Spec(Name('a'), '=', Int_Literal_Constant('1', None))")
 
         a = cls('k=a')
         assert isinstance(a,cls),`a`
@@ -163,15 +172,15 @@
 
     def check_type_param_spec_list(self):
         cls = Type_Param_Spec_List
-        a = cls('a')
-        assert isinstance(a,cls),`a`
-        assert_equal(str(a),'a')
-        assert_equal(repr(a),"Type_Param_Spec_List(Type_Param_Spec(None, Name('a')))")
 
         a = cls('a,b')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'a, b')
+        assert_equal(repr(a),"Type_Param_Spec_List(',', (Name('a'), Name('b')))")
 
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+
         a = cls('k=a,c,g=1')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'k = a, c, g = 1')
@@ -198,6 +207,61 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'f(2, k = 1, a)')
 
+    def check_alt_return_spec(self):
+        cls = Alt_Return_Spec
+        a = cls('* 123')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'*123')
+        assert_equal(repr(a),"Alt_Return_Spec('123')")
+        
+    def check_substring_range(self):
+        cls = Substring_Range
+        a = cls('a:b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a : b')
+        assert_equal(repr(a),"Substring_Range(Name('a'), Name('b'))")
+
+        a = cls('a:')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a :')
+
+        a = cls(':b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),': b')
+
+        a = cls(':')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),':')
+
+    def check_array_section(self):
+        cls = Array_Section
+        a = cls('a(:)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a(:)')
+        assert_equal(repr(a),"Array_Section(Name('a'), Substring_Range(None, None))")
+
+        a = cls('a(2:)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a(2 :)')
+
+    def check_procedure_designator(self):
+        cls = Procedure_Designator
+        a = cls('a%b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a % b')
+        assert_equal(repr(a),"Procedure_Designator(Name('a'), '%', Name('b'))")
+        
+    def check_data_ref(self):
+        cls = Data_Ref
+        a = cls('a%b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a % b')
+        assert_equal(repr(a),"Data_Ref('%', (Name('a'), Name('b')))")
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
 class test_Structure_Constructor(NumpyTestCase):
 
     def check_proc_component_ref(self):
@@ -219,9 +283,13 @@
         assert_equal(str(a),'t(s = 1, a)')
 
         a = cls('a=k')
-        assert isinstance(a,cls),`a`
+        assert isinstance(a,Structure_Constructor_2),`a`
         assert_equal(str(a),'a = k')
-        assert_equal(repr(a),"Structure_Constructor(Name('a'), Name('k'))")
+        assert_equal(repr(a),"Structure_Constructor_2(Name('a'), '=', Name('k'))")
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
     
 class test_Array_Constructor(NumpyTestCase):
 
@@ -230,7 +298,7 @@
         a = cls('n = 3, 5')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'n = 3, 5')
-        assert_equal(repr(a),"Ac_Implied_Do_Control(Name('n'), [Int_Literal_Constant('3',None), Int_Literal_Constant('5',None)])")
+        assert_equal(repr(a),"Ac_Implied_Do_Control(Name('n'), [Int_Literal_Constant('3', None), Int_Literal_Constant('5', None)])")
 
         a = cls('n = 3+1, 5, 1')
         assert isinstance(a,cls),`a`
@@ -241,10 +309,10 @@
         a = cls('a, b')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'a, b')
-        assert_equal(repr(a),"Ac_Value_List(Name('a'), Name('b'))")
+        assert_equal(repr(a),"Ac_Value_List(',', (Name('a'), Name('b')))")
 
         a = cls('a')
-        assert isinstance(a,cls),`a`
+        assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
         
     def check_ac_implied_do(self):
@@ -252,7 +320,7 @@
         a = cls('( a, b, n = 1, 5 )')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(a, b, n = 1, 5)')
-        assert_equal(repr(a),"Ac_Implied_Do(Ac_Value_List(Name('a'), Name('b')), Ac_Implied_Do_Control(Name('n'), [Int_Literal_Constant('1',None), Int_Literal_Constant('5',None)]))")
+        assert_equal(repr(a),"Ac_Implied_Do(Ac_Value_List(',', (Name('a'), Name('b'))), Ac_Implied_Do_Control(Name('n'), [Int_Literal_Constant('1', None), Int_Literal_Constant('5', None)]))")
 
     def check_ac_spec(self):
         cls = Ac_Spec
@@ -292,12 +360,12 @@
         a = cls('1')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'1')
-        assert_equal(repr(a),"%s('1',None)" % (cls.__name__))
+        assert_equal(repr(a),"%s('1', None)" % (cls.__name__))
 
         a = cls('21_2')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'21_2')
-        assert_equal(repr(a),"%s('21','2')" % (cls.__name__))
+        assert_equal(repr(a),"%s('21', '2')" % (cls.__name__))
 
         a = cls('21_SHORT')
         assert isinstance(a,cls),`a`
@@ -316,12 +384,12 @@
         a = cls('12.78')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'12.78')
-        assert_equal(repr(a),"%s('12.78',None)" % (cls.__name__))
+        assert_equal(repr(a),"%s('12.78', None)" % (cls.__name__))
 
         a = cls('12.78_8')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'12.78_8')
-        assert_equal(repr(a),"%s('12.78','8')" % (cls.__name__))
+        assert_equal(repr(a),"%s('12.78', '8')" % (cls.__name__))
 
         a = cls('12.')
         assert isinstance(a,cls),`a`
@@ -371,7 +439,7 @@
         a = cls('(1.0, -1.0)')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(1.0, -1.0)')
-        assert_equal(repr(a),"%s(Real_Part(None, Real_Literal_Constant('1.0',None)), Imag_Part('-', Real_Literal_Constant('1.0',None)))" % (cls.__name__))
+        assert_equal(repr(a),"Complex_Literal_Constant(Signed_Real_Literal_Constant('1.0', None), Signed_Real_Literal_Constant('-1.0', None))")
 
         a = cls('(3,3.1E6)')
         assert isinstance(a,cls),`a`




More information about the Numpy-svn mailing list