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

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Oct 24 16:51:49 CDT 2006


Author: pearu
Date: 2006-10-24 16:51:42 -0500 (Tue, 24 Oct 2006)
New Revision: 3391

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: finished Fortran expression parser implementation, comes with complete unittests.

Modified: trunk/numpy/f2py/lib/parser/expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/expressions.py	2006-10-24 07:26:55 UTC (rev 3390)
+++ trunk/numpy/f2py/lib/parser/expressions.py	2006-10-24 21:51:42 UTC (rev 3391)
@@ -38,11 +38,13 @@
     subclasses = {}
 
     def __new__(cls, string):
+        #print '__new__:',cls.__name__,`string`
         match = cls.__dict__.get('match', None)
         if match is not None:
             result = cls.match(string)
         else:
             result = None
+        #print '__new__:result:',cls.__name__,`string,result`
         if isinstance(result, tuple):
             obj = object.__new__(cls)
             obj.string = string
@@ -53,6 +55,7 @@
             return result
         elif result is None:
             for subcls in Base.subclasses.get(cls.__name__,[]):
+                #print cls.__name__,subcls.__name__,`string`
                 try:
                     return subcls(string)
                 except NoMatchError:
@@ -73,12 +76,6 @@
     def torepr_list(self):
         return '%s(%s)' % (self.__class__.__name__,', '.join(map(repr,self.items)))
 
-    def tostr_string(self):
-        return str(self.string)
-
-    def torepr_string(self):
-        return '%s(%r)' % (self.__class__.__name__,self.string)
-
     def __str__(self):
         return self.tostr()
         if self.__class__.__dict__.has_key('tostr'):
@@ -103,6 +100,7 @@
             for k in Base.findall(p):
                 p = p.replace(k,repmap[k])
             lst.append(subcls(p))
+        if len(lst)==1: return lst[0]
         return separator, tuple(lst)
     match = staticmethod(match)
     def init(self, separator, items):
@@ -129,16 +127,12 @@
     def torepr(self):
         return '%s(%r, %r)' % (self.__class__.__name__,self.op, self.rhs)
     def match(op_pattern, rhs_cls, string):
-        line, repmap = string_replace_map(string)
-        t = op_pattern.lsplit(line)
-        if t is None:
-            return rhs_cls(string)
-        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
+        m = op_pattern.match(string)
+        if not m: return rhs_cls(string)
+        rhs = string[m.end():].lstrip()        
+        if not rhs: return
+        op = string[:m.end()].rstrip().upper()
+        return op, rhs_cls(rhs)
     match = staticmethod(match)
 
 class BinaryOpBase(Base):
@@ -150,15 +144,16 @@
         t = op_pattern.rsplit(line)
         if t is None or len(t)!=3: return
         lhs, op, rhs = t
-        if lhs is None: return
-        if rhs is None: return
+        if not lhs: return
+        if not rhs: return
+        op = op.upper()
         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
+        return lhs_obj, op, rhs_obj
     match = staticmethod(match)
     def init(self, lhs, op, rhs):
         self.lhs = lhs
@@ -180,13 +175,15 @@
         if t is None:
             return rhs_cls(string)
         lhs, op, rhs = t
+        if not lhs: return
+        op = op.upper()
         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
+        return lhs_obj, op, rhs_obj
     match = staticmethod(match)
 
 class LBinaryOpBase(BinaryOpBase):
@@ -199,13 +196,15 @@
         if t is None:
             return lhs_cls(string)
         lhs, op, rhs = t
+        if not rhs: return
+        op = op.upper()
         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
+        return lhs_obj, op, rhs_obj
     match = staticmethod(match)
 
 class KeywordValueBase(BinaryOpBase):
@@ -223,10 +222,13 @@
     <bracket-base> = <left-bracket-base> <something> <right-bracket>
     """
     def match(brackets, cls, string):
-        left = brackets[:len(brackets)/2]
-        right = brackets[-len(brackets)/2:]
+        i = len(brackets)/2
+        left = brackets[:i]
+        right = brackets[-i:]
         if string.startswith(left) and string.endswith(right):
-            return left,cls(string[len(left):-len(right)].strip())
+            line = string[i:-i].strip()
+            if not line: return
+            return left,cls(line),right
         return
     match = staticmethod(match)
     def init(self,left,item,right):
@@ -234,8 +236,11 @@
         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)
+    def tostr(self):
+        if self.item is None:
+            return '%s%s' % (self.left, self.right)
+        return '%s%s%s' % (self.left, self.item, self.right)
+    def torepr(self): return '%s(%r, %r, %r)' % (self.__class__.__name__, self.left, self.item, self.right)
 
 class NumberBase(Base):
     """
@@ -258,29 +263,83 @@
 
 class CallBase(Base):
     """
-    <call-base> = <lhs> ( <rhs> )
+    <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]
+        lhs = line[:i].rstrip()
+        if not lhs: return
         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)
+        if rhs:
+            for k in Base.findall(rhs):
+                rhs = rhs.replace(k,repmap[k])
+            return lhs_cls(lhs), rhs_cls(rhs)
+        return lhs_cls(lhs), None
     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 tostr(self):
+        if self.rhs is None: return '%s()' % (self.lhs)
+        return '%s(%s)' % (self.lhs, self.rhs)
     def torepr(self): return '%s(%r, %r)' % (self.__class__.__name__, self.lhs, self.rhs)
 
+class StringBase(Base):
+    """
+    <string-base> = <xyz>
+    """
+    def match(pattern, string):
+        if pattern.match(string): return string,
+        return
+    match = staticmethod(match)
+    def init(self, string):
+        self.string = string
+        return
+    def tostr(self): return str(self.string)
+    def torepr(self): return '%s(%r)' % (self.__class__.__name__, self.string)
+
 ##################################################
+
+class Name(StringBase):
+    """
+    <name> = <letter> [ <alphanumeric_character> ]...
+    """
+    subclass_names = []
+    def match(string): return StringBase.match(pattern.abs_name, string)
+    match = staticmethod(match)
+
+class Binary_Constant(StringBase):
+    """
+    <binary-constant> = B ' <digit> [ <digit> ]... '
+                        | B \" <digit> [ <digit> ]... \"
+    """
+    subclass_names = []
+    def match(string): return StringBase.match(pattern.abs_binary_constant, string)
+    match = staticmethod(match)
+
+class Octal_Constant(StringBase):
+    """
+    <octal-constant> = O ' <digit> [ <digit> ]... '
+                       | O \" <digit> [ <digit> ]... \"
+    """
+    subclass_names = []
+    def match(string): return StringBase.match(pattern.abs_octal_constant, string)
+    match = staticmethod(match)
+
+class Hex_Constant(StringBase):
+    """
+    <hex-constant> = Z ' <digit> [ <digit> ]... '
+                     | Z \" <digit> [ <digit> ]... \"
+    """
+    subclass_names = []
+    def match(string): return StringBase.match(pattern.abs_hex_constant, string)
+    match = staticmethod(match)
     
 class Expr(RBinaryOpBase):
     """
