[Mumps2Py:] [85] Nomenclature change, and more parsing logic fixes.

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


Revision: 85
Author:   pgallot
Date:     2008-02-06 03:17:13 +0000 (Wed, 06 Feb 2008)

Log Message:
-----------
Nomenclature change, and more parsing logic fixes.

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


Modified: trunk/mumps2py/mumps2tok.py
===================================================================
--- trunk/mumps2py/mumps2tok.py	2008-02-04 23:35:50 UTC (rev 84)
+++ trunk/mumps2py/mumps2tok.py	2008-02-06 03:17:13 UTC (rev 85)
@@ -63,7 +63,7 @@
     "cmdEnd":re.compile(r"[ ]|\s*$")
     }
 
-def consume_actuallist(mumps_module, line, pos):
+def consume_actuallist(routine, line, pos):
     """ parses a list of parameters """
     actuallist = []
     while line[pos] != ")":
@@ -71,7 +71,7 @@
         if line[pos] == '.' and not MUMPS_RE_DICT['num'].match(line, pos):
             pass_by_ref = True
             pos = pos + 1            
-        exprtok = parse_expr(mumps_module, line, pos, r"([:,)])")
+        exprtok = parse_expr(routine, line, pos, r"([:,)])")
         if pass_by_ref:
             exprtok.pass_by_ref = True            
         actuallist.append(exprtok)
@@ -79,33 +79,32 @@
         if line[pos] == ":":
             pos = pos + 1
             condtok = exprtok
-            exprtok = parse_expr(mumps_module, line, pos, r"[,)]")
+            exprtok = parse_expr(routine, line, pos, r"[,)]")
             exprtok.post_condition(condtok)
         elif line[pos] == ",":
             pos = pos + 1
     return (pos + 1, actuallist)
 
-def consume_entry_ref(mumps_module, line, pos):
+def consume_entry_ref(routine, line, pos):
     """ parses a Mumps Entry Ref"""
     token = Token(ENTRYREF, pos)
     if line[pos] == '@':
         if MUMPS_RE_DICT["nakedRef"].match(line, pos + 1):
-            indirect = parse_expr(mumps_module, line, pos+1, r"([,+: ]|\s$)")
+            indirect = parse_expr(routine, line, pos+1, r"([,+: ]|\s$)")
             token.indirect = indirect
             pos = indirect.end
         else:
-            indirect = parse_expr(mumps_module, line, pos, \
-                                  r"(\^|[ +),:]|\s*$)")
+            indirect = parse_expr(routine, line, pos, r"(\^|[ +),:]|\s*$)")
             token.indirect = indirect
             pos = indirect.end
         if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '+':
             pos = pos + 1
-            offset = parse_expr(mumps_module, line, pos, r"(\^|[ ),:]|\s*$)")
+            offset = parse_expr(routine, line, pos, r"(\^|[ ),:]|\s*$)")
             token.offset = offset
             pos = offset.end
         if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '^':
             pos = pos + 1
-            routine = parse_expr(mumps_module, line, pos, r"([ ,)(:]|\s*$)")
+            routine = parse_expr(routine, line, pos, r"([ ,)(:]|\s*$)")
             token.routine = routine
             pos = routine.end
     else:
@@ -116,33 +115,33 @@
             pos = m_name.end()
         if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '+':
             pos = pos + 1
-            offset = parse_expr(mumps_module, line, pos, r"(\^|[ ):,]|\s*$)")
+            offset = parse_expr(routine, line, pos, r"(\^|[ ):,]|\s*$)")
             token.offset = offset
             pos = offset.end
         if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '^':
             pos = pos + 1
             m_name = re_name.match(line, pos)
             if not m_name:
-                routine = parse_expr(mumps_module, line, pos, r"([ ),(:]|\s*$)")
+                routine = parse_expr(routine, line, pos, r"([ ),(:]|\s*$)")
                 token.routine = routine
                 pos = routine.end
             else:
                 token.routine = m_name.group()
                 pos = m_name.end()
         if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '(':
-            pos, token.params = consume_actuallist(mumps_module, line, pos + 1)
+            pos, token.params = consume_actuallist(routine, line, pos + 1)
     
     token.end = pos
     return (token, pos)
 
-def parse_emptyline(mumps_module, line, startpos=0):
+def parse_emptyline(routine, line, startpos=0):
     """ parses a line of Mumps code which contains practically nothing"""
     token = Token(EMPTYLINE, startpos)
     token.end = len(line)
-    mumps_module.add_token(token)
+    routine.add_token(token)
     return token
 
-def parse_label(mumps_module, line):
+def parse_label(routine, line):
     """ parses a Mumps label"""
     token = Token(LABEL, 0)
     re_match = re.match(r"[%a-zA-Z0-9]+", line)
@@ -150,13 +149,13 @@
     pos = re_match.end()
     
     if not MUMPS_RE_DICT["cmdEnd"].match(line, pos) and line[pos] == '(':
