[Mumps2Py:] [108] code simplification, and added another special-case operator.

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 108
Author:   pgallot
Date:     2008-02-13 23:17:19 +0000 (Wed, 13 Feb 2008)

Log Message:
-----------
code simplification, and added another special-case operator.

Modified Paths:
--------------
    trunk/mumps2py/tok2python.py


Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py	2008-02-13 23:15:54 UTC (rev 107)
+++ trunk/mumps2py/tok2python.py	2008-02-13 23:17:19 UTC (rev 108)
@@ -132,7 +132,6 @@
 
 def translate_label(translation, token):
     """translate a Mumps label to Python"""
-# TODO: anything that should be done for ExternallyVisible?
     if token.parameters:
         if len(token.parameters) == 1:
             return "def %s(%s):\n" % (token.val, token.parameters[0])
@@ -386,7 +385,7 @@
         op_trans_dict = {OPADD:'+', OPSUB:'-', OPMULT:'*', OPEXP:'**',
                          OPMODULO:'%', OPGT:'>', OPLT:'<', OPNGT:'<=',
                          OPNLT:'>=', OPEQ:'==', OPNEQ:'!=', OPAND:'and',
-                         OPOR:'or', OPFRACDIV:'/', OPINTDIV:'/',
+                         OPOR:'or', OPFRACDIV:'/', OPINTDIV:'/', OPSORTS:'>',
                          OPFOLLOWS:'>', OPCONCAT:'+', OPNOT:'not '}
         
         expr_list = token.expr_list[:]
@@ -403,14 +402,20 @@
             b_not = False
             binop_token = expr_list.pop(0)
 
-            if binop_token.is_op() and binop_token.is_not():
+            if binop_token.toktype == OPNOT:
                 b_not = True
                 binop_token = expr_list.pop(0)
-            elif binop_token.is_op() and binop_token.is_patmatch():
+            elif binop_token.toktype == OPPATMATCH:
                 translation.add_import("re")
                 left_str = "re.match(%s, %s)" % \
                            (translate_pattern_atoms(binop_token), left_str)
                 continue
+            elif binop_token.toktype == OPCONTAINS:
+                translation.add_import("re")
+                left_str = "re.search(%s, %s)" % \
+                           (translate_expr(translation,expr_list.pop(0)),
+                            left_str)
+                continue
                 
             right_token = expr_list.pop(0)
             if right_token.is_op() and right_token.is_unaryop():


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/