[Mumps2Py:] [102] more sub-classing of Token; this time for Operators and pattern-matching atoms.

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


Revision: 102
Author:   pgallot
Date:     2008-02-13 20:36:17 +0000 (Wed, 13 Feb 2008)

Log Message:
-----------
more sub-classing of Token; this time for Operators and pattern-matching atoms.

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


Modified: trunk/mumps2py/tokens.py
===================================================================
--- trunk/mumps2py/tokens.py	2008-02-13 20:32:21 UTC (rev 101)
+++ trunk/mumps2py/tokens.py	2008-02-13 20:36:17 UTC (rev 102)
@@ -435,10 +435,6 @@
         else:
             return False
 
-    def is_not(self):
-        """returns true if the token is the not operator"""
-        return (self.toktype == OPNOT)
-
     def is_expr(self):
         """returns true if the token is an expression"""
         return (self.toktype == EXPR)
@@ -447,20 +443,10 @@
         """returns true if the token is a variable"""
         return (self.toktype in (LOCALVAR, GLOBALVAR))
 
-    def is_unaryop(self):
-        """returns true if the token is a unary operator"""
-        
-        return (self.toktype in (OPADD, OPSUB, OPNOT))
+    def is_op(self):
+        """returns true if the token is an operator token"""
+        return isinstance(self, OpToken)
 
-    def is_binaryop(self):
-        """returns true if the token is a simple binary operator"""
-        #TODO: everything from OPCONCAT on is not a simple binary operato
-        return (self.toktype in (OPADD, OPSUB, OPMULT, OPEXP,
-                                 OPFRACDIV, OPINTDIV, OPMODULO,
-                                 OPGT, OPLT, OPNGT, OPNLT,
-                                 OPEQ, OPNEQ, OPAND, OPOR, OPCONCAT,
-                                 OPCONTAINS, OPFOLLOWS, OPSORTS, OPPATMATCH))
-                
     def count_subtokens(self, count_dict):
         """counts the different types of (sub)tokens including itself."""
         return count_subtokens(count_dict, self)
@@ -490,3 +476,42 @@
     def unindex(self):
         """remove the index for just this instance."""
         del self.__dict__['indices']
+
+
+class OpToken(Token):
+    """Token subclass specifically for operands"""
+    def __init__(self, tok_type, startpos):
+        """ initializes a Token object of a variable Token type."""
+        Token.__init__(self, tok_type, startpos)
+    
+    def is_not(self):
+        """returns true if the token is the not operator"""
+        return (self.toktype == OPNOT)
+               
+    def is_patmatch(self):
+        """returns true if the token is the pattern match operator"""
+        return (self.toktype == OPPATMATCH)
+        
+    def is_unaryop(self):
+        """returns true if the token is a unary operator"""
+        return (self.toktype in (OPADD, OPSUB, OPNOT))
+
+    def is_binaryop(self):
+        """returns true if the token is a binary operator"""
+        return (self.toktype in (OPADD, OPSUB, OPMULT, OPEXP,
+                                 OPFRACDIV, OPINTDIV, OPMODULO,
+                                 OPGT, OPLT, OPNGT, OPNLT,
+                                 OPEQ, OPNEQ, OPAND, OPOR, OPCONCAT,
+                                 OPCONTAINS, OPFOLLOWS, OPSORTS))
+    
+class AtomToken(Token):
+    """Token subclass specifically for variables"""
+    def __init__(self, startpos):
+        """ initializes a Token object of a pattern-matching Token type."""
+        Token.__init__(self, OPPATATOM, startpos)
+        self.repcount = None
+        self.minrep = None
+        self.maxrep = None
+        self.match_str = None
+        self.alt_list = None
+        self.pat_code = None


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