-        pos, token.params = consume_actuallist(mumps_module, line, pos + 1)
+        pos, token.params = consume_actuallist(routine, line, pos + 1)
 
     token.end = pos
-    mumps_module.add_token(token)
+    routine.add_token(token)
     return token
 
-def parse_comment(mumps_module, line, startpos = 0):
+def parse_comment(routine, line, startpos = 0):
     """ parses a Mumps comment"""
     re_match = MUMPS_RE_DICT["comment"].match(line, startpos)
     val = re_match.group("comment")
@@ -169,10 +168,10 @@
         token = Token(COMMENT, startpos)
         token.val = val[1:]
     token.end = len(line)
-    mumps_module.add_token(token)
+    routine.add_token(token)
     return token
 
-def parse_expr(mumps_module, line, startpos, terminator = r"([ ]|\s*$)"):
+def parse_expr(routine, line, startpos, terminator = r"([ ]|\s*$)"):
     """ parses a Mumps expression by recursive descent"""
     #if __debug__: print "parse_expr %d [%s]" % (startpos, line[startpos:])
     
@@ -192,7 +191,7 @@
                     sub_token.maxrep = int(atom.group("mxrp"))
             if atom.group("str"):
                 sub_token.match_str = parse_expr(\
-                    mumps_module, line, atom.start("str"), r'\w|[ .,:)(]|\s*$')
+                    routine, line, atom.start("str"), r'\w|[ .,:)(]|\s*$')
                 pos = sub_token.match_str.end
             elif atom.group("altlist"):
                 sub_token.alt_list = []
@@ -213,8 +212,7 @@
     def consume_sub_expr(mobj):
         """ parses a parens-enclosed sub-expression"""
         token = Token(EXPR, mobj.start())
-        token.expr_list = [ \
-            parse_expr(mumps_module, line, mobj.end(), r"([)])"), ]
+        token.expr_list = [ parse_expr(routine, line, mobj.end(), r"([)])"), ]
         pos = token.expr_list[-1].end + 1
         return (token, pos) 
 
@@ -251,18 +249,18 @@
         """ parses a Mumps naked reference"""
         token = Token(OPNAKEDREF, mobj.start())
         pos = mobj.end()
-        pos, token.indices = consume_actuallist(mumps_module, line, pos)
+        pos, token.indices = consume_actuallist(routine, line, pos)
         return (token, pos)
 
     def consume_indirection(mobj):
         """ parses a Mumps indirection argument"""
         token = Token(INDIRECTION, mobj.start())
-        expr = parse_expr(mumps_module, line, mobj.end(), \
-                         r"(\^|\\|[-@:,+=><#&!*/ ')]|\s*$)")
+        expr = parse_expr(routine, line, mobj.end(), \
+                          r"(\^|\\|[-@:,+=><#&!*/ ')]|\s*$)")
         token.expr = expr
         pos = expr.end
         if line[pos] == '@' and line[pos + 1] == '(':
-            pos, indices = consume_actuallist(mumps_module, line, pos + 2)
+            pos, indices = consume_actuallist(routine, line, pos + 2)
             token.indices = indices               
         return (token, pos)
 
@@ -275,7 +273,7 @@
         token.varname = mobj.group("var")
         pos = mobj.end("var")
         if mobj.group("indexed"):
-            pos, indices = consume_actuallist(mumps_module, line, pos + 1)
+            pos, indices = consume_actuallist(routine, line, pos + 1)
             token.indices = indices
         return (token, pos)
 
@@ -283,7 +281,7 @@
         """ parses a Mumps extrinsic function or variable"""
         pos = mobj.end()
         token = Token(USERFUNC, pos)
-        (entry_ref, end_pos) = consume_entry_ref(mumps_module, line, pos)
+        (entry_ref, end_pos) = consume_entry_ref(routine, line, pos)
         token.entry_ref = entry_ref
         return (token, end_pos)
 
@@ -295,13 +293,13 @@
             toktype = INTRINSIC_FUNCS.get(name, F_UNKNOWN)
             token = Token(toktype, mobj.start())
             if toktype == F_TEXT:
-                (params, end_pos) = consume_entry_ref(mumps_module, line, pos)
+                (params, end_pos) = consume_entry_ref(routine, line, pos)
                 token.params = params
                 pos = end_pos + 1
             else:
                 if toktype == F_UNKNOWN:
                     token.name = name
-                pos, token.params = consume_actuallist(mumps_module, line, pos)
+                pos, token.params = consume_actuallist(routine, line, pos)
         else: # vars...
             toktype = INTRINSIC_VARS.get(name, V_UNKNOWN)
             token = Token(toktype, mobj.start())
@@ -318,7 +316,7 @@
         if toktype == SSV_UNKNOWN:
             token.name = name
         if mobj.group("indexed"):