@@ -289,6 +348,7 @@
     TODO: defined_binary_op must not be intrinsic_binary_op!!
     """
     subclass_names = []
+    use_names = ['Expr', 'Level_5_Expr']
     def match(string):
         return RBinaryOpBase.match(Expr, pattern.defined_binary_op.named(), Level_5_Expr,
                                    string)
@@ -301,6 +361,7 @@
                | .NEQV.
     """
     subclass_names = []
+    use_names = ['Level_5_Expr','Equiv_Operand']
     def match(string):
         return RBinaryOpBase.match(\
             Level_5_Expr,pattern.equiv_op.named(),Equiv_Operand,string)
@@ -312,6 +373,7 @@
     <or-op>  = .OR.
     """
     subclass_names = []
+    use_names = ['Equiv_Operand','Or_Operand']
     def match(string):
         return RBinaryOpBase.match(\
             Equiv_Operand,pattern.or_op.named(),Or_Operand,string)
@@ -323,6 +385,7 @@
     <and-op> = .AND.
     """
     subclass_names = []
+    use_names = ['Or_Operand','And_Operand']
     def match(string):
         return RBinaryOpBase.match(\
             Or_Operand,pattern.and_op.named(),And_Operand,string)
@@ -334,6 +397,7 @@
     <not-op> = .NOT.
     """
     subclass_names = []
+    use_names = ['Level_4_Expr']
     def match(string):
         return UnaryOpBase.match(\
             pattern.not_op.named(),Level_4_Expr,string)
@@ -345,6 +409,7 @@
     <rel-op> = .EQ. | .NE. | .LT. | .LE. | .GT. | .GE. | == | /= | < | <= | > | >=
     """
     subclass_names = []
+    use_names = ['Level_3_Expr']
     def match(string):
         return RBinaryOpBase.match(\
             Level_3_Expr,pattern.rel_op.named(),Level_3_Expr,string)
@@ -356,37 +421,38 @@
     <concat-op>    = //
     """
     subclass_names = []
+    use_names =['Level_3_Expr','Level_2_Expr']
     def match(string):
         return RBinaryOpBase.match(\
             Level_3_Expr,pattern.concat_op.named(),Level_2_Expr,string)
     match = staticmethod(match)
-    
-class Level_2_Expr(BinaryOpBase):
+
+class Level_2_Expr(RBinaryOpBase):
     """
     <level-2-expr> = [ [ <level-2-expr> ] <add-op> ] <add-operand>
+    <level-2-expr> = [ <level-2-expr> <add-op> ] <add-operand>
+                     | <level-2-unary-expr>
     <add-op>   = +
                  | -
     """
+    subclass_names = ['Level_2_Unary_Expr']
+    use_names = ['Level_2_Expr','Add_Operand']
+    def match(string):
+        return RBinaryOpBase.match(\
+            Level_2_Expr,pattern.add_op.named(),Add_Operand,string)
+    match = staticmethod(match)
+
+class Level_2_Unary_Expr(UnaryOpBase):
+    """
+    <level-2-unary-expr> = [ <add-op> ] <add-operand>
+    """
     subclass_names = []
+    use_names = ['Add_Operand']
     def match(string):
-        lhs_cls, op_pattern, rhs_cls = Level_2_Expr,pattern.add_op.named(),Add_Operand
-        line, repmap = string_replace_map(string)
-        t = op_pattern.rsplit(line)
-        if t is None:
-            return rhs_cls(string)
-        lhs, op, rhs = t
-        if lhs is not None:
-            for k in Base.findall(lhs):
-                lhs = lhs.replace(k, repmap[k])
-            lhs_obj = lhs_cls(lhs)
-        else:
-            lhs_obj = None
-        for k in Base.findall(rhs):
-            rhs = rhs.replace(k, repmap[k])
-        rhs_obj = rhs_cls(rhs)
-        return lhs_obj, t[1], rhs_obj
+        return UnaryOpBase.match(\
+            pattern.add_op.named(),Add_Operand,string)
     match = staticmethod(match)
-    
+
 class Add_Operand(RBinaryOpBase):
     """
     <add-operand> = [ <add-operand> <mult-op> ] <mult-operand>
@@ -394,6 +460,7 @@
                  | /
     """
     subclass_names = []
+    use_names = ['Add_Operand','Mult_Operand']
     def match(string):
         return RBinaryOpBase.match(\
             Add_Operand,pattern.mult_op.named(),Mult_Operand,string)
@@ -405,6 +472,7 @@
     <power-op> = **
     """
     subclass_names = []
+    use_names = ['Level_1_Expr','Mult_Operand']
     def match(string):
         return LBinaryOpBase.match(\
             Level_1_Expr,pattern.power_op.named(),Mult_Operand,string)
@@ -416,7 +484,9 @@
     <defined-unary-op> = . <letter> [ <letter> ]... .
     """
     subclass_names = []
+    use_names = ['Primary']
     def match(string):
+        if pattern.non_defined_binary_op.match(string): return
         return UnaryOpBase.match(\
             pattern.defined_unary_op.named(),Primary,string)
     match = staticmethod(match)
@@ -432,8 +502,8 @@
                 | <type-param-name>
                 | ( <expr> )
     """
-    subclass_names = ['Constant', 'Designator','Array_Constructor','Structure_Constructor',
-                      'Function_Reference', 'Type_Param_Inquiry', 'Type_Param_Name', 'Parenthesis']
+    subclass_names = ['Parenthesis', 'Constant', 'Designator','Array_Constructor','Structure_Constructor',
+                      'Function_Reference', 'Type_Param_Inquiry', 'Type_Param_Name']
 
 class Type_Param_Name(Base):
     """
@@ -446,6 +516,7 @@
     <type-param-inquiry> = <designator> % <type-param-name>
     """
     subclass_names = []
+    use_names = ['Designator','Type_Param_Name']
     def match(string):
         return BinaryOpBase.match(\
             Designator, pattern.percent_op.named(), Type_Param_Name, string)
@@ -456,35 +527,19 @@
     <structure-constructor-2> = [ <keyword> = ] <component-data-source>
     """
     subclass_names = []
+    use_names = ['Keyword', 'Component_Data_Source']
     def match(string): return KeywordValueBase.match(Component_Data_Source, string)
     match = staticmethod(match)
 
-class Structure_Constructor(Base):
+class Structure_Constructor(CallBase):
     """
     <structure-constructor> = <derived-type-spec> ( [ <component-spec-list> ] )
