[Numpy-svn] r3399 - trunk/numpy/f2py/lib/parser
numpy-svn at scipy.org
numpy-svn at scipy.org
Wed Oct 25 11:40:16 EDT 2006
Author: pearu
Date: 2006-10-25 10:40:10 -0500 (Wed, 25 Oct 2006)
New Revision: 3399
Modified:
trunk/numpy/f2py/lib/parser/expressions.py
trunk/numpy/f2py/lib/parser/test_expressions.py
Log:
F2PY G3: more tests for Fortran expr parser.
Modified: trunk/numpy/f2py/lib/parser/expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/expressions.py 2006-10-25 11:37:30 UTC (rev 3398)
+++ trunk/numpy/f2py/lib/parser/expressions.py 2006-10-25 15:40:10 UTC (rev 3399)
@@ -202,7 +202,7 @@
def match(number_pattern, string):
m = number_pattern.match(string)
if m is None: return
- return m.group('value'),m.group('kind_param')
+ return m.group('value').upper(),m.group('kind_param')
match = staticmethod(match)
def init(self, value, kind_param):
self.value = value
@@ -257,6 +257,7 @@
def tostr(self): return str(self.string)
def torepr(self): return '%s(%r)' % (self.__class__.__name__, self.string)
+
##################################################
class Name(StringBase):
@@ -275,6 +276,9 @@
subclass_names = []
def match(string): return StringBase.match(pattern.abs_binary_constant, string)
match = staticmethod(match)
+ def init(self, string):
+ self.string = string.upper()
+ return
class Octal_Constant(StringBase):
"""
@@ -284,6 +288,9 @@
subclass_names = []
def match(string): return StringBase.match(pattern.abs_octal_constant, string)
match = staticmethod(match)
+ def init(self, string):
+ self.string = string.upper()
+ return
class Hex_Constant(StringBase):
"""
@@ -293,8 +300,10 @@
subclass_names = []
def match(string): return StringBase.match(pattern.abs_hex_constant, string)
match = staticmethod(match)
+ def init(self, string):
+ self.string = string.upper()
+ return
-
class Int_Literal_Constant(NumberBase):
"""
<int-literal-constant> = <digit-string> [ _ <kind-param> ]
@@ -534,7 +543,7 @@
| <type-param-name>
| ( <expr> )
"""
- subclass_names = ['Parenthesis', 'Constant', 'Designator','Array_Constructor','Structure_Constructor',
+ subclass_names = ['Constant', 'Parenthesis', 'Designator','Array_Constructor','Structure_Constructor',
'Function_Reference', 'Type_Param_Inquiry', 'Type_Param_Name',
]
@@ -1014,7 +1023,7 @@
<substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
<structure-component> = <data-ref>
"""
- subclass_names = ['Object_Name','Array_Element','Array_Section','Structure_Component',
+ subclass_names = ['Object_Name','Array_Section','Array_Element','Structure_Component',
'Substring'
]
@@ -1476,8 +1485,10 @@
if lhs==rhs: return 0
rhs_deps = Base_deps[rhs]
lhs_deps = Base_deps[lhs]
+ if lhs in rhs_deps and rhs in lhs_deps: return 0
if lhs in rhs_deps: return -1
if rhs in lhs_deps: return 1
+ return 0
return cmp(len(lhs_deps),len(rhs_deps))
for clsname,deps in Base_deps.items():
Modified: trunk/numpy/f2py/lib/parser/test_expressions.py
===================================================================
--- trunk/numpy/f2py/lib/parser/test_expressions.py 2006-10-25 11:37:30 UTC (rev 3398)
+++ trunk/numpy/f2py/lib/parser/test_expressions.py 2006-10-25 15:40:10 UTC (rev 3399)
@@ -494,7 +494,7 @@
a = cls('10.9e-17_quad')
assert isinstance(a,cls),`a`
- assert_equal(str(a),'10.9e-17_quad')
+ assert_equal(str(a),'10.9E-17_quad')
class test_Signed_Real_Literal_Constant(NumpyTestCase):
@@ -551,7 +551,7 @@
a = cls('-10.9e-17_quad')
assert isinstance(a,cls),`a`
- assert_equal(str(a),'-10.9e-17_quad')
+ assert_equal(str(a),'-10.9E-17_quad')
class test_Complex_Literal_Constant(NumpyTestCase):
@@ -620,7 +620,7 @@
a = cls('.True.')
assert isinstance(a,cls),`a`
- assert_equal(str(a),'.True.')
+ assert_equal(str(a),'.TRUE.')
a = cls('.FALSE.')
assert isinstance(a,cls),`a`
@@ -1060,6 +1060,60 @@
assert isinstance(a,cls),`a`
assert_equal(str(a),'.NOT. a')
assert_equal(repr(a),"And_Operand('.NOT.', Name('a'))")
+
+class test_Primary(NumpyTestCase):
+
+ def check_simple(self):
+ cls = Primary
+ a = cls('a')
+ assert isinstance(a,Name),`a`
+ assert_equal(str(a),'a')
+
+ a = cls('(a)')
+ assert isinstance(a,Parenthesis),`a`
+ assert_equal(str(a),'(a)')
+
+ a = cls('1')
+ assert isinstance(a,Int_Literal_Constant),`a`
+ assert_equal(str(a),'1')
+
+ a = cls('1.')
+ assert isinstance(a,Real_Literal_Constant),`a`
+ assert_equal(str(a),'1.')
+
+ a = cls('(1, n)')
+ assert isinstance(a,Complex_Literal_Constant),`a`
+ assert_equal(str(a),'(1, n)')
+
+ a = cls('.true.')
+ assert isinstance(a,Logical_Literal_Constant),`a`
+ assert_equal(str(a),'.TRUE.')
+
+ a = cls('"hey a()c"')
+ assert isinstance(a,Char_Literal_Constant),`a`
+ assert_equal(str(a),'"hey a()c"')
+
+ a = cls('b"0101"')
+ assert isinstance(a,Binary_Constant),`a`
+ assert_equal(str(a),'B"0101"')
+
+ a = cls('o"0107"')
+ assert isinstance(a,Octal_Constant),`a`
+ assert_equal(str(a),'O"0107"')
+
+ a = cls('z"a107"')
+ assert isinstance(a,Hex_Constant),`a`
+ assert_equal(str(a),'Z"A107"')
+
+ a = cls('a % b')
+ assert isinstance(a,Data_Ref),`a`
+ assert_equal(str(a),'a % b')
+
+ a = cls('a(:)')
+ assert isinstance(a,Array_Section),`a`
+ assert_equal(str(a),'a(:)')
+
+
if __name__ == "__main__":
NumpyTest().run()
More information about the Numpy-svn
mailing list