[Mumps2Py:] [4] added an is_int helper function.

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


Revision: 4
Author:   pgallot
Date:     2008-01-17 17:24:50 +0000 (Thu, 17 Jan 2008)

Log Message:
-----------
added an is_int helper function.

Modified Paths:
--------------
    trunk/tokens.py


Modified: trunk/tokens.py
===================================================================
--- trunk/tokens.py	2008-01-17 15:54:57 UTC (rev 3)
+++ trunk/tokens.py	2008-01-17 17:24:50 UTC (rev 4)
@@ -16,6 +16,7 @@
 ##    along with Mumps2Py.  If not, see <http://www.gnu.org/licenses/>.
 """ All the possible token types that can be extracted from Mumps code"""
 from types import *
+import re
 
 # IMPORTANT: Add a Token Type Constant, update the relevant dictionaries.
 
@@ -376,6 +377,13 @@
         """returns true if the token is a numeric literal"""
         return (self.toktype == NUMLITERAL)
 
+    def is_int(self):
+        """returns true if a numeric literal has no decimal"""
+        if (self.toktype == NUMLITERAL):
+            return not re.search(r"[.]",self.val)
+        else:
+            return False
+
     def is_not(self):
         """returns true if the token is the not operator"""
         return (self.toktype == OPNOT)
@@ -390,14 +398,12 @@
         return (self.toktype in (OPADD, OPSUB, OPNOT))
 
     def is_binaryop(self):
-        """returns true if the token is a binary operator"""
+        """returns true if the token is a simple binary operator"""
         return (self.toktype in (OPADD, OPSUB, OPMULT, OPEXP,
                                  OPFRACDIV, OPINTDIV, OPMODULO,
                                  OPGT, OPLT, OPNGT, OPNLT,
                                  OPEQ, OPNEQ, OPAND, OPOR, OPCONCAT,
-                                 OPCONTAINS, OPNCONTAINS,
-                                 OPFOLLOWS, OPNFOLLOWS,
-                                 OPSORTS, OPNSORTS, OPPATMATCH))
+                                 OPCONTAINS, OPFOLLOWS, OPSORTS, OPPATMATCH))
                 
     def count_subtokens(self, count_dict):
         """counts the different types of (sub)tokens including itself."""


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