-                            | [ <keyword> = ] <component-data-source>
+                            | <structure-constructor-2>
     """
     subclass_names = ['Structure_Constructor_2']
-    def match(string):
-        if string[-1]!=')': return
-        line, repmap = string_replace_map(string)
-        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),')'
+    use_names = ['Derived_Type_Spec', 'Component_Spec_List']
+    def match(string): return CallBase.match(Derived_Type_Spec, Component_Spec_List, string)
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        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):
     """
@@ -492,7 +547,7 @@
                               | <data-target>
                               | <proc-target>
     """
-    subclass_names = ['Expr','Data_Target','Proc_Target']
+    subclass_names = ['Proc_Target', 'Data_Target', 'Expr']
 
 class Data_Target(Base):
     """
@@ -507,13 +562,14 @@
                     | <procedure-name>
                     | <proc-component-ref>
     """
-    subclass_names = ['Procedure_Name','Proc_Component_Ref', 'Expr']
+    subclass_names = ['Proc_Component_Ref', 'Procedure_Name', 'Expr']
 
 class Proc_Component_Ref(BinaryOpBase):
     """
     <proc-component-ref> = <variable> % <procedure-component-name>
     """
     subclass_names = []
+    use_names = ['Variable','Procedure_Component_Name']
     def match(string):
         return BinaryOpBase.match(\
             Variable, pattern.percent_op.named(), Procedure_Component_Name, string)            
@@ -524,6 +580,7 @@
     <component-spec> = [ <keyword> = ] <component-data-source>
     """
     subclass_names = []
+    use_names = ['Keyword','Component_Data_Source']
     def match(string): return KeywordValueBase.match(Component_Data_Source, string)
     match = staticmethod(match)
 
@@ -532,6 +589,7 @@
     <component-spec-list> = <component-spec> [ , <component-spec> ]...
     """
     subclass_names = []
+    use_names = ['Component_Spec']
     def match(string): return SequenceBase.match(r',', Component_Spec, string)
     match = staticmethod(match)
 
@@ -542,6 +600,7 @@
 
     """
     subclass_names = []
+    use_names = ['Ac_Spec']
     def match(string):
         try:
             obj = BracketBase.match('(//)', Ac_Spec, string)
@@ -557,14 +616,14 @@
     <ac-spec> = <type-spec> ::
                 | [ <type-spec> :: ] <ac-value-list>
     """
-    subclass_names = []
+    subclass_names = ['Ac_Value_List']
+    use_names = ['Type_Spec']
     def match(string):
         if string.endswith('::'):
             return Type_Spec(string[:-2].rstrip()),None
         line, repmap = string_replace_map(string)
         i = line.find('::')
-        if i==-1:
-            return None, Ac_Value_List(string)
+        if i==-1: return
         ts = line[:i].rstrip()
         line = line[i+2:].lstrip()
         for k in Base.findall(ts):
@@ -588,10 +647,8 @@
     <ac-value-list> = <ac-value> [ , <ac-value> ]...
     """
     subclass_names = []
-    def match(string):
-        r = SequenceBase.match(r',', Ac_Value, string)
-        if len(r[1])==1: return r[1][0]
-        return r
+    use_names = ['Ac_Value']
+    def match(string): return SequenceBase.match(r',', Ac_Value, string)
     match = staticmethod(match)
 
 class Ac_Value(Base):
@@ -606,6 +663,7 @@
     <ac-implied-do> = ( <ac-value-list> , <ac-implied-do-control> )
     """
     subclass_names = []
+    use_names = ['Ac_Value_List','Ac_Implied_Do_Control']    
     def match(string):
         if string[0]+string[-1] != '()': return
         line, repmap = string_replace_map(string[1:-1].strip())
@@ -630,6 +688,7 @@
     <ac-implied-do-control> = <ac-do-variable> = <scalar-int-expr> , <scalar-int-expr> [ , <scalar-int-expr> ]    
     """
     subclass_names = []
+    use_names = ['Ac_Do_Variable','Scalar_Int_Expr']
     def match(string):
         i = string.find('=')
         if i==-1: return
@@ -677,6 +736,8 @@
                             | BYTE
     """
     subclass_names = []
+    use_names = ['Kind_Selector','Char_Selector']
+        
     def match(string):
         if string[:7].upper()=='INTEGER':
             t = string[:7].upper()
@@ -725,6 +786,8 @@
                       | * <char-length>
     """
     subclass_names = []
+    use_names = ['Scalar_Int_Initialization_Expr','Char_Length']
+
     def match(string):
         if string[0]+string[-1] != '()':
             if not string.startswith('*'): return
@@ -753,7 +816,8 @@
                       | ( <type-param-value> , [ KIND = ] <scalar-int-initialization-expr> )
                       | ( KIND = <scalar-int-initialization-expr> [ , LEN = <type-param-value> ] )
     """
-    subclass_names = ['Lenght_Selector']
+    subclass_names = ['Length_Selector']
+    use_names = ['Type_Param_Value','Scalar_Int_Initialization_Expr']
     def match(string):
         if string[0]+string[-1] != '()': return
         line, repmap = string_replace_map(string[1:-1].strip())
@@ -805,12 +869,13 @@
     def torepr(self):
         return '%s(%r, %r)' % (self.__class__.__name__, self.items[0],self.items[1])
     
-class Lenght_Selector(Base):
+class Length_Selector(Base):
     """
-    <length-selector> = ( [ LEN = ] <type-param-value> )
+    <length -selector> = ( [ LEN = ] <type-param-value> )
                         | * <char-length> [ , ]
     """
     subclass_names = []
+    use_names = ['Type_Param_Value','Char_Length']
     def match(string):
         if string[0]+string[-1] == '()':
             line = string[1:-1].strip()
@@ -839,6 +904,7 @@
                     | <scalar-int-literal-constant>
     """
     subclass_names = []
+    use_names = ['Type_Param_Value','Scalar_Int_Literal_Constant']
     def match(string):
         if string[0]+string[-1] == '()':
             return '(',Type_Param_Value(string[1:-1].strip()),')'
