2013-08-18 01:13:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
2013-09-13 03:09:35 +00:00
|
|
|
#include "frontends/lean/frontend.h"
|
2013-08-18 01:13:55 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-11-15 20:13:03 +00:00
|
|
|
class script_evaluator;
|
2013-08-25 17:34:19 +00:00
|
|
|
/** \brief Functional object for parsing commands and expressions */
|
|
|
|
class parser {
|
|
|
|
class imp;
|
|
|
|
std::unique_ptr<imp> m_ptr;
|
|
|
|
public:
|
2013-11-15 20:13:03 +00:00
|
|
|
parser(frontend & fe, std::istream & in, script_evaluator * S, bool use_exceptions = true, bool interactive = false);
|
2013-08-25 17:34:19 +00:00
|
|
|
~parser();
|
|
|
|
|
|
|
|
/** \brief Parse a sequence of commands */
|
|
|
|
bool operator()();
|
|
|
|
|
|
|
|
/** \brief Parse a single expression */
|
|
|
|
expr parse_expr();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Implements the Read Eval Print loop */
|
|
|
|
class shell {
|
2013-11-07 18:00:12 +00:00
|
|
|
frontend & m_frontend;
|
2013-11-15 20:13:03 +00:00
|
|
|
script_evaluator * m_script_evaluator;
|
2013-08-25 17:34:19 +00:00
|
|
|
public:
|
2013-11-15 20:13:03 +00:00
|
|
|
shell(frontend & fe, script_evaluator * S);
|
2013-08-25 17:34:19 +00:00
|
|
|
~shell();
|
|
|
|
|
|
|
|
bool operator()();
|
|
|
|
};
|
|
|
|
|
2013-11-15 20:13:03 +00:00
|
|
|
inline bool parse_commands(frontend & fe, std::istream & in, script_evaluator * S = nullptr, bool use_exceptions = true, bool interactive = false) {
|
2013-11-07 21:56:04 +00:00
|
|
|
return parser(fe, in, S, use_exceptions, interactive)();
|
2013-08-25 17:34:19 +00:00
|
|
|
}
|
2013-11-07 18:00:12 +00:00
|
|
|
inline expr parse_expr(frontend & fe, std::istream & in) {
|
2013-11-07 21:56:04 +00:00
|
|
|
return parser(fe, in, nullptr).parse_expr();
|
2013-08-25 17:34:19 +00:00
|
|
|
}
|
2013-08-18 01:13:55 +00:00
|
|
|
}
|