def _ValToArithOrError(self, val, int_coerce=True, blame_word=None, span_id=const.NO_INTEGER): if span_id == const.NO_INTEGER and blame_word: span_id = word.LeftMostSpanForWord(blame_word) #log('_ValToArithOrError span=%s blame=%s', span_id, blame_word) try: i = self._ValToArith(val, span_id, int_coerce=int_coerce) except util.FatalRuntimeError as e: if self.exec_opts.strict_arith: raise else: i = 0 span_id = dev.SpanIdFromError(e) if self.arena: # BoolEvaluator for test builtin doesn't have it. if span_id != const.NO_INTEGER: ui.PrintFilenameAndLine(span_id, self.arena) else: log('*** Warning has no location info ***') warn(e.UserErrorString()) return i
def PrettyPrintError(parse_error, arena, f=sys.stderr): span_id = dev.SpanIdFromError(parse_error) # TODO: Should there be a special span_id of 0 for EOF? const.NO_INTEGER # means there is no location info, but 0 could mean that the location is EOF. # So then you query the arena for the last line in that case? # Eof_Real is the ONLY token with 0 span, because it's invisible! # Well Eol_Tok is a sentinel with a span_id of const.NO_INTEGER. I think # that is OK. # Problem: the column for Eof could be useful. if span_id == const.NO_INTEGER: # Any clause above might return this. # This is usually a bug. print('*** Error has no source location info ***', file=f) else: PrintFilenameAndLine(span_id, arena, f=f) print(parse_error.UserErrorString(), file=f)