@@ -873,6 +939,7 @@
                        | :
     """
     subclass_names = ['Scalar_Int_Expr']
+    use_names = ['Scalar_Int_Expr']
     def match(string):
         if string in ['*',':']: return string,
         return
@@ -881,41 +948,31 @@
     def tostr(self): return str(self.value)
     def torepr(self): return '%s(%r)' % (self.__class__.__name__, self.value)
 
-class Derived_Type_Spec(Base):
+class Derived_Type_Spec(CallBase):
     """
     <derived-type-spec> = <type-name> [ ( <type-param-spec-list> ) ]
     """
-    subclass_names = []
-    def match(string):
-        i = string.find('(')
-        if i==-1: return Type_Name(string),None
-        if string[-1] != ')': return
-        return Type_Name(string[:i].rstrip()), Type_Param_Spec_List(string[i+1:-1].strip())
+    subclass_names = ['Type_Name']
+    use_names = ['Type_Param_Spec_List']
+    def match(string): return CallBase.match(Type_Name, Type_Param_Spec_List, string)
     match = staticmethod(match)
-    init = Base.init_list
-    def tostr(self):
-        if self.items[1] is None: return str(self.items[0])
-        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(KeywordValueBase):
     """
     <type-param-spec> = [ <keyword> = ] <type-param-value>
     """
     subclass_names = []
+    use_names = ['Keyword','Type_Param_Value']
     def match(string): return KeywordValueBase.match(Type_Param_Value, string)
     match = staticmethod(match)
 
 class Type_Param_Spec_List(SequenceBase):
     """
-    <type-param-spec-list> = <type-param> [ , <type-param> ]...
+    <type-param-spec-list> = <type-param-spec> [ , <type-param-spec> ]...
     """
     subclass_names = []
-    def match(string):
-        r = SequenceBase.match(',', Type_Param_Spec, string)
-        if len(r[1])==1: return r[1][0]
-        return r
+    use_names = ['Type_Param_Spec']
+    def match(string): return SequenceBase.match(',', Type_Param_Spec, string)
     match = staticmethod(match)
 
 
@@ -945,6 +1002,7 @@
     <substring> = <parent-string> ( <substring-range> )    
     """
     subclass_names = []
+    use_names = ['Parent_String','Substring_Range']
     def match(string): return CallBase.match(Parent_String, Substring_Range, string)
     match = staticmethod(match)
 
@@ -986,6 +1044,7 @@
     <array-section> = <data-ref> [ ( <substring-range> ) ]
     """
     subclass_names = ['Data_Ref']
+    use_names = ['Data_Ref','Substring_Range']
     def match(string): return CallBase.match(Data_Ref, Substring_Range, string)
     match = staticmethod(match)
 
@@ -994,6 +1053,7 @@
     <substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
     """
     subclass_names = []
+    use_names = ['Scalar_Int_Expr']
     def match(string):
         line, repmap = string_replace_map(string)
         if ':' not in line: return
@@ -1057,7 +1117,7 @@
     """
     <signed-int-literal-constant> = [ <sign> ] <int-literal-constant>
     """
-    subclass_names = []
+    subclass_names = ['Int_Literal_Constant'] # never used because sign is included in pattern
     def match(string):
         return NumberBase.match(pattern.abs_signed_int_literal_constant_named, string)
     match = staticmethod(match)
@@ -1080,7 +1140,7 @@
     """
     <signed-real-literal-constant> = [ <sign> ] <real-literal-constant>
     """
-    subclass_names = []
+    subclass_names = ['Real_Literal_Constant'] # never used
     def match(string):
         return NumberBase.match(pattern.abs_signed_real_literal_constant_named, string)
     match = staticmethod(match)
@@ -1090,6 +1150,7 @@
     <complex-literal-constant> = ( <real-part>, <imag-part> )
     """
     subclass_names = []
+    use_names = ['Real_Part','Imag_Part']
     def match(string):
         if string[0]+string[-1]!='()': return
         if not pattern.abs_complex_literal_constant.match(string):
@@ -1131,7 +1192,7 @@
             abs_a_n_char_literal_constant_named = pattern.abs_a_n_char_literal_constant_named1
         line, repmap = string_replace_map(string)
         m = abs_a_n_char_literal_constant_named.match(line)
-        if m is None: return
+        if not m: return
         kind_param = m.group('kind_param')
         line = m.group('value')
         for k in Base.findall(line):
@@ -1162,45 +1223,8 @@
     """
     subclass_names = ['Binary_Constant','Octal_Constant','Hex_Constant']
 
-class Binary_Constant(Base):
-    """
-    <binary-constant> = B ' <digit> [ <digit> ]... '
-                        | B \" <digit> [ <digit> ]... \"
-    """
-    subclass_names = []
-    def match(string):
-        if pattern.abs_binary_constant.match(string): return (string,)
-        return
-    match = staticmethod(match)
-    tostr = Base.tostr_string
-    torepr = Base.torepr_string
 
-class Octal_Constant(Base):
-    """
-    <octal-constant> = O ' <digit> [ <digit> ]... '
-                       | O \" <digit> [ <digit> ]... \"
-    """
-    subclass_names = []
-    def match(string):
-        if pattern.abs_octal_constant.match(string): return (string,)
-        return
-    match = staticmethod(match)
-    tostr = Base.tostr_string
-    torepr = Base.torepr_string
 
-class Hex_Constant(Base):
-    """
-    <hex-constant> = Z ' <digit> [ <digit> ]... '
-                     | Z \" <digit> [ <digit> ]... \"
-    """
-    subclass_names = []
-    def match(string):
-        if pattern.abs_hex_constant.match(string): return (string,)
-        return
-    match = staticmethod(match)
-    tostr = Base.tostr_string
-    torepr = Base.torepr_string
-
 class Named_Constant(Base):
     """
     <named-constant> = <name>
@@ -1218,6 +1242,7 @@
     <function-reference> = <procedure-designator> ( [ <actual-arg-spec-list> ] )
     """
     subclass_names = []
+    use_names = ['Procedure_Designator','Actual_Arg_Spec_List']
     def match(string):
         if string[-1] != ')': return None
         line, repmap = string_replace_map(string)
@@ -1242,7 +1267,6 @@
         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 Procedure_Designator(BinaryOpBase):
@@ -1252,6 +1276,7 @@
                              | <data-ref> % <binding-name>
     """
     subclass_names = ['Procedure_Name','Proc_Component_Ref']
+    use_names = ['Data_Ref','Binding_Name']
     def match(string):
         return BinaryOpBase.match(\
             Data_Ref, pattern.percent_op.named(),  Binding_Name, string)
@@ -1262,6 +1287,7 @@
     <part-ref> = <part-name> [ ( <section-subscript-list> ) ]
     """
     subclass_names = ['Part_Name']
+    use_names = ['Part_Name','Section_Subscript_List']
     def match(string): return CallBase.match(Part_Name, Section_Subscript_List, string)
     match = staticmethod(match)
 
