[Mumps2Py:] [139] added support for device command mnemonic-spaces, extended global syntax, and external functions. |
[ Thread Index |
Date Index
| More lists.mumps2py.org/discuss Archives
]
Revision: 139
Author: pgallot
Date: 2008-02-28 20:27:14 +0000 (Thu, 28 Feb 2008)
Log Message:
-----------
added support for device command mnemonic-spaces, extended global syntax, and external functions.
Modified Paths:
--------------
trunk/mumps2py/mumps2tok.py
Modified: trunk/mumps2py/mumps2tok.py
===================================================================
--- trunk/mumps2py/mumps2tok.py 2008-02-28 20:20:01 UTC (rev 138)
+++ trunk/mumps2py/mumps2tok.py 2008-02-28 20:27:14 UTC (rev 139)
@@ -47,6 +47,8 @@
"str":re.compile(r'"'),
"num":re.compile(r"([0-9]*[.])?[0-9]+([eE][+-][0-9]+)?"),
"extr":re.compile(r"[$]{2}"),
+ "external":re.compile(r"[$][&](?P<package>[%a-zA-Z0-9][A-Za-z0-9]*[.]{1})?"),
+ "extglobal":re.compile(r"\^[|[]"),
"intr":re.compile(r"[$]{1}(?P<intrinsic>[A-Za-z0-9]+)(?P<func>[(]{1})?"),
"structsysvar":re.compile(r"\^[$]{1}(?P<var>[A-Za-z0-9]+)(?P<indexed>[(]{1})?"),
"patmat":re.compile(r"[?]"),
@@ -268,6 +270,27 @@
token.indices = indices
return (token, pos)
+ def consume_extglobal(mobj):
+ """parses an extended global variable reference"""
+ pos = mobj.end()
+ token = VarToken(EXTGLOBALVAR, mobj.start())
+ global_dir = parse_expr( line, pos, r'[,|]|[]]')
+ token.global_dir = global_dir
+ pos = global_dir.end
+ if line[pos] == ',':
+ dummy = parse_expr(line, pos + 1, r'[|]|[]]')
+ token.dummy = dummy
+ pos = dummy.end
+
+ pos = pos + 1
+ mobj2 = MUMPS_RE_DICT["var"].match(line, pos)
+ token.varname = mobj2.group("var")
+ pos = mobj2.end("var")
+ if mobj2.group("indexed"):
+ pos, indices = consume_actuallist(line, pos + 1)
+ token.indices = indices
+ return (token, pos)
+
def consume_extrinsic(mobj):
""" parses a Mumps extrinsic function or variable"""
pos = mobj.end()
@@ -276,6 +299,16 @@
token.entry_ref = entry_ref
return (token, end_pos)
+ def consume_external_func(mobj):
+ """ parses a call to an external (non-MUMPS) function"""
+ pos = mobj.end()
+ token = Token(EXTERNALFUNC, pos)
+ if mobj.group("package"):
+ token.package_name = mobj.group("package")[:-1]
+ (entry_ref, end_pos) = parse_entry_ref(line, pos)
+ token.entry_ref = entry_ref
+ return (token, end_pos)
+
def consume_intrinsic(mobj):
""" parses a Mumps intrinsic function or variable"""
name = mobj.group("intrinsic").upper()
@@ -327,6 +360,8 @@
(MUMPS_RE_DICT["num"], consume_num, "num"),
(MUMPS_RE_DICT["extr"], consume_extrinsic, "extr"),
(MUMPS_RE_DICT["intr"], consume_intrinsic, "intr"),
+ (MUMPS_RE_DICT["external"], consume_external_func, "external"),
+ (MUMPS_RE_DICT["extglobal"], consume_extglobal, "extglobal"),
(MUMPS_RE_DICT["nakedRef"], consume_naked_ref, "nakedRef"),
(MUMPS_RE_DICT["structsysvar"], consume_structsysvar, "structsysvar"),
(MUMPS_RE_DICT["subexpr"], consume_sub_expr, "subexpr")]
@@ -802,9 +837,15 @@
pos = keyword.keyval.end
if not mterminated.match(line, pos) and line[pos] == ':':
pos = pos + 1
- timeout = parse_expr(line, pos, r"[ ,]|\s*$")
+ timeout = parse_expr(line, pos, r"[ ,:]|\s*$")
device["Expr"].timeout = timeout
pos = timeout.end
+ if not mterminated.match(line, pos) and line[pos] == ':':
+ pos = pos + 1
+ mnemonic_space = parse_expr(line, pos, r"[ ,]|\s*$")
+ device["Expr"].mnemonic_space = mnemonic_space
+ pos = mnemonic_space.end
+
if not mterminated.match(line, pos) and line[pos] == ',':
pos = pos + 1
device_list.append(device)
@@ -972,16 +1013,17 @@
def parsemodule(mods, mod_name):
"""parse the module specified by popup"""
if mods:
- for the_module in mods:
- if the_module.mod_name == mod_name:
- parseMumps(the_module)
+ for a_module in mods:
+ if a_module.mod_name == mod_name:
+ parseMumps(a_module)
try:
- #mods = parse_for_routines("../testfiles/kernel.m2p", "./out")
+ #mods = parse_for_routines("../testfiles/vista.m2p", "./out")
mods = parse_for_routines("../testfiles/fm22.m2p", "./out")
#parsemodule(mods,"ZTMB")
for the_module in mods:
print the_module.mod_name
parseMumps(the_module)
+ the_module.empty_tokenlist() # keep memory usage down
except ParseError, err:
print err.error_msg()