[Mumps2Py:] [63] added support for the Reverse and Justify intrinsic functions. |
[ Thread Index |
Date Index
| More lists.mumps2py.org/discuss Archives
]
Revision: 63
Author: pgallot
Date: 2008-01-28 20:55:13 +0000 (Mon, 28 Jan 2008)
Log Message:
-----------
added support for the Reverse and Justify intrinsic functions.
Modified Paths:
--------------
trunk/mumps2py/tok2python.py
Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py 2008-01-28 20:53:09 UTC (rev 62)
+++ trunk/mumps2py/tok2python.py 2008-01-28 20:55:13 UTC (rev 63)
@@ -234,8 +234,24 @@
"incorrect number of parameters")
return length_str
+ def translate_intr_justify(translation, token):
+ """ translates the Mumps Intrinsic function JUSTIFY to Python"""
+ if len(token.params) == 2:
+ justify_str = "%s.rjust(%s)" % \
+ (translate_expr(translation, token.params[0]),
+ translate_expr(translation, token.params[1]))
+ elif len(token.params) == 3:
+ justify_str = "\"%%*.*f\" %% (%s, %s, %s)" % \
+ (translate_expr(translation, token.params[1]),
+ translate_expr(translation, token.params[2]),
+ translate_expr(translation, token.params[0]))
+ else:
+ raise TranslationError(translation, token,
+ "incorrect number of parameters")
+ return justify_str
+
def translate_intr_piece(translation, token):
- """ translates the Mumps Intrinsic function EXTRACT to Python"""
+ """ translates the Mumps Intrinsic function PIECE to Python"""
translation.add_import("re")
inputstr_str = translate_expr(translation, token.params[0])
sep_str = translate_expr(translation, token.params[1])
@@ -258,6 +274,16 @@
"incorrect number of parameters")
return piece_str
+ def translate_intr_reverse(translation, token):
+ """ translates the Mumps Intrinsic function REVERSE to Python"""
+ if len(token.params) == 1:
+ reverse_str = "%s[::-1]" % \
+ translate_expr(translation, token.params[0])
+ else:
+ raise TranslationError(translation, token,
+ "incorrect number of parameters")
+ return reverse_str
+
def translate_local_var(translation, token):
""" translates a local variable into a Python variable"""
if not token.is_indexed() or \
@@ -330,8 +356,10 @@
F_CHAR: translate_intr_char,
F_DATA: translate_intr_data,
F_EXTRACT: translate_intr_extract,
+ F_JUSTIFY: translate_intr_justify,
F_LENGTH: translate_intr_length,
F_PIECE: translate_intr_piece,
+ F_REVERSE: translate_intr_reverse,
EXPR: translate_expr_list}
if expr_transl_dict.has_key(token.toktype):