]> thyrsus.com Git - mad.git/commitdiff
Begin to refactor error handling.
authorEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 20:45:32 +0000 (20:45 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Wed, 18 Feb 2004 20:45:32 +0000 (20:45 +0000)
mad

diff --git a/mad b/mad
index ea5b5bd7d9735053b773a2f90b90e2a334c580b1..6ac653c0cd777713b3c490ef1bba08a268e3f7c6 100755 (executable)
--- a/mad
+++ b/mad
@@ -300,7 +300,7 @@ def p_range(t):
     'range : NAME application DOTRANGE NAME application'
     t[0] = ('range', t[1], t[2][0], t[5][0])
     if t[1] != t[4]:
-        sys.stderr.write("variable names in range don't match!")
+        sys.stderr.write("\"%s\", %d: variable names in range don't match!" % (sourcefile, t.lineno(1)))
         sys.exit(1)
 
 ## R
@@ -494,6 +494,7 @@ def p_expression_name(t):
 # Error handling
 
 def p_error(t):
+    "Gets fed an error token."
     sys.stderr.write('"%s", line %d: syntax error at "%s"\n' % (sourcefile, t.lineno, t.value))
 
 import yacc
@@ -507,9 +508,8 @@ madmath = ('elog.','sqrt.','sin.','cos.','tan.',)
 # Map MAD intrinsics to C library functions
 madfunc_map = {'elog':'log'}
 
-def croak(t, msg):
-    (file, line, label, statement) = t
-    sys.stderr.write('"%s", line %d: %s\n' % (file, line, msg))
+def croak(msg):
+    sys.stderr.write('"%s", line %d: %s\n' % (sourcefile, sourceline, msg))
 
 # All MAD variables are global, you have to simulate locals using SAVE DATA and
 # RETURN DATA.  Thus the variable lookup tables about are straight
@@ -541,7 +541,7 @@ def analyze():
         if statement[0] == 'for':
             target = statement[1]
             if  not target in labels:
-                croak((sourcefile,sourceline,label,statement),"no such label as "+`target`)
+                croak("no such label as "+`target`)
                 sys.exit(1)
     # On to actual analysis
     try:
@@ -605,7 +605,7 @@ def analyze():
                 funcline = sourceline
             elif statement[0] == 'read':
                 if statement[1] not in format:
-                    croak(card, "uninitialized format string" +`statement[1]`)
+                    croak("uninitialized format string" +`statement[1]`)
                 else:
                     (fmt, types) = fmt_convert(format[statement[1]])
                     for (vtype, var) in zip(types, statement[2:]):
@@ -660,9 +660,10 @@ def analyze():
                         deck[i] = (sourcefile, sourceline, label, ('entry', name, prev[1]))
                         break
                     elif prev[0] == 'entry':
-                        croak(deck[i-j-1],"multiple ENTRY points are not supported")
+                        (sourcefile,sourceline,label,statement) = deck[i-j-1]
+                        croak("multiple ENTRY points are not supported")
                 else:
-                    croak(deck[i], 'no EXTERNAL declaration matches this ENTRY')
+                    croak('no EXTERNAL declaration matches this ENTRY')
     except:
         sys.stderr.write("mad: internal error while analyzing code for line %d\n" % line)
         (exc_type, exc_value, exc_traceback) = sys.exc_info()