[Mumps2Py:] [164] Workaround for handling the ZK-implementation-specific intrinsic function' s non-standard arguments.

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


Revision: 164
Author:   pgallot
Date:     2008-03-10 19:18:04 +0000 (Mon, 10 Mar 2008)

Log Message:
-----------
Workaround for handling the ZK-implementation-specific intrinsic function's non-standard arguments. 
Try to generalize white-space handling.

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


Modified: trunk/mumps2py/mumps2tok.py
===================================================================
--- trunk/mumps2py/mumps2tok.py	2008-03-10 17:30:42 UTC (rev 163)
+++ trunk/mumps2py/mumps2tok.py	2008-03-10 19:18:04 UTC (rev 164)
@@ -59,12 +59,12 @@
     "patAtom":re.compile(r"(((?P<mnrp>\d+)?[.](?P<mxrp>\d+)?)|(?P<rpcount>\d+)){1}((?P<altlist>[(])|(?P<patcode>[ACELNPUacelnpu]+)|(?P<str>([\"])))"),
     "nakedRef":re.compile(r"\^\("),
     "subexpr":re.compile(r"[(]"),
-    "command":re.compile(r"(?P<indents>[ .]*)(?P<cmd>[A-Za-z]+)"),
+    "command":re.compile(r"(?P<indents>(\s|[.])*)(?P<cmd>[A-Za-z]+)"),
     "label":re.compile(r"^(\^)?[%a-zA-Z0-9][A-Za-z0-9]*"),
     "comment":re.compile(r"[ ]*?[ .]*?(?P<comment>[;]+.*)"),
     "emptyline":re.compile(r"[ .]*\s*$"),
-    "cmd":re.compile(r"[. ]*([A-Za-z]+\w*?(?:[ :]|\s*$))"),
-    "cmdEnd":re.compile(r"[ ]|\s*$")
+    "cmd":re.compile(r"(\s|[.])*([A-Za-z]+\w*?(?:[ :]|\s*$))"),
+    "cmdEnd":re.compile(r"[ ;]|\s*$")
     }
 
 def consume_actuallist(line, pos):
@@ -291,6 +291,9 @@
 
         pos += 1
         mobj2 = MUMPS_RE_DICT["var"].match(line, pos)
+        if not mobj2:
+            raise ParseError(line, "Unexpected extglobal pattern", pos)
+        
         token.varname = mobj2.group("var")
         pos = mobj2.end("var")
         if mobj2.group("indexed"):
@@ -316,6 +319,26 @@
         token.entry_ref = entry_ref
         return (token, end_pos)
 
+    def consume_dummylist(line, pos):
+        """consume a non-standard function's argument as one long string"""
+        val = ""
+        openparens_count = 1
+        mterminated = MUMPS_RE_DICT["cmdEnd"]
+        while not mterminated.match(line, pos) and openparens_count:
+            if line[pos] == '"':
+                str_val = parse_expr(line, pos, r'[ _,:)]|\s*$')
+                new_pos = str_val.end
+            else:
+                if line[pos] == '(':
+                    openparens_count += 1
+                elif line[pos] == ')':
+                    openparens_count -= 1
+                new_pos = pos + 1
+
+            val = val + line[pos:new_pos]
+            pos = new_pos
+        return (pos, (val ,))    
+
     def consume_intrinsic(mobj):
         """ parses a Mumps intrinsic function or variable"""
         name = mobj.group("intrinsic").upper()
@@ -330,7 +353,10 @@
             else:
                 if toktype == F_UNKNOWN:
                     token.name = name
-                pos, token.params = consume_actuallist(line, pos)
+                if name == "ZK": # implementation-specific incompatible case.
+                    pos, token.params = consume_dummylist(line, pos)
+                else:
+                    pos, token.params = consume_actuallist(line, pos)
         else: # vars...
             toktype = INTRINSIC_VARS.get(name, V_UNKNOWN)
             token = Token(toktype, mobj.start())
@@ -556,7 +582,7 @@
                 
     def parse_quit(parent_tok, line, pos):
         """parses the Mumps Quit command"""
-        mterminated = re.compile(r"[; ]|\s*$")
+        mterminated = MUMPS_RE_DICT["cmdEnd"]
         if not mterminated.match(line, pos):
             return_val = parse_expr(line, pos)
             pos = return_val.end
@@ -1050,7 +1076,9 @@
 
     try:
         #mods = parse_for_routines("../testfiles/vista.m2p", "./out")
-        mods = parse_for_routines("../testfiles/fm22.m2p", "./out")
+        #mods = parse_for_routines("../testfiles/fm22.m2p", "./out")
+        #mods = parse_for_routines("c:/temp/famo.mrt", "./out")
+        mods = parse_for_routines("../testfiles/famo.m2p", "./out")
         #parsemodule(mods,"ZTMB")
         for the_module in mods:
             print the_module.mod_name


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