def parse_buffer(buffer, mode="<STR_LIT>", flags=[], version=None, engine=None):
if version is None:<EOL><INDENT>version = sys.version_info[<NUM_LIT:0>:<NUM_LIT:2>]<EOL><DEDENT>if engine is None:<EOL><INDENT>engine = pythonparser_diagnostic.Engine()<EOL><DEDENT>lexer = pythonparser_lexer.Lexer(buffer, version, engine)<EOL>if mode in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>lexer.interactive = True<EOL><DEDENT>parser = pythonparser_parser.Parser(lexer, version, engine)<EOL>parser.add_flags(flags)<EOL>if mode == "<STR_LIT>":<EOL><INDENT>return parser.file_input(), lexer.comments<EOL><DEDENT>elif mode == "<STR_LIT>":<EOL><INDENT>return parser.single_input(), lexer.comments<EOL><DEDENT>elif mode == "<STR_LIT>":<EOL><INDENT>return parser.eval_input(), lexer.comments<EOL><DEDENT>
Like :meth:`parse`, but accepts a :class:`source.Buffer` instead of
source and filename, and returns comments as well.

:see: :meth:`parse`
:return: (:class:`ast.AST`, list of :class:`source.Comment`)
    Abstract syntax tree and comments