[Mumps2Py:] [96] added support for Mumps Intrinsic $TRanslate() |
[ Thread Index |
Date Index
| More lists.mumps2py.org/discuss Archives
]
Revision: 96
Author: pgallot
Date: 2008-02-12 18:44:35 +0000 (Tue, 12 Feb 2008)
Log Message:
-----------
added support for Mumps Intrinsic $TRanslate()
Modified Paths:
--------------
trunk/mumps2py/mumpsCL.py
trunk/mumps2py/tok2python.py
Modified: trunk/mumps2py/mumpsCL.py
===================================================================
--- trunk/mumps2py/mumpsCL.py 2008-02-12 03:24:31 UTC (rev 95)
+++ trunk/mumps2py/mumpsCL.py 2008-02-12 18:44:35 UTC (rev 96)
@@ -75,6 +75,22 @@
else:
return val + len(substr) + 1
+def Mf_translate(input_str, subst_str = None, repl_str = None):
+ """Python-equivalent of the Mumps $Translate intrinsic"""
+ subst_dict = {}
+ if subst_str:
+ for cnt in range(len(subst_str)-1, -1, -1):
+ if repl_str and len(repl_str) > cnt:
+ subst_dict[subst_str[cnt]] = repl_str[cnt]
+ else:
+ subst_dict[subst_str[cnt]] = None
+ new_str = ""
+ for char in input_str:
+ new_char = subst_dict.get(char, char)
+ if new_char:
+ new_str = new_str + new_char
+ return new_str
+
def Mc_merge(recipient, recipient_modifier, copy_item, copy_item_subset):
"""merge a subset of one dictionary into a subset of another"""
new_keys = {}
Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py 2008-02-12 03:24:31 UTC (rev 95)
+++ trunk/mumps2py/tok2python.py 2008-02-12 18:44:35 UTC (rev 96)
@@ -316,6 +316,21 @@
raise TranslationError(translation, token,
"incorrect number of parameters")
return reverse_str
+
+ def translate_intr_translate(translation, token):
+ """ translates the Mumps Intrinsic function TRANSLATE to Python"""
+ translation.add_cl_import()
+ inputstr_str = translate_expr(translation, token.params[0])
+ subst_str = ""
+ repl_str = ""
+ if len(token.params) >= 2:
+ subst_str = ", " + translate_expr(translation, token.params[1])
+ if len(token.params) == 3:
+ repl_str = ", " + translate_expr(translation, token.params[2])
+ translation_str = "Mf_translate(%s%s%s)" % \
+ (inputstr_str, subst_str, repl_str)
+ return translation_str
+
def translate_local_var(translation, token):
""" translates a local variable into a Python variable"""
@@ -395,6 +410,7 @@
F_PIECE: translate_intr_piece,
F_RANDOM: translate_intr_random,
F_REVERSE: translate_intr_reverse,
+ F_TRANSLATE: translate_intr_translate,
V_HOROLOG: translate_intr_horolog,
EXPR: translate_expr_list}