-            pos, indices = consume_actuallist(mumps_module, line, pos + 1)
+            pos, indices = consume_actuallist(routine, line, pos + 1)
             token.indices = indices
         return (token, pos)
         
@@ -326,7 +324,7 @@
         """ parses mumps-style pattern-matchine patterns"""
         pos = mobj.end()
         token = Token(OPPATMATCH, mobj.start())
-        (token.atom_list, pos) = consume_pattern(mumps_module, line, pos)
+        (token.atom_list, pos) = consume_pattern(routine, line, pos)
         token.end = pos
         return (token, pos)
 
@@ -360,7 +358,7 @@
                 break
 
         if not pattern_match:
-            raise ParseError(mumps_module, line, "No Pattern match", pos )
+            raise ParseError(routine, line, "No Pattern match", pos )
 
     token.end = pos
     if len(token.expr_list)==2:
@@ -373,43 +371,41 @@
         token = token.expr_list[0]
     return token
 
-def parse_command(mumps_module, line, startpos=0):
+def parse_command(routine, line, startpos=0):
     """parses all known Mumps commands"""
 
-    def consume_arg_indirection(mumps_module, line, pos):
+    def consume_arg_indirection(routine, line, pos):
         """ parses an argument indirection expression"""
         mterminated = MUMPS_RE_DICT["cmdEnd"]
-        if not mterminated.match(line, pos) and \
-           line[pos:pos+2] == '@(':
-            indirection = parse_expr(mumps_module, line, pos, r"([ ,:]|\s*$)")
+        if not mterminated.match(line, pos) and line[pos:pos+2] == '@(':
+            indirection = parse_expr(routine, line, pos, r"([ ,:]|\s*$)")
 
             new_pos = indirection.end
             if mterminated.match(line, new_pos):
-                mumps_module.last_token().indirection = indirection
-                mumps_module.end_token(new_pos)
+                routine.last_token().indirection = indirection
+                routine.end_token(new_pos)
                 return True
         return False
          
-    def parse_xecute(mumps_module, line, pos):
+    def parse_xecute(routine, line, pos):
         """ parses the Mumps Xecute command"""
         expr_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            exprtok = parse_expr(mumps_module, line, pos, r"([ :,]|\s*$)")
+            exprtok = parse_expr(routine, line, pos, r"([ :,]|\s*$)")
             pos = exprtok.end
             if line[pos] == ":":
-                condtok = parse_expr(mumps_module, line, pos + 1, \
-                                     r"([ ,]|\s*$)")
+                condtok = parse_expr(routine, line, pos + 1, r"([ ,]|\s*$)")
                 exprtok.post_condition(condtok)
                 pos = condtok.end
             if line[pos] == ",":
                 pos = pos + 1
             expr_list.append(exprtok)
             
-        mumps_module.last_token().Xecute = expr_list
-        mumps_module.end_token(pos + 1)
+        routine.last_token().Xecute = expr_list
+        routine.end_token(pos + 1)
 
-    def parse_write(mumps_module, line, pos):
+    def parse_write(routine, line, pos):
         """ parses the Mumps Write command"""
         write_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
@@ -422,25 +418,24 @@
                 pos = pos + 1
             elif line[pos] == '?':
                 sub_token = Token(FCC_MOV, pos)
