[Mumps2Py:] [88] added support for the $FIND() intrinsic function.

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


Revision: 88
Author:   pgallot
Date:     2008-02-11 21:32:35 +0000 (Mon, 11 Feb 2008)

Log Message:
-----------
added support for the $FIND() intrinsic function.

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


Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py	2008-02-06 21:29:12 UTC (rev 87)
+++ trunk/mumps2py/tok2python.py	2008-02-11 21:32:35 UTC (rev 88)
@@ -219,7 +219,23 @@
             raise TranslationError(translation, token,
                                    "incorrect number of parameters")
         return extract_str
-                 
+
+    def translate_intr_find(translation, token):
+        """ translates the Mumps Intrinsic function FIND to Python"""
+        search_str = translate_expr(translation, token.params[0])
+        sub_str = translate_expr(translation, token.params[1])
+        if len(token.params) == 2:
+            find_str = "%s.find(%s) + len(%s) + 1" % \
+                       (search_str, sub_str, sub_str)
+        elif len(token.params) == 3:
+            start_str = translate_expr_sub_one(translation, token.params[2])
+            find_str = "%s.find(%s, %s) + len(%s) + 1" % \
+                       (search_str, sub_str, start_str, sub_str)
+        else:
+            raise TranslationError(translation, token,
+                                   "incorrect number of parameters")
+        return find_str
+                           
     def translate_intr_length(translation, token):
         """ translates the Mumps Intrinsic function LENGTH to Python"""
         if len(token.params) == 1:
@@ -367,6 +383,7 @@
         F_CHAR: translate_intr_char,
         F_DATA: translate_intr_data,
         F_EXTRACT: translate_intr_extract,
+        F_FIND: translate_intr_find,
         F_JUSTIFY: translate_intr_justify,
         F_LENGTH: translate_intr_length,
         F_PIECE: translate_intr_piece,


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