From: Eric S. Raymond Date: Wed, 18 Feb 2004 20:45:32 +0000 (+0000) Subject: Begin to refactor error handling. X-Git-Tag: 1.0~78 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=2d806d111417b6859899e30d2d2dcbe55a1a6379;p=mad.git Begin to refactor error handling. --- diff --git a/mad b/mad index ea5b5bd..6ac653c 100755 --- 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()