-                sub_token.offset = parse_expr(mumps_module, line, pos+1, \
+                sub_token.offset = parse_expr(routine, line, pos+1, \
                                               r"([, ]|\s*$)")
                 pos = sub_token.offset.end
             elif line[pos] == '*':
                 sub_token = Token(FCC_CHARVAL, pos)
-                sub_token.val = parse_expr(mumps_module, line, pos+1, \
-                                               r"([, ]|\s*$)")
+                sub_token.val = parse_expr(routine, line, pos+1, r"([, ]|\s*$)")
                 pos = sub_token.val.end
             else:
-                sub_token = parse_expr(mumps_module, line, pos, r"([, ]|\s*$)")
+                sub_token = parse_expr(routine, line, pos, r"([, ]|\s*$)")
                 pos = sub_token.end
             if line[pos] == ',':
                 pos = pos + 1
             write_list.append(sub_token)
 
-        mumps_module.last_token().write_list = write_list
-        mumps_module.end_token(pos)
+        routine.last_token().write_list = write_list
+        routine.end_token(pos)
 
-    def parse_read(mumps_module, line, pos):
+    def parse_read(routine, line, pos):
         """ parses the Mumps Read command"""
         read_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
@@ -453,51 +448,50 @@
                 pos = pos + 1
             elif line[pos] == '?':
                 sub_token = Token(FCC_MOV, pos)
-                sub_token.offset = parse_expr(mumps_module, line, pos + 1, \
+                sub_token.offset = parse_expr(routine, line, pos + 1, \
                                               r"([, ]|\s*$)")
                 pos = sub_token.offset.end
             elif line[pos] == '"': # it's a string.
-                sub_token = parse_expr(mumps_module, line, pos, r"([, ]|\s*$)")
+                sub_token = parse_expr(routine, line, pos, r"([, ]|\s*$)")
                 pos = sub_token.end
             elif line[pos] == '*':
                 sub_token = Token(FCC_CHARVAL, pos)
-                char_val_name = parse_expr(mumps_module, line, pos + 1, \
+                char_val_name = parse_expr(routine, line, pos + 1, \
                                            r"([:, ]|\s*$)")
                 sub_token.char_val_name = char_val_name
                 pos = char_val_name.end
             else:
-                sub_token = parse_expr(mumps_module, line, pos + 1, \
-                                 r"([#:, ]|\s*$)")
+                sub_token = parse_expr(routine, line, pos + 1, r"([#:, ]|\s*$)")
                 pos = sub_token.end
                 if not mterminated.match(line, pos) and line[pos] == '#':
-                    max_chars = parse_expr(mumps_module, line, pos + 1, \
+                    max_chars = parse_expr(routine, line, pos + 1, \
                                            r"([:, ]|\s*$)")
                     sub_token.max_chars = max_chars 
                     pos = max_chars.end
             if not mterminated.match(line, pos) and line[pos] == ':':
-                timeout = parse_expr(mumps_module, line, pos + 1, r"[ ,]|\s*$")
+                timeout = parse_expr(routine, line, pos + 1, r"[ ,]|\s*$")
                 sub_token.timeout = timeout
                 pos = timeout.end
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
             read_list.append(sub_token)
 
-        mumps_module.last_token().read_list = read_list
-        mumps_module.end_token(pos)
+        routine.last_token().read_list = read_list
+        routine.end_token(pos)
                 
-    def parse_view(mumps_module, line, pos):
+    def parse_view(routine, line, pos):
         """parses the Mumps View command"""
         keyword_items = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
             item = {}
-            keyword = parse_expr(mumps_module, line, pos, r"([:, ]|\s*$)")
+            keyword = parse_expr(routine, line, pos, r"([:, ]|\s*$)")
             item["keyword"] = keyword
             pos = keyword.end
             expressions = []
             while not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                expr = parse_expr(mumps_module, line, pos, r"([:, ]|\s*$)")
+                expr = parse_expr(routine, line, pos, r"([:, ]|\s*$)")
                 pos = expr.end
                 expressions.append(expr)
             item["expressions"] = expressions
@@ -505,37 +499,36 @@
                 pos = pos + 1
             keyword_items.append(item)
 
-        mumps_module.last_token().keyword_items = keyword_items
-        mumps_module.end_token(pos)
+        routine.last_token().keyword_items = keyword_items
+        routine.end_token(pos)
 
-    def parse_merge(mumps_module, line, pos):
+    def parse_merge(routine, line, pos):
         """parses the Mumps Merge Command"""
         items = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
             merge_item = {}
-            recipient = parse_expr(mumps_module, line, pos, r"([=, ]|\s*$)")
+            recipient = parse_expr(routine, line, pos, r"([=, ]|\s*$)")
             merge_item["l_item"] = recipient
             pos = recipient.end
             if not mterminated.match(line, pos) and line[pos] == '=':
                 pos = pos + 1
-                copy_item = parse_expr(mumps_module, line, pos, r"([, ]|\s*$)")
+                copy_item = parse_expr(routine, line, pos, r"([, ]|\s*$)")
                 merge_item["r_item"] = copy_item
                 pos = copy_item.end
             items.append(merge_item)
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
+        routine.last_token().items = items
+        routine.end_token(pos)
 
-        mumps_module.last_token().items = items
-        mumps_module.end_token(pos)
-
-    def parse_devicecmd(mumps_module, line, pos):
+    def parse_devicecmd(routine, line, pos):
         """parses the Mumps Open, Close, and Use commands"""
         device_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
             device = {}
-            expr = parse_expr(mumps_module, line, pos + 1, r"([ :,]|\s*$)")
+            expr = parse_expr(routine, line, pos + 1, r"([ :,]|\s*$)")
             device["Expr"] = expr
             pos = expr.end
             if not mterminated.match(line, pos) and line[pos] == ':':
@@ -544,30 +537,37 @@
                     pos = pos + 1
                     keyword_list = []
                     while line[pos] != ')':
-                        keyword = parse_expr(mumps_module, line, pos, r"[,:=)]")
+                        keyword = parse_expr(routine, line, pos, r"[,:=)]")
                         keyword_list.append(keyword)
                         pos = keyword.end
                         if line[pos] == "=":
-                            kval = parse_expr(mumps_module, line, pos, r"[,:)]")
+                            kval = parse_expr(routine, line, pos, r"[,:)]")
                             keyword.keyval = kval
                             pos = kval.end
                         if line[pos] in (':', ','):
                             pos = pos + 1
                     device["keyword_list"] = keyword_list
                     pos = pos + 1
+                else:
+                    keyword = parse_expr(routine, line, pos, r"[ =:,]|\s*$")
+                    device["keyword_list"] = [keyword, ]
+                    pos = keyword.end
+                    if not mterminated.match(line, pos) and line[pos] == "=":
+                        keyword.keyval = parse_expr(routine, line, pos + 1,
+                                                    r"[ ,:)]|\s*$")
+                        pos = keyword.keyval.end
             if not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                timeout = parse_expr(mumps_module, line, pos, r"[ ,]|\s*$")
+                timeout = parse_expr(routine, line, pos, r"[ ,]|\s*$")
                 device["Expr"].timeout = timeout
                 pos = timeout.end
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
             device_list.append(device)
-                
-        mumps_module.last_token().device_list = device_list
-        mumps_module.end_token(pos)
+        routine.last_token().device_list = device_list
+        routine.end_token(pos)
 
-    def parse_set(mumps_module, line, pos):
+    def parse_set(routine, line, pos):
         """ parses the Mumps Set command"""
         var_set = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
@@ -577,7 +577,7 @@
                 pos = pos + 1
                 var_list = []
                 while line[pos] != ")":
-                    varname = parse_expr(mumps_module, line, pos, r"([,)])")
+                    varname = parse_expr(routine, line, pos, r"([,)])")
                     var_list.append(varname)
                     pos = varname.end
                     if line[pos] == ',':
@@ -585,12 +585,12 @@
                 var["var_names"] = var_list
                 pos = pos + 1
             else:
-                varname = parse_expr(mumps_module, line, pos, r"([,= ]|\s*$)")
+                varname = parse_expr(routine, line, pos, r"([,= ]|\s*$)")
                 var["varname"] = varname
                 pos = varname.end
             if not mterminated.match(line, pos) and line[pos] == '=':
                 pos = pos + 1
-                val = parse_expr(mumps_module, line, pos, r"([ ,]|\s*$)")
+                val = parse_expr(routine, line, pos, r"([ ,]|\s*$)")
                 var["val"] = val
                 pos = val.end
             else: # note: this is somewhat of an assumption, but...
@@ -599,11 +599,10 @@
             var_set.append(var)
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
+        routine.last_token().var_set = var_set
+        routine.end_token(pos)
 
-        mumps_module.last_token().var_set = var_set
-        mumps_module.end_token(pos)
-
-    def parse_lock(mumps_module, line, pos):
+    def parse_lock(routine, line, pos):
         """parses the Mumps Lock command"""
         lock_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
@@ -616,7 +615,7 @@
                 nref_list = []
                 pos = pos + 1
                 while line[pos] != ')':
-                    nref = parse_expr(mumps_module, line, pos, r"([,)])")
+                    nref = parse_expr(routine, line, pos, r"([,)])")
                     pos = nref.end
                     nref_list.append(nref)
                     if line[pos] == ',':
@@ -624,33 +623,32 @@
                 lock_item["nrefs"] = nref_list
                 pos = pos + 1 # eat the closing parenthesis
             else:
-                nref = parse_expr(mumps_module, line, pos, r"([ ,:]|\s*$)")
+                nref = parse_expr(routine, line, pos, r"([ ,:]|\s*$)")
                 pos = nref.end
                 lock_item["nrefs"] = (nref, )
             if not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                timeout = parse_expr(mumps_module, line, pos, r"[ ,]|\s*$")
+                timeout = parse_expr(routine, line, pos, r"[ ,]|\s*$")
                 for nref in lock_item["nrefs"]:
                     nref.timeout = timeout
                 pos = timeout.end
             lock_list.append(lock_item)
             if line[pos] == ',':
                 pos = pos + 1
-                
-        mumps_module.last_token().lock_list = lock_list
-        mumps_module.end_token(pos)
+        routine.last_token().lock_list = lock_list
+        routine.end_token(pos)
 
-    def parse_job(mumps_module, line, pos):
+    def parse_job(routine, line, pos):
         """parses the Mumps Job command"""
         entry_ref_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            (entry_ref, pos) = consume_entry_ref(mumps_module, line, pos)
+            (entry_ref, pos) = consume_entry_ref(routine, line, pos)
             if not mterminated.match(line, pos) and line[pos] == '(':
                 pos = pos + 1
                 params = []
                 while line[pos] != ")":
-                    paramtok = parse_expr(mumps_module, line, pos, r"([,)])")
+                    paramtok = parse_expr(routine, line, pos, r"([,)])")
                     params.append(paramtok)
                     pos = paramtok.end
                     if line[pos] == ',':
@@ -663,7 +661,7 @@
                     pos = pos + 1
                     keyword_list = []
                     while line[pos] != ')':
-                        keyword = parse_expr(mumps_module, line, pos, r"([:)])")
+                        keyword = parse_expr(routine, line, pos, r"([:)])")
                         keyword_list.append(keyword)
                         pos = keyword.end
                         if line[pos] == ':':
@@ -672,27 +670,25 @@
                     entry_ref.keyword_list = keyword_list
             if not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                timeout = parse_expr(mumps_module, line, pos, r"[ ,]|\s*$")
+                timeout = parse_expr(routine, line, pos, r"[ ,]|\s*$")
                 entry_ref.timeout = timeout
                 pos = timeout.end
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
             entry_ref_list.append(entry_ref)
+        routine.last_token().entry_ref = entry_ref_list
+        routine.end_token(pos)
 
-        mumps_module.last_token().entry_ref = entry_ref_list
-        mumps_module.end_token(pos)
-
-    def parse_quit(mumps_module, line, pos):
+    def parse_quit(routine, line, pos):
         """parses the Mumps Quit command"""
-        mterminated = MUMPS_RE_DICT["cmdEnd"]
+        mterminated = re.compile(r"[; ]|\s*$")
         if not mterminated.match(line, pos):
-            return_val = parse_expr(mumps_module, line, pos)
+            return_val = parse_expr(routine, line, pos)
             pos = return_val.end
-            mumps_module.last_token().expr = return_val
+            routine.last_token().expr = return_val
+        routine.end_token(pos)
 
-        mumps_module.end_token(pos)
-
-    def parse_new(mumps_module, line, pos):
+    def parse_new(routine, line, pos):
         """parses the Mumps New command"""
         new_list = []
         excl_list = []
@@ -701,24 +697,24 @@
             if line[pos] == '(':
                 pos = pos + 1
                 while line[pos] != ')':
-                    vartok = parse_expr(mumps_module, line, pos, r"([,)])")
+                    vartok = parse_expr(routine, line, pos, r"([,)])")
                     pos = vartok.end
                     excl_list.append(vartok)
                     if line[pos] == ',':
                         pos = pos + 1
                 pos = pos + 1 # eat the closing parens.
             else:
-                vartok = parse_expr(mumps_module, line, pos, r"([ ,]|\s*$)")
+                vartok = parse_expr(routine, line, pos, r"([ ,]|\s*$)")
                 pos = vartok.end
                 new_list.append(vartok)
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
                 
-        mumps_module.last_token().new_list = new_list
-        mumps_module.last_token().excl_list = excl_list
-        mumps_module.end_token(pos)
+        routine.last_token().new_list = new_list
+        routine.last_token().excl_list = excl_list
+        routine.end_token(pos)
 
-    def parse_kill(mumps_module, line, pos):
+    def parse_kill(routine, line, pos):
         """parses the Mumps Kill command"""
         kill_list = []
         excl_list = []
@@ -727,82 +723,81 @@
             if line[pos] == '(':
                 pos = pos + 1
                 while line[pos] != ')':
-                    vartok = parse_expr(mumps_module, line, pos, r"([,)])")
+                    vartok = parse_expr(routine, line, pos, r"([,)])")
                     pos = vartok.end
                     excl_list.append(vartok)
                     if line[pos] == ',':
                         pos = pos + 1
                 pos = pos + 1 # eat the closing parens.
             else:
-                vartok = parse_expr(mumps_module, line, pos, r"([ ,]|\s*$)")
+                vartok = parse_expr(routine, line, pos, r"([ ,]|\s*$)")
                 pos = vartok.end
                 kill_list.append(vartok)
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
                 
-        mumps_module.last_token().kill_list = kill_list
-        mumps_module.last_token().excl_list = excl_list
-        mumps_module.end_token(pos)
+        routine.last_token().kill_list = kill_list
+        routine.last_token().excl_list = excl_list
+        routine.end_token(pos)
                            
-    def parse_if(mumps_module, line, pos):
+    def parse_if(routine, line, pos):
         """parses the Mumps If command"""
         expr_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            exprtok = parse_expr(mumps_module, line, pos, r"([ ,]|\s*$)")
+            exprtok = parse_expr(routine, line, pos, r"([ ,]|\s*$)")
             expr_list.append(exprtok)
             pos = exprtok.end
             if line[pos] == ",":
                 pos = pos + 1
-        mumps_module.last_token().condition_list = expr_list
-        mumps_module.end_token(pos + 1)
+        routine.last_token().condition_list = expr_list
+        routine.end_token(pos + 1)
 
-    def parse_hang(mumps_module, line, pos):
+    def parse_hang(routine, line, pos):
         """parses the Mumps Hang/Halt commands"""
-        timetok = parse_expr(mumps_module, line, pos)
-        mumps_module.last_token().HangTime = timetok
-        mumps_module.end_token(timetok.end)
+        timetok = parse_expr(routine, line, pos)
+        routine.last_token().HangTime = timetok
+        routine.end_token(timetok.end)
 
-    def parse_goto(mumps_module, line, pos):
+    def parse_goto(routine, line, pos):
         """parse the Mumps Goto command"""
         entry_ref_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            (entry_ref, pos) = consume_entry_ref(mumps_module, line, pos)
+            (entry_ref, pos) = consume_entry_ref(routine, line, pos)
             if not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                condtok = parse_expr(mumps_module, line, pos, r"([ ,]|\s$)")
+                condtok = parse_expr(routine, line, pos, r"([ ,]|\s$)")
                 entry_ref.post_condition(condtok)
                 pos = condtok.end
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
             entry_ref_list.append(entry_ref)
 
-        mumps_module.last_token().entry_ref = entry_ref_list
-        mumps_module.end_token(pos)
+        routine.last_token().entry_ref = entry_ref_list
+        routine.end_token(pos)
 
-    def parse_for(mumps_module, line, pos):
+    def parse_for(routine, line, pos):
         """ parses the Mumps For command"""
         loops = []
         loop_incr_var = None
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         if not mterminated.match(line, pos):
-            loop_incr_var = parse_expr(mumps_module, line, pos, r"([=])")
+            loop_incr_var = parse_expr(routine, line, pos, r"([=])")
             pos = loop_incr_var.end + 1 # eat the equal sign.
             while not mterminated.match(line, pos):
                 loop_vals = {}
-                loop_vals["initVal"] = parse_expr(mumps_module, line, pos, \
+                loop_vals["initVal"] = parse_expr(routine, line, pos, \
                                                   r"([,: ]|\s$)")
                 pos = loop_vals["initVal"].end
                 if not mterminated.match(line, pos) and line[pos] == ':':
                     pos = pos + 1
-                    incr_val = parse_expr(mumps_module, line, pos, \
-                                          r"([ :,]|\s$)")
+                    incr_val = parse_expr(routine, line, pos, r"([ :,]|\s$)")
                     loop_vals["IncrVal"] = incr_val
                     pos = incr_val.end
                 if not mterminated.match(line, pos) and line[pos] == ':':
                     pos = pos + 1
-                    terminal_val = parse_expr(mumps_module, line, pos, \
+                    terminal_val = parse_expr(routine, line, pos, \
                                               r"([ :,]|\s$)")
                     loop_vals["TermVal"] = terminal_val
                     pos = terminal_val.end
@@ -810,21 +805,21 @@
                 if not mterminated.match(line, pos) and line[pos] == ',':
                     pos = pos + 1
                 
-        mumps_module.last_token().loop_incr_var = loop_incr_var
-        mumps_module.last_token().for_loops = loops
-        mumps_module.end_token(pos)
+        routine.last_token().loop_incr_var = loop_incr_var
+        routine.last_token().for_loops = loops
+        routine.end_token(pos)
 
-    def parse_do(mumps_module, line, pos):
+    def parse_do(routine, line, pos):
         """parses the Mumps Do command"""
         entry_ref_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            (entry_ref, pos) = consume_entry_ref(mumps_module, line, pos)
+            (entry_ref, pos) = consume_entry_ref(routine, line, pos)
             if not mterminated.match(line, pos) and line[pos] == '(':
                 pos = pos + 1
                 params = []
                 while line[pos] != ")":
-                    paramtok = parse_expr(mumps_module, line, pos, r"([,)])")
+                    paramtok = parse_expr(routine, line, pos, r"([,)])")
                     params.append(paramtok)
                     pos = paramtok.end
                     if line[pos] == ',':
@@ -833,43 +828,49 @@
                 pos = pos + 1
             if not mterminated.match(line, pos) and line[pos] == ':':
                 pos = pos + 1
-                condtok = parse_expr(mumps_module, line, pos, r"([ ,]|\s$)")
+                condtok = parse_expr(routine, line, pos, r"([ ,]|\s$)")
                 entry_ref.post_condition(condtok)
                 pos = condtok.end
             if not mterminated.match(line, pos) and line[pos] == ',':
                 pos = pos + 1
             entry_ref_list.append(entry_ref)
 
-        mumps_module.last_token().entry_ref = entry_ref_list
-        mumps_module.end_token(pos)
+        routine.last_token().entry_ref = entry_ref_list
+        routine.end_token(pos)
         
-    def parse_break(mumps_module, line, pos):
+    def parse_break(routine, line, pos):
         """parse the Mumps Break command"""
         expr_list = []
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            exprtok = parse_expr(mumps_module, line, pos, r"([ :,]|\s*$)")
+            exprtok = parse_expr(routine, line, pos, r"([ :,]|\s*$)")
             pos = exprtok.end
             if line[pos] == ":":
-                condtok = parse_expr(mumps_module, line, pos+1, r"([ ,]|\s*$)")
+                condtok = parse_expr(routine, line, pos+1, r"([ ,]|\s*$)")
                 exprtok.post_condition(condtok)
                 pos = condtok.end
             if line[pos] == ",":
                 pos = pos + 1
             expr_list.append(exprtok)
             
-        mumps_module.last_token().Xecute = expr_list
-        mumps_module.end_token(pos + 1)
+        routine.last_token().Xecute = expr_list
+        routine.end_token(pos + 1)
 
-    def consume_unknowncommand(mumps_module, line, pos):
+    def consume_unknowncommand(routine, line, pos):
         """eat the argument of an unknown command"""
         val = ""
         mterminated = MUMPS_RE_DICT["cmdEnd"]
         while not mterminated.match(line, pos):
-            val = val + line[pos]
-            pos = pos + 1
-        mumps_module.last_token().val = val
-        mumps_module.end_token(pos)
+            if line[pos] == '"':
+                str_val = parse_expr(routine, line, pos, r'[ _,:)]|\s*$')
+                new_pos = str_val.end
+            else:
+                new_pos = pos + 1
+            val = val + line[pos:new_pos]
+            pos = new_pos
+            
+        routine.last_token().val = val
+        routine.end_token(pos)
         
     command_list = {BREAKCMD:parse_break,
                    CLOSECMD:parse_devicecmd,
@@ -901,29 +902,29 @@
     pos = re_match.end("cmd") + 1
 
     toktype = CMD_TOKEN_DICT.get(cmd, UNKNOWNCMD)
-    mumps_module.add_token(Token(toktype, startpos))
+    routine.add_token(Token(toktype, startpos))
     if toktype == UNKNOWNCMD:
-        mumps_module.last_token().name = cmd
+        routine.last_token().name = cmd
     if re_match.group("indents"): # count the periods for the nesting level...
-        mumps_module.indent_token( \
+        routine.indent_token( \
             len(re.findall("[.]", line[startpos:re_match.start("cmd")]))) 
     if line[re_match.end("cmd")] == ':':
-        condtok = parse_expr(mumps_module, line, pos)
-        mumps_module.post_condition(condtok)
+        condtok = parse_expr(routine, line, pos)
+        routine.post_condition(condtok)
         pos = condtok.end + 1
     
-    if not consume_arg_indirection(mumps_module, line, pos):
+    if not consume_arg_indirection(routine, line, pos):
         if toktype in command_list:
             parse_func = command_list[toktype]
-            parse_func(mumps_module, line, pos)
+            parse_func(routine, line, pos)
         else:
-            mumps_module.end_token(pos)
+            routine.end_token(pos)
 
-    return mumps_module.last_token()
+    return routine.last_token()
 
-def parseMumps(mumps_module, open_fileinput= None):
+def parseMumps(routine, open_fileinput= None):
     """ Parse all the code of given Mumps module."""
-    mumps_module.empty_tokenlist()
+    routine.empty_tokenlist()
     
     pattern_list = [
         (MUMPS_RE_DICT["label"], parse_label, "label"),
@@ -934,14 +935,14 @@
     if open_fileinput:
         input_file = open_fileinput
     else:
-        input_file = fileinput.input(mumps_module.input_file)
+        input_file = fileinput.input(routine.input_file)
 
     try:
         for line in input_file:
-            if fileinput.lineno() < mumps_module.start:
+            if fileinput.lineno() < routine.start:
                 continue
 
-            if mumps_module.end != -1 and fileinput.lineno() > mumps_module.end:
+            if routine.end != -1 and fileinput.lineno() > routine.end:
                 break
 
             #if __debug__: print "%d :%s" % (fileinput.lineno(), line),
@@ -950,7 +951,7 @@
             for (pattern, parser, dscr) in pattern_list:
                 if pattern.match(line):
                     pattern_match = True
-                    token = parser(mumps_module, line)
+                    token = parser(routine, line)
                     token.line_no(fileinput.lineno())
                     pos = token.end
                    
@@ -960,18 +961,18 @@
                             # no need to scan for labels...
                             if pattern.match(line, pos):
                                 inside_pattern_match = True
-                                token = parser(mumps_module, line, pos)
+                                token = parser(routine, line, pos)
                                 pos = token.end
                                 break
                             
                         if not inside_pattern_match:
-                            raise ParseError(mumps_module, line, \
+                            raise ParseError(routine, line, \
                                              "no Matching pattern", pos, \
                                              fileinput.lineno())
                     break
 
             if not pattern_match:
-                raise ParseError(mumps_module, line, "no Pattern match", pos, \
+                raise ParseError(routine, line, "no Pattern match", pos, \
                                  fileinput.lineno())
     finally:
         if not open_fileinput:
@@ -988,8 +989,9 @@
                     parseMumps(the_module)
 
     try:
+        #mods = parse_for_routines("../testfiles/kernel.m2p", "./out")
         mods = parse_for_routines("../testfiles/fm22.m2p", "./out")
-        #parsemodule(mods,"ACKQUTL1")
+        #parsemodule(mods,"ZTMB")
         for the_module in mods:
             print the_module.mod_name
             parseMumps(the_module)


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