[Mumps2Py:] [73] fixed string handling; finally, I think.

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


Revision: 73
Author:   pgallot
Date:     2008-01-31 21:35:10 +0000 (Thu, 31 Jan 2008)

Log Message:
-----------
fixed string handling; finally, I think.
and cruft removal.

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


Modified: trunk/mumps2py/mumps2tok.py
===================================================================
--- trunk/mumps2py/mumps2tok.py	2008-01-31 21:33:21 UTC (rev 72)
+++ trunk/mumps2py/mumps2tok.py	2008-01-31 21:35:10 UTC (rev 73)
@@ -17,7 +17,6 @@
 """ extract tokens from the Mumps source code """
 
 import re, fileinput
-from mumps_module import ModuleInfo
 from tokens import *
 
 GLOBALDB = 0 # debugging variable.
@@ -49,7 +48,7 @@
     "var":re.compile(r"((?P<globalvar>\^{1})|(?P<pbr>[.]{1}))?(?P<var>[A-Za-z%][A-Za-z0-9]*)(?P<indexed>[(]{1})?"),
     "indirection":re.compile(r"@"),
     "op":re.compile(r"[-_/+']|([']?(([*]{1,2})|([]]{1,2})|\\|[[=><#&!/]))"),
-    "str":re.compile(r"([\"]{3}|[\"]{1})(([\"]{2})*?|.)*([\"]{3}|[\"]{1})"),
+    "str":re.compile(r'"'),
     "num":re.compile(r"([0-9]*[.])?[0-9]+([eE][+-][0-9]+)?"),
     "extr":re.compile(r"[$]{2}(?P<label>\w+)(\^(?P<routine>[%A-Za-z][A-Za-z0-9]*))?(?P<func>[(]{1})?"),
     "intr":re.compile(r"[$]{1}(?P<intrinsic>[A-Za-z0-9]+)(?P<func>[(]{1})?"),
@@ -221,9 +220,20 @@
 
     def consume_str(mobj):
         """ parses a Mumps-string"""
-        token = Token(STRINGLITERAL, mobj.start())
-        token.val = mobj.group()
-        return (token, mobj.end())
+        startpos = mobj.start()
+        pos = startpos+1
+        token = Token(STRINGLITERAL, startpos)
+        len_line = len(line)
+        while pos < len_line:
+            if line[pos] != '"':
+                pos = pos + 1
+            elif (pos + 1) < len_line and line[pos + 1] == '"':
+                pos = pos + 2
+            else:
+                pos = pos + 1
+                break
+        token.val = line[startpos:pos]
+        return (token, pos)
 
     def consume_num(mobj):
         """ parses a number"""
@@ -971,27 +981,10 @@
         fileinput.close()
 
 if __name__ == '__main__':
-    from mumps_module import parseForModules
-    MumpsFile = "fm22.rsa"
-    m2py_dir = ".\\out"
+    from mumps_module import parse_for_routines
 
-    f = open(MumpsFile)
-    s = f.readline()
-    f.close()
-
-    if re.search(r"CACHE FORMAT\^~Format=Cache.S~", s):
-        mods = parseForModules(MumpsFile, m2py_dir, 0)
-        try:
-            for module in mods:
-                parseMumps(module)
-        except ParseError, e:
-            print e.error_msg()
-    else:
-        outputname = re.split(r"\..*$", MumpsFile)[0]
-        
-        if __debug__:
-            print outputname
-        try:
-            parseMumps(ModuleInfo(MumpsFile, m2py_dir, outputname))
-        except ParseError, e:
-            print e.error_msg()
+    try:
+        for module in parse_for_routines("fm22.rsa", "./out"):
+            parseMumps(module)
+    except ParseError, err:
+        print err.error_msg()


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