[Mumps2Py:] [16] improved translate_intr_extract a bit. |
[ Thread Index |
Date Index
| More lists.mumps2py.org/discuss Archives
]
Revision: 16
Author: pgallot
Date: 2008-01-17 19:36:14 +0000 (Thu, 17 Jan 2008)
Log Message:
-----------
improved translate_intr_extract a bit. The [0:n] case now translates as [:n].
Modified Paths:
--------------
trunk/mumps2py/tok2python.py
Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py 2008-01-17 18:56:58 UTC (rev 15)
+++ trunk/mumps2py/tok2python.py 2008-01-17 19:36:14 UTC (rev 16)
@@ -88,15 +88,17 @@
def translate_intr_extract(translation, token):
""" translates the Mumps Intrinsic function EXTRACT to python"""
- if len(token.params) == 3:
- extract_str = "%s[%s:%s]" % (
- translate_expr(translation, token.params[0]),
- translate_expr_sub_one(translation, token.params[1]),
- translate_expr(translation, token.params[2]))
- elif len(token.params) == 2:
- extract_str = "%s[%s]" % (
- translate_expr(translation, token.params[0]),
- translate_expr_sub_one(translation, token.params[1]))
+ inputstr_str = translate_expr(translation, token.params[0])
+ start_str = translate_expr_sub_one(translation, token.params[1])
+
+ if len(token.params) == 2:
+ extract_str = "%s[%s]" % (inputstr_str, start_str)
+ elif len(token.params) == 3:
+ if start_str == '0':
+ start_str = ""
+ extract_str = "%s[%s:%s]" % (inputstr_str, start_str,
+ translate_expr(translation,
+ token.params[2]))
else:
raise TranslationError(translation, token,
"incorrect number of parameters")