@@ -1270,10 +1296,8 @@
     <section-subscript-list> = <section-subscript> [ , <section-subscript> ]...
     """
     subclass_names = []
-    def match(string):
-        r = SequenceBase.match(',', Section_Subscript, string)
-        if len(r[1])==1: return r[1][0]
-        return r
+    use_names = ['Section_Subscript']
+    def match(string): return SequenceBase.match(',', Section_Subscript, string)
     match = staticmethod(match)
 
 class Section_Subscript(Base):
@@ -1282,17 +1306,18 @@
                           | <subscript-triplet>
                           | <vector-subscript>
     """
-    subclass_names = ['Subscript', 'Subscript_Triplet', 'Vector_Subscript']
+    subclass_names = ['Subscript_Triplet', 'Vector_Subscript', 'Subscript']
 
 class Subscript_Triplet(Base):
     """
     <subscript-triplet> = [ <subscript> ] : [ <subscript> ] [ : <stride> ]
     """
     subclass_names = []
+    use_names = ['Subscript','Stride']
     def match(string):
         line, repmap = string_replace_map(string)
         t = line.split(':')
-        if len(t)==1 or len(t)>3: return
+        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()
@@ -1370,10 +1395,8 @@
     <data-ref> = <part-ref> [ % <part-ref> ]...
     """
     subclass_names = []
-    def match(string):
-        r = SequenceBase.match('%', Part_Ref, string)
-        if len(r[1])==1: return r[1][0]
-        return r
+    use_names = ['Part_Ref']
+    def match(string): return SequenceBase.match('%', Part_Ref, string)
     match = staticmethod(match)
 
 class Actual_Arg_Spec_List(SequenceBase):
@@ -1381,10 +1404,8 @@
     <actual-arg-spec-list> = <actual-arg-spec> [ , <actual-arg-spec> ]...
     """
     subclass_names = []
-    def match(string):
-        r = SequenceBase.match(r',', Actual_Arg_Spec, string)
-        if len(r[1])==1: return r[1][0]
-        return r
+    use_names = ['Actual_Arg_Spec']
+    def match(string): return SequenceBase.match(r',', Actual_Arg_Spec, string)
     match = staticmethod(match)
 
 class Actual_Arg_Spec(KeywordValueBase):
@@ -1392,6 +1413,7 @@
     <actual-arg-spec> = [ <keyword> = ] <actual-arg>
     """
     subclass_names = []
+    use_names = ['Keyword','Actual_Arg']
     def match(string): return KeywordValueBase.match(Actual_Arg, string)
     match = staticmethod(match)
 
@@ -1407,6 +1429,7 @@
     <type-name> shall not be DOUBLEPRECISION or the name of intrinsic type
     """
     subclass_names = []
+    use_names = ['Name']
     def match(string):
         if pattern.abs_intrinsic_type_name.match(string): return
         return Name(string)
