def namer(stream_in, matcher): try: (result, stream_out) = matcher() except StopIteration: if show_failures: stream = \ _adjust(fmt('stream = {rest}', **s_kargs(stream_in)), right) str_name = _adjust(name, left // 4, True, True) match = _adjust(fmt(' {0} failed', str_name), left, True) # Python bug #4618 print(match + ' ' + stream, file=out, end=str('\n')) raise StopIteration else: try: try: rest = fmt('{rest}', **s_kargs(stream_out)) except StopIteration: rest = '<EOS>' stream = _adjust(fmt('stream = {0}', rest), right) str_name = _adjust(name, left // 4, True, True) match = _adjust(fmt(' {0} = {1}', str_name, result), left, True) # Python bug #4618 print(match + ' ' + stream, file=out, end=str('\n')) return (result, stream_out) except Exception as e: print('Error in trace', file=out, end=str('\n')) print(repr(e), file=out, end=str('\n')) return (result, stream_out)
def syntax_error_kargs(stream_in, stream_out, results): ''' Helper function for constructing fmt dictionary. ''' kargs = s_kargs(stream_in, prefix='in_') kargs = s_kargs(stream_out, prefix='out_', kargs=kargs) kargs['results'] = results return kargs
def kargs(self, state, prefix='', kargs=None): line_stream = state_to_line_stream(state) return s_kargs(line_stream, prefix=prefix, kargs=kargs)