def read(parser, stream):
source = stream() if callable(stream) else stream<EOL>try:<EOL><INDENT>text = source.read()<EOL>stream_name = getattr(source, '<STR_LIT:name>', None)<EOL>try:<EOL><INDENT>result = parser(text)<EOL><DEDENT>except ECMASyntaxError as e:<EOL><INDENT>error_name = repr_compat(stream_name or source)<EOL>raise type(e)('<STR_LIT>' % (str(e), error_name))<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if callable(stream):<EOL><INDENT>source.close()<EOL><DEDENT><DEDENT>result.sourcepath = stream_name<EOL>return result<EOL>
Return an AST from the input ES5 stream.

Arguments

parser
    A parser instance.
stream
    Either a stream object or a callable that produces one.  The
    stream object to read from; its 'read' method will be invoked.

    If a callable was provided, the 'close' method on its return
    value will be called to close the stream.