@@ -1463,21 +1486,10 @@
     <parenthesis> = ( <expr> )
     """
     subclass_names = []
-    def match(string): BracketBase.match('()', Expr, string)
+    use_names = ['Expr']
+    def match(string): return BracketBase.match('()', Expr, string)
     match = staticmethod(match)
 
-class Name(Base):
-    """
-    <name> = <letter> [ <alphanumeric_character> ]...
-    """
-    subclass_names = []
-    def match(string):
-        if pattern.abs_name.match(string):
-            return string,
-        return
-    match = staticmethod(match)
-    tostr = Base.tostr_string
-    torepr = Base.torepr_string
 
 ##############################################################################
     
@@ -1504,15 +1516,20 @@
         else:
             print '%s not implemented needed by %s' % (n,clsname)
 
-for cls in Base_classes.values():
-    subclasses = Base.subclasses.get(cls.__name__,[])
-    subclasses_names = [c.__name__ for c in subclasses]
-    subclass_names = getattr(cls,'subclass_names', [])
-    for n in subclasses_names:
-        if n not in subclass_names:
-            print '%s needs to be added to %s subclasses_name list' % (n,cls.__name__)
-    for n in subclass_names:
-        if n not in subclasses_names:
-            print '%s needs to be added to %s subclass_name list' % (n,cls.__name__)
+if 0:
+    for cls in Base_classes.values():
+        subclasses = Base.subclasses.get(cls.__name__,[])
+        subclasses_names = [c.__name__ for c in subclasses]
+        subclass_names = getattr(cls,'subclass_names', [])
+        use_names = getattr(cls,'use_names',[])
+        for n in subclasses_names:
+            if n not in subclass_names:
+                print '%s needs to be added to %s subclasses_name list' % (n,cls.__name__)
+        for n in subclass_names:
+            if n not in subclasses_names:
+                print '%s needs to be added to %s subclass_name list' % (n,cls.__name__)
+        for n in use_names:
+            if not Base_classes.has_key(n):
+                print '%s not defined used by %s' % (n, cls.__name__)
 #import pprint
 #pprint.pprint(Base.subclasses)

Modified: trunk/numpy/f2py/lib/parser/pattern_tools.py
===================================================================
--- trunk/numpy/f2py/lib/parser/pattern_tools.py	2006-10-24 07:26:55 UTC (rev 3390)
+++ trunk/numpy/f2py/lib/parser/pattern_tools.py	2006-10-24 21:51:42 UTC (rev 3391)
@@ -82,7 +82,7 @@
         if len(t) < 3: return
         rhs = t[-1].strip()
         pattern_match = t[-2].strip()
-        assert abs(self).match(pattern_match),`pattern_match`
+        assert abs(self).match(pattern_match),`self,string,t,pattern_match`
         lhs = (''.join(t[:-2])).strip()
         return lhs, pattern_match, rhs
 
@@ -248,13 +248,13 @@
 
 power_op = Pattern('<power-op>','[*]{2}')
 mult_op = Pattern('<mult-op>','[*/]')
-add_op = Pattern('<add-op>','[+-]')
-concat_op = Pattern('<concat-op>','[/]{}')
-rel_op = Pattern('<rel-op>','([.](EQ|NE|LT|LE|GT|GE)[.])|[=]{2}|/[=]|[<]|[<][=]|[>]|[=][>]',flags=re.I)
+add_op = Pattern('<add-op>',r'[+-]')
+concat_op = Pattern('<concat-op>',r'[/]{2}')
+rel_op = Pattern('<rel-op>','[.]EQ[.]|[.]NE[.]|[.]LT[.]|[.]LE[.]|[.]GT[.]|[.]GE[.]|[=]{2}|/[=]|[<][=]|[<]|[>][=]|[>]',flags=re.I)
 not_op = Pattern('<not-op>','[.]NOT[.]',flags=re.I)
 and_op = Pattern('<and-op>','[.]AND[.]',flags=re.I)
 or_op = Pattern('<or-op>','[.]OR[.]',flags=re.I)
-equiv_op = Pattern('<equiv-op>','[.](EQV|NEQV)[.]',flags=re.I)
+equiv_op = Pattern('<equiv-op>','[.]EQV[.]|[.]NEQV[.]',flags=re.I)
 percent_op = Pattern('<percent-op>',r'%',flags=re.I)
 intrinsic_operator = power_op | mult_op | add_op | concat_op | rel_op | not_op | and_op | or_op | equiv_op
 extended_intrinsic_operator = intrinsic_operator
@@ -263,6 +263,8 @@
 defined_binary_op = Pattern('<defined-binary-op>','[.][A-Z]+[.]',flags=re.I)
 defined_operator = defined_unary_op | defined_binary_op | extended_intrinsic_operator
 
+non_defined_binary_op = intrinsic_operator | logical_literal_constant
+
 label = Pattern('<label>','\d{1,5}')
 abs_label = abs(label)
 

Modified: trunk/numpy/f2py/lib/parser/test_expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/test_expressions.py	2006-10-24 07:26:55 UTC (rev 3390)
+++ trunk/numpy/f2py/lib/parser/test_expressions.py	2006-10-24 21:51:42 UTC (rev 3391)
@@ -10,14 +10,14 @@
         cls = Expr
         a = cls('a .op. b')
         assert isinstance(a,cls),`a`
-        assert_equal(str(a),'a .op. b')
-        assert_equal(repr(a),"Expr(Name('a'), '.op.', Name('b'))")
+        assert_equal(str(a),'a .OP. b')
+        assert_equal(repr(a),"Expr(Name('a'), '.OP.', Name('b'))")
 
         a = cls('a')
         assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
 
-class test_Designator(NumpyTestCase):
+class test_Substring(NumpyTestCase):
 
     def check_substring(self):
         cls = Substring
@@ -26,7 +26,7 @@
         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):
+class test_Part_Ref(NumpyTestCase):
 
     def check_part_ref(self):
         cls = Part_Ref
@@ -34,7 +34,7 @@
         assert isinstance(a, Name),`a`
         assert_equal(str(a),'a')
         
-class test_Type_Spec(NumpyTestCase):
+class test_Kind_Selector(NumpyTestCase):
 
     def check_kind_selector(self):
         cls = Kind_Selector
@@ -51,6 +51,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'*1')
 
+class test_Type_Param_Value(NumpyTestCase):
+
     def check_type_param_value(self):
         cls = Type_Param_Value
         a = cls('*')
@@ -66,6 +68,8 @@
         assert isinstance(a,Level_2_Expr),`a`
         assert_equal(str(a),'1 + 2')
 
+class test_Char_Length(NumpyTestCase):
+
     def check_char_length(self):
         cls = Char_Length
         a = cls('1')
@@ -85,17 +89,21 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(:)')
 
-    def check_lenght_selector(self):
-        cls = Lenght_Selector
+class test_Length_Selector(NumpyTestCase):
+
+    def check_length_selector(self):
+        cls = Length_Selector
         a = cls('( len = *)')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(LEN = *)')
-        assert_equal(repr(a),"Lenght_Selector('(', Type_Param_Value('*'), ')')")
+        assert_equal(repr(a),"Length_Selector('(', Type_Param_Value('*'), ')')")
 
         a = cls('*2,')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'*2')
 
+class test_Char_Selector(NumpyTestCase):
+
     def check_char_selector(self):
         cls = Char_Selector
         a = cls('(len=2, kind=8)')
@@ -120,6 +128,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(LEN = 2, KIND = 8)')
 
+class test_Intrinsic_Type_Spec(NumpyTestCase):
+
     def check_intrinsic_type_spec(self):
         cls = Intrinsic_Type_Spec
         a = cls('INTEGER')
@@ -155,6 +165,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'DOUBLE PRECISION')
 
+class test_Type_Param_Spec(NumpyTestCase):
+
     def check_type_param_spec(self):
         cls = Type_Param_Spec
         a = cls('a=1')
@@ -170,6 +182,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'k = :')
 
+class test_Type_Param_Spec_List(NumpyTestCase):
+
     def check_type_param_spec_list(self):
         cls = Type_Param_Spec_List
 
@@ -207,13 +221,17 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'f(2, k = 1, a)')
 
+class test_Alt_Return_Spec(NumpyTestCase):
+
     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')")
-        
+
+class test_Substring_Range(NumpyTestCase):
+
     def check_substring_range(self):
         cls = Substring_Range
         a = cls('a:b')
@@ -233,6 +251,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),':')
 
+class test_Array_Section(NumpyTestCase):
+
     def check_array_section(self):
         cls = Array_Section
         a = cls('a(:)')
@@ -244,13 +264,17 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'a(2 :)')
 
+class test_Procedure_Designator(NumpyTestCase):
+
     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'))")
-        
+
+class test_Data_Ref(NumpyTestCase):
+
     def check_data_ref(self):
         cls = Data_Ref
         a = cls('a%b')
@@ -262,7 +286,7 @@
         assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
 
-class test_Structure_Constructor(NumpyTestCase):
+class test_Proc_Component_Ref(NumpyTestCase):
 
     def check_proc_component_ref(self):
         cls = Proc_Component_Ref
@@ -271,12 +295,14 @@
         assert_equal(str(a),'a % b')
         assert_equal(repr(a),"Proc_Component_Ref(Name('a'), '%', Name('b'))")
 
+class test_Structure_Constructor(NumpyTestCase):
+
     def check_structure_constructor(self):
         cls = Structure_Constructor
         a = cls('t()')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'t()')
-        assert_equal(repr(a),"Structure_Constructor(Derived_Type_Spec(Name('t'), None), '(', None, ')')")
+        assert_equal(repr(a),"Structure_Constructor(Name('t'), None)")
 
         a = cls('t(s=1, a)')
         assert isinstance(a,cls),`a`
@@ -291,7 +317,7 @@
         assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
     
-class test_Array_Constructor(NumpyTestCase):
+class test_Ac_Implied_Do_Control(NumpyTestCase):
 
     def check_ac_implied_do_control(self):
         cls = Ac_Implied_Do_Control
@@ -304,6 +330,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'n = 3 + 1, 5, 1')
 
+class test_Ac_Value_List(NumpyTestCase):
+
     def check_ac_value_list(self):
         cls = Ac_Value_List
         a = cls('a, b')
@@ -314,7 +342,9 @@
         a = cls('a')
         assert isinstance(a,Name),`a`
         assert_equal(str(a),'a')
-        
+
+class test_Ac_Implied_Do(NumpyTestCase):
+    
     def check_ac_implied_do(self):
         cls = Ac_Implied_Do
         a = cls('( a, b, n = 1, 5 )')
@@ -322,6 +352,8 @@
         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)]))")
 
+class test_Ac_Spec(NumpyTestCase):
+
     def check_ac_spec(self):
         cls = Ac_Spec
         a = cls('integer ::')
@@ -334,14 +366,14 @@
         assert_equal(str(a),'INTEGER :: a, b')
 
         a = cls('a,b')
-        assert isinstance(a,cls),`a`
+        assert isinstance(a,Ac_Value_List),`a`
         assert_equal(str(a),'a, b')
 
         a = cls('integer :: a, (a, b, n = 1, 5)')
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'INTEGER :: a, (a, b, n = 1, 5)')
 
-class test_Constant(NumpyTestCase):
+class test_Name(NumpyTestCase):
 
     def check_name(self):
         a = Name('a')
@@ -355,6 +387,8 @@
         a = Expr('a')
         assert isinstance(a,Name),`a`
 
+class test_Int_Literal_Constant(NumpyTestCase):
+
     def check_int_literal_constant(self):
         cls = Int_Literal_Constant
         a = cls('1')
@@ -379,6 +413,34 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'1976354279568241_8')
 
+class test_Signed_Int_Literal_Constant(NumpyTestCase):
+
+    def check_int_literal_constant(self):
+        cls = Signed_Int_Literal_Constant
+        a = cls('1')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'1')
+        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__))
+
+        a = cls('-21_SHORT')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'-21_SHORT')
+
+        a = cls('21_short')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'21_short')
+
+        a = cls('+1976354279568241_8')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+1976354279568241_8')
+
+class test_Real_Literal_Constant(NumpyTestCase):
+
     def check_real_literal_constant(self):
         cls = Real_Literal_Constant
         a = cls('12.78')
@@ -434,6 +496,66 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'10.9e-17_quad')
 
+class test_Signed_Real_Literal_Constant(NumpyTestCase):
+
+    def check_signed_real_literal_constant(self):
+        cls = Signed_Real_Literal_Constant
+        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__))
+
+        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__))
+
+        a = cls('- 12.')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'- 12.')
+
+        a = cls('1.6E3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'1.6E3')
+
+        a = cls('+1.6E3_8')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+1.6E3_8')
+
+        a = cls('1.6D3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'1.6D3')
+
+        a = cls('-1.6E-3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'-1.6E-3')
+        a = cls('1.6E+3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'1.6E+3')
+
+        a = cls('3E4')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'3E4')
+
+        a = cls('.123')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'.123')
+
+        a = cls('+1.6E-3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+1.6E-3')
+
+        a = cls('10.9E7_QUAD')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'10.9E7_QUAD')
+
+        a = cls('-10.9e-17_quad')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'-10.9e-17_quad')
+
+
+class test_Complex_Literal_Constant(NumpyTestCase):
+
     def check_complex_literal_constant(self):
         cls = Complex_Literal_Constant
         a = cls('(1.0, -1.0)')
@@ -453,6 +575,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'(0., PI)')
 
+class test_Char_Literal_Constant(NumpyTestCase):
+
     def check_char_literal_constant(self):
         cls = Char_Literal_Constant
         a = cls('NIH_"DO"')
@@ -485,6 +609,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'"hey ha(ada)\t"')
 
+class test_Logical_Literal_Constant(NumpyTestCase):
+
     def check_logical_literal_constant(self):
         cls = Logical_Literal_Constant
         a = cls('.TRUE.')
@@ -504,6 +630,8 @@
         assert isinstance(a,cls),`a`
         assert_equal(str(a),'.TRUE._HA')
 
+class test_Binary_Constant(NumpyTestCase):
+
     def check_boz_literal_constant(self):
         cls = Boz_Literal_Constant
         bcls = Binary_Constant
@@ -512,17 +640,426 @@
         assert_equal(str(a),'B"01"')
         assert_equal(repr(a),"%s('B\"01\"')" % (bcls.__name__))
 
+class test_Octal_Constant(NumpyTestCase):
+
+    def check_boz_literal_constant(self):
+        cls = Boz_Literal_Constant
         ocls = Octal_Constant
         a = cls('O"017"')
         assert isinstance(a,ocls),`a`
         assert_equal(str(a),'O"017"')
         assert_equal(repr(a),"%s('O\"017\"')" % (ocls.__name__))
 
+class test_Hex_Constant(NumpyTestCase):
+
+    def check_boz_literal_constant(self):
+        cls = Boz_Literal_Constant
         zcls = Hex_Constant
         a = cls('Z"01A"')
         assert isinstance(a,zcls),`a`
         assert_equal(str(a),'Z"01A"')
         assert_equal(repr(a),"%s('Z\"01A\"')" % (zcls.__name__))
-    
+
+class test_Subscript_Triplet(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Subscript_Triplet
+        a = cls('a:b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a : b')
+        assert_equal(repr(a),"Subscript_Triplet(Name('a'), Name('b'), None)")
+
+        a = cls('a:b:1')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a : b : 1')
+
+        a = cls(':')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),':')
+
+        a = cls('::5')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),': : 5')
+
+        a = cls(':5')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),': 5')
+
+        a = cls('a+1 :')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a + 1 :')
+
+class test_Section_Subscript(NumpyTestCase):
+
+    def check_simple(self):
+        cls_in = Section_Subscript
+
+        a = cls('1:2')
+        assert isinstance(a, Subscript_Triplet),`a`
+        assert_equal(str(a),'1 : 2')
+
+        a = cls('zzz')
+        assert isinstance(a, Name),`a`
+        assert_equal(str(a),'zzz')
+        
+class test_Section_Subscript_List(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Section_Subscript_List
+        a = cls('a,2')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a, 2')
+        assert_equal(repr(a),"Section_Subscript_List(',', (Name('a'), Int_Literal_Constant('2', None)))")
+
+        a = cls('::1')
+        assert isinstance(a,Subscript_Triplet),`a`
+        assert_equal(str(a),': : 1')
+
+        a = cls('::1, 3')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),': : 1, 3')
+
+class test_Derived_Type_Spec(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Derived_Type_Spec
+        a = cls('a(b)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a(b)')
+        assert_equal(repr(a),"Derived_Type_Spec(Name('a'), Name('b'))")
+
+        a = cls('a(b,c,g=1)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a(b, c, g = 1)')
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
+        a = cls('a()')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a()')
+
+class test_Type_Name(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Type_Name
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+        assert_equal(repr(a),"Name('a')")
+
+        self.assertRaises(NoMatchError,cls,'integer')
+        self.assertRaises(NoMatchError,cls,'doubleprecision')
+
+class test_Actual_Arg_Spec(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Actual_Arg_Spec
+        a = cls('k=a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'k = a')
+        assert_equal(repr(a),"Actual_Arg_Spec(Name('k'), '=', Name('a'))")
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
+class test_Actual_Arg_Spec_List(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Actual_Arg_Spec_List
+        a = cls('a,b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a, b')
+        assert_equal(repr(a),"Actual_Arg_Spec_List(',', (Name('a'), Name('b')))")
+
+        a = cls('a = k')
+        assert isinstance(a,Actual_Arg_Spec),`a`
+        assert_equal(str(a),'a = k')
+
+        a = cls('a = k,b')
+        assert isinstance(a,Actual_Arg_Spec_List),`a`
+        assert_equal(str(a),'a = k, b')
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
+class test_Component_Spec(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Component_Spec
+        a = cls('k=a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'k = a')
+        assert_equal(repr(a),"Component_Spec(Name('k'), '=', Name('a'))")
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
+        a = cls('a % b')
+        assert isinstance(a, Proc_Component_Ref),`a`
+        assert_equal(str(a),'a % b')
+
+        a = cls('s =a % b')
+        assert isinstance(a, Component_Spec),`a`
+        assert_equal(str(a),'s = a % b')
+
+class test_Component_Spec_List(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Component_Spec_List
+        a = cls('k=a, b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'k = a, b')
+        assert_equal(repr(a),"Component_Spec_List(',', (Component_Spec(Name('k'), '=', Name('a')), Name('b')))")
+
+        a = cls('k=a, c')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'k = a, c')
+
+class test_Structure_Constructor_2(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Structure_Constructor_2
+        a = cls('k=a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'k = a')
+        assert_equal(repr(a),"Structure_Constructor_2(Name('k'), '=', Name('a'))")
+
+        a = cls('a')
+        assert isinstance(a,Name),`a`
+        assert_equal(str(a),'a')
+
+class test_Array_Constructor(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Array_Constructor
+        a = cls('(/a/)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'(/a/)')
+        assert_equal(repr(a),"Array_Constructor('(/', Name('a'), '/)')")
+
+        a = cls('[a]')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'[a]')
+        assert_equal(repr(a),"Array_Constructor('[', Name('a'), ']')")
+
+        a = cls('[integer::a]')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'[INTEGER :: a]')
+
+        a = cls('[integer::a,b]')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'[INTEGER :: a, b]')
+
+class test_Parenthesis(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Parenthesis
+        a  = cls('(a)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'(a)')
+        assert_equal(repr(a),"Parenthesis('(', Name('a'), ')')")
+
+        a  = cls('(a+1)')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'(a + 1)')
+
+        a  = cls('((a))')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'((a))')
+
+        a  = cls('(a+(a+c))')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'(a + (a + c))')
+
+class test_Level_1_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_1_Expr
+        a = cls('.hey. a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'.HEY. a')
+        assert_equal(repr(a),"Level_1_Expr('.HEY.', Name('a'))")
+
+        self.assertRaises(NoMatchError,cls,'.not. a')
+
+class test_Level_2_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_2_Expr
+        a = cls('a+b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a + b')
+        assert_equal(repr(a),"Level_2_Expr(Name('a'), '+', Name('b'))")
+
+        a = cls('a-b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a - b')
+
+        a = cls('a+b+c')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a + b + c')
+
+        a = cls('+a')
+        assert isinstance(a,Level_2_Unary_Expr),`a`
+        assert_equal(str(a),'+ a')
+
+        a = cls('+1')
+        assert isinstance(a,Level_2_Unary_Expr),`a`
+        assert_equal(str(a),'+ 1')
+
+        a = cls('+a+b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+ a + b')
+
+class test_Level_2_Unary_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_2_Unary_Expr
+        a = cls('+a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+ a')
+        assert_equal(repr(a),"Level_2_Unary_Expr('+', Name('a'))")
+
+        a = cls('-a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'- a')
+
+        a = cls('+1')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'+ 1')
+
+class test_Level_3_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_3_Expr
+        a = cls('a//b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a // b')
+        assert_equal(repr(a),"Level_3_Expr(Name('a'), '//', Name('b'))")
+
+        a = cls('"a"//"b"')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'"a" // "b"')
+
+class test_Level_4_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_4_Expr
+        a = cls('a.eq.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .EQ. b')
+        assert_equal(repr(a),"Level_4_Expr(Name('a'), '.EQ.', Name('b'))")
+
+        a = cls('a.ne.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .NE. b')
+
+        a = cls('a.lt.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .LT. b')
+
+        a = cls('a.gt.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .GT. b')
+
+        a = cls('a.ge.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .GE. b')
+
+        a = cls('a==b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a == b')
+
+        a = cls('a/=b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a /= b')
+
+        a = cls('a<b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a < b')
+
+        a = cls('a<=b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a <= b')
+
+        a = cls('a>=b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a >= b')
+
+        a = cls('a>b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a > b')
+
+class test_Level_5_Expr(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Level_5_Expr
+        a = cls('a.eqv.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .EQV. b')
+        assert_equal(repr(a),"Level_5_Expr(Name('a'), '.EQV.', Name('b'))")
+
+        a = cls('a.neqv.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .NEQV. b')
+
+        a = cls('a.eq.b')
+        assert isinstance(a,Level_4_Expr),`a`
+        assert_equal(str(a),'a .EQ. b')
+
+class test_Mult_Operand(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Mult_Operand
+        a = cls('a**b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a ** b')
+        assert_equal(repr(a),"Mult_Operand(Name('a'), '**', Name('b'))")
+
+class test_Add_Operand(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Add_Operand
+        a = cls('a*b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a * b')
+        assert_equal(repr(a),"Add_Operand(Name('a'), '*', Name('b'))")
+
+        a = cls('a/b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a / b')
+
+class test_Equiv_Operand(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Equiv_Operand
+        a = cls('a.or.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .OR. b')
+        assert_equal(repr(a),"Equiv_Operand(Name('a'), '.OR.', Name('b'))")
+
+class test_Or_Operand(NumpyTestCase):
+
+    def check_simple(self):
+        cls = Or_Operand
+        a = cls('a.and.b')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'a .AND. b')
+        assert_equal(repr(a),"Or_Operand(Name('a'), '.AND.', Name('b'))")
+
+class test_And_Operand(NumpyTestCase):
+
+    def check_simple(self):
+        cls = And_Operand
+        a = cls('.not.a')
+        assert isinstance(a,cls),`a`
+        assert_equal(str(a),'.NOT. a')
+        assert_equal(repr(a),"And_Operand('.NOT.', Name('a'))")
+        
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list