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

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Jan 18 04:25:59 CST 2007


Author: pearu
Date: 2007-01-18 04:25:55 -0600 (Thu, 18 Jan 2007)
New Revision: 3512

Modified:
   trunk/numpy/f2py/lib/parser/pattern_tools.py
Log:
G3 F2PY: Fixed parsing a*b**c expression.

Modified: trunk/numpy/f2py/lib/parser/pattern_tools.py
===================================================================
--- trunk/numpy/f2py/lib/parser/pattern_tools.py	2007-01-15 06:53:06 UTC (rev 3511)
+++ trunk/numpy/f2py/lib/parser/pattern_tools.py	2007-01-18 10:25:55 UTC (rev 3512)
@@ -261,10 +261,10 @@
 data_ref = part_ref + ~~~(r'[%]' + part_ref)
 primary = constant | name | data_ref | (r'[(]' + name + r'[)]')
 
-power_op = Pattern('<power-op>','[*]{2}')
-mult_op = Pattern('<mult-op>',r'[/*]')
+power_op = Pattern('<power-op>',r'(?<![*])[*]{2}(?![*])')
+mult_op = Pattern('<mult-op>',r'(?<![*])[*](?![*])|(?<![/])[/](?![/])')
 add_op = Pattern('<add-op>',r'[+-]')
-concat_op = Pattern('<concat-op>',r'[/]{2}')
+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)
@@ -372,6 +372,29 @@
     assert m.match('HEY_"adadfa"')
     assert m.match('HEY _ "ad\tadfa"')
     assert not m.match('adadfa')
+
+    def assert_equal(result, expect):
+        try:
+            assert result==expect
+        except AssertionError, msg:
+            raise AssertionError,"Expected %r but got %r: %s" \
+                  % (expect, result, msg)
+
+    m = mult_op.named()
+    assert m.rsplit('a *  b')
+    assert_equal(m.lsplit('a * c* b'),('a','*','c* b'))
+    assert_equal(m.rsplit('a * c* b'),('a * c','*','b'))
+    assert_equal(m.lsplit('a * b ** c'),('a','*','b ** c'))
+    assert_equal(m.rsplit('a * b ** c'),('a','*','b ** c'))
+    assert_equal(m.lsplit('a * b ** c * d'),('a','*','b ** c * d'))
+    assert_equal(m.rsplit('a * b ** c * d'),('a * b ** c','*','d'))
+
+    m = power_op.named()
+    assert m.rsplit('a **  b')
+    assert_equal(m.lsplit('a * b ** c'),('a * b','**','c'))
+    assert_equal(m.rsplit('a * b ** c'),('a * b','**','c'))
+    assert_equal(m.lsplit('a ** b ** c'),('a','**','b ** c'))
+    assert_equal(m.rsplit('a ** b ** c'),('a ** b','**','c'))
     print 'ok'
 
 if __name__ == '__main__':



More information about the Numpy-svn mailing list